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.