This is a short post detailing how to manually setup php fpm with apache on centos7. php fpm is a great solution (especially when used with nginx, but you may want to keep running apache while still having some of the benefits of fmp – you might even be running nginx for static resources, fpm for php and apache at the front!)
Firstly, you need to install the fpm modules (in my case I’m running php72w) using yum.
sudo yum install php72w-fpm
Next step is to update the apache configuration files to use the worker handler rather than the prefork handler.
The config file has all the handlers in it, and should have one of them uncommented. just re-comment it and un-comment the one you want to use.
sudo vim /etc/httpd/conf.modules.d/00-mpm-conf # Select the MPM module which should be used by uncommenting exactly # one of the following LoadModule lines: # prefork MPM: Implements a non-threaded, pre-forking web server # See: http://httpd.apache.org/docs/2.4/mod/prefork.html #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so # worker MPM: Multi-Processing Module implementing a hybrid # multi-threaded multi-process web server # See: http://httpd.apache.org/docs/2.4/mod/worker.html # LoadModule mpm_worker_module modules/mod_mpm_worker.so # event MPM: A variant of the worker MPM with the goal of consuming # threads only for connections with active processing # See: http://httpd.apache.org/docs/2.4/mod/event.html # #LoadModule mpm_event_module modules/mod_mpm_event.so
Next, create an fpm pool for your site:
cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/example.com.conf
Next, modify the fpm pool settings for your site:
The defaults in the file are ok, except its better to listen over a socket than to use a TCP port, so change the line
; listen = 127.0.0.1:9000 listen = /var/run/php-fpm/example.com.sock # also, make sure you add the following 3 lines: listen.owner = apache listen.group = apache listen.mode = 0660
Next, you need to configure apache to forward all requests to fpm through your socket (add the following lines to both the :80 an the :443 sections in your
vim /etc/httpd/sites-available/example.com # add the following before the block # Proxy declaration
# we must declare a parameter in here (doesn't matter which) or it'll not register the proxy ahead of time ProxySet disablereuse=off # Note: If you configure php-fpm to use the "ondemand" process manager, then use "ProxySet disablereuse=on"# Redirect to the proxy SetHandler proxy:fcgi://php-fpm
Lastly, you need to set the new services to be started on boot and (re)start them:
systemctl enable php-fpm systemctl enable httpd systemctl restart php-fpm systemctl restart httpd
congrats. you now have php fpm with apache on centos7!
Sources: This awesome guide has pretty much the same info as my post.