Php fpm with apache on centos7

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:
#LoadModule mpm_prefork_module modules/

# worker MPM: Multi-Processing Module implementing a hybrid
# multi-threaded multi-process web server
# See:
LoadModule mpm_worker_module modules/

# event MPM: A variant of the worker MPM with the goal of consuming
# threads only for connections with active processing
# See:
#LoadModule mpm_event_module modules/

Next, create an fpm pool for your site:

cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/

Next, modify the fpm pool settings for your site:

vim /etc/php-fpm.d/

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 =
listen = /var/run/php-fpm/

# also, make sure you add the following 3 lines:
listen.owner = apache = 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 block) – in my case I’m using the sites-available / sites-enabled conventions inside /etc/httpd, but you may be using something else.

vim /etc/httpd/sites-available/
# 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.
“>This older post about installing php7 in centos