PHP-FPM (FastCGI Process Manager) is an alternative to PHP FastCGI. It provides features like Adaptive process spawning, basic statistics, and advanced process management with graceful stop/start which may be useful for really busy websites. If you want to set up an Apache2 HTTP server with PHP-FPM support and enjoy those benefits, the steps below should be a great place to start.
Install Apache2 HTTP Server
If you don’t already know, the Apache HTTP server is the most popular in use today. With PHP-FPM support, you may be able to improve your website performance greatly, and especially useful for big and busy websites built on PHP. To install Apache2 with PHP7.2 with FastCGI support, run the commands below After installing Apache2, the commands below can be used to stop, start and enable Apache2 to always start up when the server boots. To test the Apache2 setup, open your browser and browse to the server hostname or IP address and you should see the Apache2 default test page as shown below. When you see that, then Apache2 is working as expected. To install the Apache2 Fast-CGI module, you may have to manually install it. The commands below will error that the package has no installation candidate. You may get the error below after running the commands above. To add that package, download it and install it manually.
Install PHP7.2 PHP-7.2-FPM
PHP 7.2 isn’t available on Ubuntu default repositories. to install it, you will have to get it from third-party repositories. Run the commands below to add the below third party repository to upgrade to PHP 7.2 Then update and upgrade to PHP 7.2 Next, run the commands below to install PHP 7.2 and related modules. After installing PHP 7.2, run the commands below to open the PHP default config file for Apache2. Then make the changes on the following lines below in the file and save. The value below is great setting to apply in your environments. After making the change above, save the file and close it.
Configure Apache2 HTTP to use PHP7.2-FPM
Now that both Apache2 and PHP7.2-FPM are installed, run the commands below to enable the FastCGI module for Apache2 Next, open the Apache2 default configuration file and add the following highlighted lines, then save the file and close. Configure the file as shown below: Save and closeout.
Restart Apache2 and Test
After the configurations above, run the commands below to restart Apache2. To test PHP 7.2 settings with Apache2, create a phpinfo.php file in the Apache2 root directory by running the commands below Then type the content below and save the file. Save the file. then browse to your server hostname followed by /phpinfo.php You should see the PHP default test page… That’s it! This is how you use Apache2 with PHP-FPM (FastCGI) Enjoy!