How to install FastCGI/php7.0-fpm with Apache in Ubuntu 16.04 LTS
How to install FastCGI/php-fpm with Apache in Ubuntu 16.04 LTS
Introduction
In the web Server Apache is one of the popular web server which is mostly use in our server environment by hosting providers and it easily handles php through default handler which is cgi and php-fpm is FastCGI implementation very simple to setup on server. It uses as backed for heavy application for php to run php cgi fast as compare to normal cgi application. It has very fast processing PHP website/scripts for large traffic sites.
Apache runs by default working on mod_php which takes more resources comparative to php-fpm. So today we are going to install php-fpm with Apache to compile php scripting through php-fpm.
Please follow installation steps:-
solutionclub:~# apt-get update solutionclub:~# apt-get install apache2-mpm-event solutionclub:~# a2dismod mpm_worker solutionclub:~# a2enmod mpm_event
Now The Time,We need to restart apache2 once
solutionclub:~# systemctl restart apache2
After restart You Should check Apache status
solutionclub:~# systemctl status apache2 apache2.service - LSB: Apache2 web server Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: active (running) since Mon 2018-03-05 10:02:25 IST; 8h ago Docs: man:systemd-sysv-generator(8) Process: 1092 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS) CGroup: /system.slice/apache2.service ├─1192 /usr/sbin/apache2 -k start ├─1202 /usr/sbin/apache2 -k start ├─1203 /usr/sbin/apache2 -k start ├─1204 /usr/sbin/apache2 -k start ├─1205 /usr/sbin/apache2 -k start └─1206 /usr/sbin/apache2 -k start Mar 05 10:02:21 sdppc17 systemd[1]: Starting LSB: Apache2 web server... Mar 05 10:02:21 sdppc17 apache2[1092]: * Starting Apache httpd web server apache2 Mar 05 10:02:24 sdppc17 apache2[1092]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0 Mar 05 10:02:25 sdppc17 apache2[1092]: * Mar 05 10:02:25 sdppc17 systemd[1]: Started LSB: Apache2 web server.
Now install libapache2-mod-fastcgi
Note: If you are not success to install libapache2-mod-fastcgi package then add repo in sources.list /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
solutionclub:~# apt-get update solutionclub:~# apt-get install libapache2-mod-fastcgi
Now you ready to install php-fpm
solutionclub:~# apt-get install php-fpm
PHP-FPM is not auto binding with apache. So we require to configure apache. Let us check how to configure.
solutionclub:~# vim /etc/apache2/conf-available/php-fpm.conf
Now you just copy and paste these line in conf file.
<IfModule mod_fastcgi.c> AddHandler php7-fcgi .php Action php7-fcgi /php7-fcgi Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php/php7.0-fpm.sock -pass-header Authorization <Directory /usr/lib/cgi-bin> Require all granted </Directory> </IfModule>
Now We need to enable this module with Apache and enable php-fpm configuration also .
solutionclub:~# a2enmod actions fastcgi alias solutionclub:~# a2enconf php-fpm
Finally we can restart Apache service for have effect.
solutionclub:~# systemctl restart apache2
Now Add phpinfo file in your Apache root folder
solutionclub:~# echo "<?php phpinfo(); ?>" >> /var/www/html/index.php
When You restart Apache service check it on http://server-ip-address/index.php