Apache is a most widely used web server in Linux platforms and is one of the best stacks to host PHP applications. With the release of Apache httpd 2.4, there is a Apache proxy module (mod_proxy_fcgi.) introduced and integrated by default with Apache. Also From release 5.3.3 onward, PHP now includes the fastCGI process manager (php-fpm) in the stock source code.

So in short we can install and enable those php and Apache related packages in a Linux server and setup to run Apache with PHP-FPM. In this setup Apache will send all the PHP files for processing to PHP-FPM and PHP-FPM will return the rendered output to the browser. using this stack, a website can load faster and handle more concurrent connections while using fewer resources. Using PHP-FPM we can run each PHP application on a separate process and can assign resource limitations.

In this blog article we configure Apache with php-fpm on Centos7. After that we can run php code using only stock Apache and php binaries. No need to configure anything like suphp, mod_php or suexec. You can also refer this article if you have the newer Centos 8. So lets get started.

Install Apache

Copy to Clipboard

Install php-fpm

Copy to Clipboard

Create below two directories.

Copy to Clipboard

Create a file Named example.conf using below command.

Copy to Clipboard

Add below content in above example.conf file.

Copy to Clipboard

Create Below Directories  and files.

Copy to Clipboard

Allow Apache  to read the conf files from the /etc/httpd/sites-enabled folder.  For that we are going to add following line at the end of /etc/httpd/conf/httpd.conf file.

Copy to Clipboard

Now go the folder named /etc/php-fpm.d and create a file named example.conf  and add below content.

Copy to Clipboard

Add below content in example.conf file.

Copy to Clipboard

Execute Below commands.

Copy to Clipboard

This concludes the installation and configuration apache with php-fpm. Now if you visit the phpinfo page, we can see FPM/FastCGI in the ServerAPI field. Take a look at the below screenshot. Leave your thoughts at the comment box.