php7.0-fpm not working with apache2.4 on Ubuntu-16.04
Your configurations are a little bit off. Try this:
<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>
I add it this here, and works well: /etc/apache2/sites-available/000-default.conf
Related videos on Youtube
Cosmo
Updated on September 18, 2022Comments
-
Cosmo over 1 year
I'm using Ubuntu-16.04 to establish an apache server. I use php-fpm to handle php files. I followed this post. After configuration, my apache2 and php7.0-fpm services restarted correctly. But when I browse a php file I got a plain file. It seems that there is no php cgi to handle the php file. What's wrong with me?
I'm new to apache. So I don't know what configurations to paste. I will post the necessary configurations according to your answers. Thx!
My installation steps:
Install PHP and PHP-fpm:
sudo apt-get install php libapache2-mod-php sudo apt-get install libapache2-mod-fastcgi php7.0-fpm
Enable the fastcgi mods
sudo a2dismod php mpm_prefork sudo a2enmod actions fastcgi alias mpm_worker
Create a global config for php7.0-fpm
sudo vim /etc/apache2/conf-available/php7.0-fpm.conf
And write in the configurations:
<IfModule mod_fastcgi.c> AddHandler php7.0-fcgi .php Action php7.0.fcgi /php7.0.fcgi Alias /php7.0-fcgi /usr/lib/cgi-bin/php7.0.fcgi FastCgiExternalServer /usr/lib/cgi-bin/php7.0.fcgi -socket /var/run/php7.0.fpm.sock -pass-header Authorization <Directory /usr/lib/cgi-bin> Require all granted </Directory> </IfModule>
Then Enable the php7.0-fpm conf
sudo a2enconf php7.0-fpm
Restart apache and fpm
sudo service apache2 restart && sudo service php7.0-fpm restart
Edit
/var/www/html/index.php
:<?php phpinfo(); ?>
Then browse
http://localhost/index.php
, but got the file content instead of the printed page.-
FooBee about 7 yearsNo one wants to read some external tutorial to get an idea what you might have done wrong. So just post the files you adapted as a start.
-
Cosmo about 7 years@Sven Thanks for your remind. I have described my installation steps briefly.
-
bgtvfr almost 7 yearsls /var/run/php7.0.fpm.sock?
-