Moodle with PHP-FPM

Moodle with PHP-FPM

by Leon Stringer -
Number of replies: 1
Picture of Core developers Picture of Particularly helpful Moodlers

Rick asked about PHP-FPM so I thought I'd answer in a separate thread:

Previously Apache would run PHP files using mod_php which used a shared object file so the Apache process would actually execute the script. With PHP-FPM Apache passes execution of the script to another process: the php-fpm service (daemon) so you need to ensure this is running. With Nginx PHP-FPM is the normal way to execute scripts (no mod_php).

I've never done any benchmarking to compare performance, I just updated PHP version one day and my server had switched from mod_php to PHP-FPM. As this seems to be the favoured way of running PHP these days so that's what I use.

Things to watch out for when switching to PHP-FPM:

  1. Because PHP-FPM is now executing scripts it's this service that needs reloading or restarting to re-read php.ini or clear OPcache (e.g. systemctl restart php-fpm).
  2. Error output now goes to /var/log/php-fpm/www-error.log.
  3. The user that scripts are executed as may change, i.e. the user that needs write access to the Moodledata.

This last point was a big issue on my CentOS systems as sites stopped working because PHP was now being run as user php-fpm instead of apache. This is managed by user = in /etc/php-fpm.d/www.conf:

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache

Beyond the above change in user account, as far as I know there's no effect on Moodle of switching from mod_php to PHP-FPM. I mainly use CentOS and Fedora so some of the above information might be specific to these distros (usernames, log and configuration file locations).

Average of ratings: Useful (3)
In reply to Leon Stringer

Re: Moodle with PHP-FPM

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Thanks for your reply, and for splitting this out as a separate topic.

Between the time I posted and your response, I did find a little bit of information in the Moodle Performance docs that suggested that PHP-FPM is recommended. I went ahead and installed PHP-FPM on my experimental CentOS Apache VPS, then installed a copy of my full production moodle data, and then TURNED ON performance stats from debugging.

In my brief experimentation, moodle page load times were almost always faster with PHP-FPM. Sometime 20% faster (meaning .8 seconds instead of 1.0) and sometimes much faster, like .3 versus 1.0. So my initial reaction is "Wow, I should be running PHP-FPM."  (This reminds me about when the change to php 7 happened, and Martin saying to me "it's much faster.")

I didn't have to do anything to to the moodledata folder because I always use 777 for permissions.

Of course, prior to moving my production data into this experimental server I installed Moodle from scratch.  No complaints.  Then I copied over my data, no problems at all.

Being that I am not a "server" guy, but do run my own moodle and VPS, I still like to be cautious.  But it seems that the switch to PHP-FPM should be fine.  My Moodle is not heavily loaded, with only around 50 students this semester.  And my server only "serves" Moodle, so it is pretty simple.

Does anything that I have make any sense? 


Average of ratings: Useful (1)