PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.
These features include:
- Adaptive process spawning (NEW!)
- Basic statistics (ala Apache’s mod_status) (NEW!)
- Advanced process management with graceful stop/start
- Ability to start workers with different uid/gid/chroot/environment and different php.ini (replaces safe_mode)
- Stdout & stderr logging
- Emergency restart in case of accidental opcode cache destruction
- Accelerated upload support
- Support for a “slowlog”
- Enhancements to FastCGI, such as fastcgi_finish_request() – a special function to finish request & flush all data while continuing to do something time-consuming (video converting, stats processing, etc.)
Normally PHP FPM is said to be installed with nginx. Apache is a very popular and quite easy to use for most of hte users/developers in any of the platforms/OS (Windows, Mac or Linux). Fortunately it can be installed and configured quite easily with Apache2 too. .
- First install normal Apache2
sudo apt-get install apache2
- Now install FastCGI and PHP FPM
$ sudo apt-get install libapache2-mod-fastcgi php5-fpm
Note: if libapache2-mod-fastcgi does not work, check your source.list has multiverse is enabled (uncommented).
- Then create the file /etc/apache2/conf-available/php5-fpm.conf with the contents:
<IfModule mod_fastcgi.c> AddHandler php5-fcgi .php Action php5-fcgi /php5-fcgi Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization <Directory /usr/lib/cgi-bin> Require all granted </Directory> </IfModule>
- Then run the following commands:
sudo a2enmod actions fastcgi alias sudo a2enconf php5-fpm sudo service apache2 reload
That’s it. You just need now to test it if your configurations are done properly or not. For that, just create a file in /var/www/html/ as info.php in your favorite PHP/TEXT editor and add the following code:
<?php phpinfo(); ?>
Save the file and run it from the browser http://localhost/info.php
If you can see phpinfo() function’s output, then you are done. Start your further developments.