How to install php5-fpm with Apache in Ubuntu
Introduction
Apache is popular web server software which is mostly used in our server environment by hosting providers and it handles php through default handler which is cgi .PHP5-FPM is FastCGI implementation for PHP. it uses as backed application for php to run php cgi as fast compare to normal cgi application. It is useful for processing PHP scripts for large traffic sites.
Apache runs by default with mod_php which takes more resources then php-fpm. So we are here going to install php-fpm with apache to compile php scripting through php-fpm.
Installation Steps
Step 1. Install apache2 with mod-mpm-event
First of all update repository and install apache with mpm event.
linuxtweaks ~]#sudo apt-get update linuxtweaks ~]#sudo apt-get install apache2-mpm-event
When apache successfully install we can check apache service if it’s running
linuxtweaks ~]#sudo service apache2 status
if it’s not running you can start it by following command-
linuxtweaks ~]#service apache2 start
Step 2. Install libapache2-mod-fastcgi
Next we have to install libapache2-mod-fastcgi module for apache to working with php-fpm.
As this module is not included with default repo so we have to add repolist in apt repository.
Open below files and add repository location
linuxtweaks ~]#sudo vi /etc/apt/sources.list
deb http://us.archive.ubuntu.com/ubuntu/ trusty multiverse deb-src http://us.archive.ubuntu.com/ubuntu/ trusty multiverse deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
Copy above lines and add in sources.list at the end of file.
Now update repository and install apache module
linuxtweaks ~]#sudo apt-get update linuxtweaks ~]#sudo apt-get install libapache2-mod-fastcgi
Step 3. Install php5-fpm
Install php-fpm with following command
linuxtweaks ~]#sudo apt-get install php5-fpm
Step 4. Configure Php-fpm with apache
Create new file and configure php-fpm for apache
linuxtweaks ~]#vi /etc/apache2/conf-available/php5-fpm.conf
add the following line of code in above file –
<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>
After completion of configuration of php-fpm we need to enable this module with apache and enable php-fpm configuration as well.
linuxtweaks ~]#a2enmod actions fastcgi alias linuxtweaks ~]#a2enconf php5-fpm
Finally we can restart apache service for take effect
linuxtweaks ~]#service apache2 restart
Step 5. Testing
Create a phpinfo file for checking if everything works as per our requirement.
linuxtweaks ~]#vi /var/www/html/phpinfo.php
Add the following line of code
<?php phpinfo(); ?>
And check through http://server-ip-address/phpinfo.php
You will see fastcgi/FPM for apache handler.
To know more about php5-fpm please click here !!!