Converting a Website from mod_php 5.6.29 to php56u-fpm-httpd

So a customer wanted us to convert their PHP site to use the php-fpm. The reason was, that php-fpm can run as it’s own user and group, and isn’t limited in it’s execution in the same way that apache is on the filesystem with the regular version of php.

This is how I achieved it.

yum install php-fpm.x86_64 php56u-fpm-httpd.noarch

# for some reason if you get a weird error install them seperately
yum install php-fpm.x86_64 
yum install php56u-fpm-httpd.noarch

Then you will need to run the following:

systemctl enable php-fpm
systemctl enable httpd

systemctl start php-fpm
# check the status
systemctl status php-fpm

If necessary like it was for me change /etc/php-fpm.d/www.conf to reflect the following

listen = /var/run/php-fpm/default.sock
	listen.owner = apache = apache
	listen.mode = 0660

# Also make sure you set the correct execution group, the listen socket perms are different
# as I have found out from experience

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = sftpusercangohere
group = apache

If necessary, you will want to use a Custom user/group for php-fpm. This is one of the advantages of using FPM.

Also, you can use EVENT MPM instead of PREFORK MPM, it’s more efficient with fpm, and certainly worth considering. This step is optional, and not required for fpm to work

# Comment out this line
#LoadModule mpm_prefork_module modules/

#Uncomment the following
LoadModule mpm_event_module modules/

Edit your httpd.conf file in /etc/htpd/conf.d/* or /etc/httpd/httpd.conf and ensure in side the Virtualhost directive you have the following set:

 ProxyPassMatch ^/(.*\.php)$ fcgi://$1

Where html is the documentroot of the site.

This article is kind of complete but still a bit drafty.

Leave a Reply

Your email address will not be published. Required fields are marked *