I have a bare metal Ubuntu 18.04 box that I installed LAMP on for NextCloud and Minecraft dynmap install in vhosts. Everything works okay, but my NextCloud speeds are laughably slow and all the reading I've done says I should have used php-fpm instead of vanilla php.

I have searched and searched on how to upgrade php 7.2 to the fpm version and I've come up empty handed. I can't seem to find any information on whether my php.ini can be pasted over, how to tell apache to use the new version and not the old version, whether or not I have to tell each vhost independently to use it of it's an apache config somewhere...

Any help is appreciated.


Googling php7.2-fpm apache2 will reveal many guides to configure apache.

NOTE ---I do not claim this to be the proper or most secure settings. The issue of site security is complex and constantly evolving. It is up to you to keep up to date on the best security practices.

This is the method I successfully used the set up in a development environment. This assumes default Ubuntu 18.04 LAMP server settings with php7.2 installed. Method is simalar for release standard php or php7.3 and php7.4(with ppa REPOs configured)

If you do not have one first create a php info page.

echo '<?php phpinfo() ?>' | sudo tee /var/www/html/phpinfo.php

Check page in browser via local network or gui if installed on server. "server ip or domain"/phpinfo.php

The line 'Server API' will confirm default 'Apache 2.0 Handler'

In a terminal navigate to path /etc/apache2/

cd /etc/apache2/

Check that you have the php7.2-fpm configuration available in conf-available

ls conf-available

If it is not available it may be installed via:

sudo apt install php7.2-fpm

enable php7.2-fpm configuration:

sudo a2enconf php7.2-fpm

This creates a link of the actual file /etc/apache/conf-available/php7.2-fpm.conf and places it in /etc/apache2/conf-enabled directory. By default ubuntu apache2 configuration includes all *.conf files from /etc/apache2/*-enabled directorys into the /etc/apache2/apache2.conf file.

Now you will need to enable the proxy and proxy_fcgi modules

sudo a2enmod proxy_fcgi

This will enable both modules as proxy.conf is a dependency of proxy_fcgi.

Now to complete, disable php7.2 module:

sudo a2dismod php7.2

Restart apache server

sudo systemctl restart apache2

Confirm configuration "ip or domain"/phpinfo.php

The line "Server API" will now confirm " FPM/FastCGI ".

PHP workload is now offloaded from apache process to an independent php server process.

This assumes default Ubuntu LAMP server settings. This does not take into account any previously enabled modules or configurations. Before making any changes to default conf files I recommend creating a backup copy for restoring default settings.

This method is similar for later Ubuntu releases with php7.3 or php 7.4

If any errors are encountered during restart check the apache2 logs files at /var/log/apache2/ and php logs in /var/log.

| improve this answer | |
  • Thank you for this. Is there a way for me to test using php7.2-fpm with a single vhost before making the switch permenant for all vhosts? Or even a way to enable/disable php7.2/php7.2-fpm per vhost? – S16 Jan 19 at 21:01
  • Yes, you could leave php7.2.conf module enabled. – da_kingpin Jan 20 at 0:16
  • Take a look at the php7.2-fpm.conf file. You could the copy <FilesMatch>"the code between tags"</FilesMatch> and put it into you site.conf file inside the VirtualHost tags with php7.2.conf module enabled – da_kingpin Jan 20 at 0:27
  • I would suggest reading the Apache docs (httpd.apache.org/docs) – da_kingpin Jan 20 at 0:43
  • Here is a link with similar info. Its for php7.4 but the idea is the same. php-fpm – da_kingpin Jan 20 at 4:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.