CentOS 7 Apache with PHP 7.1 and FCGId

Right, installing PHP 7.1 is simple, just get the Webtatic repo and install it

# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# yum install -y mod_php71w php71w-cli php71w-common php71w-gd php71w-mbstring php71w-mcrypt php71w-mysqlnd php71w-xml php71w-opcache

If you want to use FCGId instead of mod_php install and configure FPM and mod_fcgid (make sure you remove mod_php71w from the previous command!)

# yum install -y php71w-fpm mod_fcgid
# chkconfig --levels 235 php-fpm on
# vi /etc/php-fpm.d/www.conf

and change the following

listen = 127.0.0.1:9000
to
listen = /tmp/php5-fpm.sock

then we need to create some configuration and a wrapper script:

# vi /etc/httpd/conf.d/fcgid.conf

and add this to the end

<Directory /var/www/html/>
AddHandler fcgid-script .php
FCGIWrapper /etc/httpd/conf.d/wrapper .php
Options ExecCGI Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>

you can change the webroot directory to where you server your pages from if it’s different. Then create the wrapper:

# vi /etc/httpd/conf.d/wrapper

and add the following

#!/bin/sh
PHPRC=/etc/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/bin/php-cgi

Nearly there! Final step

# vi /etc/httpd/conf/httpd.conf

and look for the DirectoryIndex variable, then add your php index files

DirectoryIndex index.php index.html index.htm

Then update the permissions and fire it all up

# chmod 777 /etc/httpd/conf.d/wrapper
# systemctl start php-fpm.service
# systemctl restart httpd.service

Done.

Bookmark the permalink.

Leave a Reply

Your email address will not be published.