Ubuntu 22.04 + Apache + PHP-FPM

Hi, does anyone notice problems with Apache and PHP-FPM on Ubuntu 22.04? After a few tries, it was able to start as FPM/FastCGI, but it doesn’t support pools (only default www.conf).

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Site Moderator
Site Moderator badge
August 9, 2022

Hello there,

This setup is completely fine. You just need to make sure you’ve installed all packages and have the correct configuration.

We also have an article on How To Configure Apache HTTP with MPM Event and PHP-FPM on Ubuntu 18.04 which is for an older Ubuntu version but the process should be very similar for Ubuntu 22.04 as well. You can check the article here


Site Moderator
Site Moderator badge
August 9, 2022

Hi @michalgiza,

I’ve had no problems with running Apache, PHP-FPM and fpm pools. Let’s say you are using PHP 8.1 you’ll need to install the PHP extension:

  1. apt install php8.1-fpm

Once you have it, you’ll need install proxy_fcgi on apache:

  1. sudo a2enmod proxy_fcgi

In the Apache config you can add the following block:

     <FilesMatch ".php$"> 
         SetHandler "proxy:unix:/var/run/php/php8.1-fpm.sock|fcgi://localhost/"          

After you have that, you can enable your domain’s apache config. Once you have that you can edit the fpm pool at Pool config: /etc/php/8.1/fpm/pool.d/www.conf.

Once that, you’ll need to create a new user called example like so:

  1. sudo nano /etc/php/8.1/fpm/pool.d/example.conf

and paste in the following:

  1. [user1]
  2. user = example
  3. group = group1
  4. listen = /run/php/php8.1-fpm-user1.sock
  5. listen.owner = www-data
  6. = www-data
  7. pm = dynamic
  8. pm.max_children = 5
  9. pm.start_servers = 2
  10. pm.min_spare_servers = 1
  11. pm.max_spare_servers = 3

Now, remember the Apache block with added? You need to edit it to look like so:

     <FilesMatch ".php$"> 
         SetHandler "proxy:unix:/var/run/php/php8.1-fpm-example.sock|fcgi://localhost/"          

Notice the example user in there.

Now you’ll need to restart PHP php-fpm and apache2 for the changes to take effect.