Trying to confirm is php7.0-fpm is working with apache on Ubuntu 16.04

php-fpmubuntu-16.04

I configured php7.0-fpm to work with apache on Ubuntu 16.04 but not sure if it is correctly configured and working.

As I understand, after installation and configuration, the output of php info file should display "Server API –> FPM/FastCGI" but it is still showing "Server API –> Apache 2.0 Handler".

This is how I installed and configured php7.0-fpm:

sudo apt-get install libapache2-mod-fastcgi php7.0-fpm

sudo a2enmod actions fastcgi alias

sudo a2enconf php7.0-fpm

sudo service php7.0-fpm restart

sudo systemctl status php7.0-fpm

sudo systemctl restart apache2.service

Below is the output of sudo systemctl status php7.0-fpm:

php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2017-11-25 11:57:33 UTC; 23h ago
Process: 1149 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS)
Main PID: 1336 (php-fpm7.0)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
Tasks: 3
Memory: 37.8M
CPU: 3.089s
CGroup: /system.slice/php7.0-fpm.service
├─1336 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
├─1340 php-fpm: pool www
└─1341 php-fpm: pool www

Nov 25 11:57:33 ip-10-0-0-126 systemd[1]: Starting The PHP 7.0 FastCGI Process Manager...
Nov 25 11:57:33 ip-10-0-0-126 systemd[1]: Started The PHP 7.0 FastCGI Process Manager.

What am I doing wrong? Would appreciate some help and advice?

Below is the contents of my /etc/apache2/conf-enabled/php7.0-fpm.conf file:

<Directory /usr/lib/cgi-bin>
    Require all granted
</Directory>
<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
</IfModule>

Best Answer

You need to enable the proxy_fcgi module, and disable mod_php7, for the stock php7.0-fpm conf file to be effective.

If you look at /etc/apache2/conf-enabled/php7.0-fpm.conf, you'll see this at the top:

<IfModule !mod_php7.c>
<IfModule proxy_fcgi_module>