1

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.

3
  • 1
    No 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.
    – Sven
    May 3, 2017 at 17:51
  • @Sven Thanks for your remind. I have described my installation steps briefly.
    – Cosmo
    May 4, 2017 at 8:49
  • ls /var/run/php7.0.fpm.sock?
    – bgtvfr
    Jun 28, 2017 at 7:53

2 Answers 2

2

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

0

I just went through similar issues when installing php7.0 in Ubuntu 16.04. Don't hold me to this but I think the issue had to do with permissions. I make www-data the owner and group of all the files in the /var/www folder and the chmod permissions are changed to drwxrwxr-x. This is just on my own development server and I'm not that experienced at this so use at your own risk. They can be undone as easily as they can be changed though.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .