How to Run PHP-FPM with Apache in Ubuntu

There are basically two ways to run PHP code with Apache web server:

  • Apache PHP module
  • PHP-FPM

In most situations the Apache PHP7.4 module is used to handle PHP code, which is usually fine. But in some cases, you need to run PHP code with PHP-FPM instead. Here’s how.

Disable the Apache PHP7.4 module.

sudo a2dismod php7.4

Install PHP-FPM.

sudo apt install php7.4-fpm

Enable proxy_fcgi and setenvif module.

sudo a2enmod proxy_fcgi setenvif

Enable the /etc/apache2/conf-available/php7.4-fpm.conf configuration file.

sudo a2enconf php7.4-fpm

Restart Apache for the changes to take effect.

sudo systemctl restart apache2

To test PHP scripts with Apache server, we need to create a info.php file in the document root directory.

sudo nano /var/www/html/info.php

Paste the following PHP code into the file.

<?php phpinfo(); ?>

Now in the browser address bar, enter server-ip-address/info.php. Replace server-ip-address with your actual IP. If you followed this tutorial on your local computer, then type 127.0.0.1/info.php or localhost/info.php.

You should see your server’s PHP information is FPM/FastCGI, which means Apache web server will pass PHP requests to PHP-FPM. 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How To Install LAMP Stack on CentOS VPS

This Knowledgebase article details steps on how to install LAMP stack on CentOS & RHEL OS...

How to Install LEMP Stack on Ubuntu VPS

This knowledgebase article details how to install LEMP stack (Nginx, MariaDB, and PHP7.4) on...

Install WordPress on Ubuntu with LAMP

This knowledgebase will detail how to install WordPress on Ubuntu flavours with Apache, MariaDB...

How to Set up WordPress Multisite on Ubuntu Server using LAMP

This knowledgebase will show you how to set up WordPress Multisite with Apache Web server. It’s...

How to Install LAMP Stack on Ubuntu VPS

This knowledgebase article is going to show you how to install LAMP stack on Ubuntu 20.04 LTS. A...