I’m finally posting this. Sorry for the looooong delay. You know how it is (probably).
This configuration is not pristine, and I’ve changed stuff from the default. I’ll try to explain it a bit, and just post back questions if you don’t get something.
It’s been sanitized to example.com, obviously. My real one uses an Include directive for the directory options so that they’re standard across virtual hosts, but that’s nothing specific to PHP-FPM.
Also, this is on Ubuntu Lucid 10.04. I believe the latest versions automatically separate the pool and main configuration. Note that I’ve done this in mine; when you install by default, the default pool (www) is setup in php5-fpm.conf.
In addition, I’ve set it up to use Unix sockets. It was configured to use TCP networking by default.
Finally, this whole setup requires an Ubuntu PPA if you are on Lucid. I think that it is included in later versions of Ubuntu.
I recommend setting up your Virtualmin sites to use Apache-FCGId for now; I converted VirtualHost definitions thus configured to what I have now.
Right…so let’s try to explain this from step 1…and again, this assumes Ubuntu 10.04.4.
Setting this up won’t mess up your sites that run in Apache-FCGId mode, by the way. I recommend against this since you’ll be running more processes that way and that sort of defeats the purpose of this setup…but to you.
Another thing I noticed is that each PHP-FPM pool seems to use a bit more memory than having Apache-FCGId sites running under the same amount of users. Not sure why this is, though it probably has to do with the php5-fpm process size. The thing I like is that the PHP processes are managed better, APC WORKS (which can further reduce process size if the entire codebase can be cached), and thus memory usage is more predictable - it will spike and then come back down rather than staying up.
Paths in here refer to paths on my system.
Step 1: Install PHP-FPM
sudo apt-add-repository ppa:brianmercer/php
sudo apt-get update
Step 2: Install stuff
- Make sure the
multiverse
repository is enabled your /etc/apt/sources.list
!
- Run:
sudo apt-get install php5-fpm libapache2-mod-fastcgi
sudo a2enmod fastcgi
sudo service apache2 reload
Step 3: Change Apache and VirtualHost configurations!
This is where you start looking at my attached files. Brief rundown:
-
/etc/php5/fpm/php5-fpm.conf
: I deleted the [www] pool configuration. I turned on the include directory for pool configurations (a pool is basically an instance of PHP-FPM running as a particular user and configured to run in a certain way. I use several of these to segregate access and to allow PHP to run as the virtual server user. Virtualmin would ideally create a pool per Virtual Server (and reuse them for sub-servers)).
-
/etc/php5/fpm/example-pool.conf
: I turned on Unix socket use instead of TCP networking (about 10% faster, they say) and I changed the variables related to the listening and running user and group (this is recommend around the net) and reduced the amount of servers running since I was on a VPS. I found that the defaults work well though on a machine with 2 GB RAM or a bit more...depending on what you're doing. This machine was a Web + database server (though it wasn't the one this configuration is from).
-
/etc/apache2/apache2.conf
: I added the FastCgiExternalServer directive.
Step 4: Restart stuff
sudo service apache2 restart
sudo php5-fpm restart
That’s about it. I’ve tried to be as accurate as possible, but might’ve made a couple typos. So let me know! Glad I finally got this posted!