3

I have installed Apache php7.0 and mysql on an Ubuntu 16.04 machine and I get the answer "php is not running." Here is my vhost configuration:

<VirtualHost *:80>
  ServerAdmin webmaster@example.com
  ServerName www.example.com
  DocumentRoot /var/www/sites/www.example.com/httpdocs
  ScriptAlias "cgi-bin" "/var/www/sites/wwww.example.com/cgi-bin"

  ErrorLog ${APACHE_LOG_DIR}/www.example.com.error_log

  LogLevel debug

  CustomLog ${APACHE_LOG_DIR}/www.example.com.log combined

    <IfModule mod_fastcgi.c>

    AddHandler php7-fcgi .php
    Action php7-fcgi /php7-fcgi virtual
    Alias /php7-fcgi-kermit /usr/lib/cgi-bin/php7-fcgi-kermit
    FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi-kermit -socket /run/php/php7.0-fpm.kermit.sock -pass-header Authorization

    <Directory "/usr/lib/cgi-bin">
    Require all granted
    </Directory>
    </IfModule>

  <IfModule mod_fastcgi.c>
    <FilesMatch ".+\.ph(p[345]?|t|tml)$">
      SetHandler php7-fcgi-kermit
    </FilesMatch>
  </IfModule>

</VirtualHost>

When I try to go to the site it is not parsing the php but printing it to the screen.

Does anybody have any ideas?

I have gotten rid of all of the other fpm stuff that used to work with apache 2.2 and have added this line to the conf

ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/var/run/php/php7.0-fpm.kermit.sock|fcgi://localhost/var/www/sites/www.example.com/httpdocs  

Now I get the following error in the error logs

[Wed Mar 21 13:04:35.539499 2018] [proxy:error] [pid 26569] (13)Permission denied: AH02454: FCGI: attempt to connect to Unix domain socket /var/run/php/php7.0-fpm.kermit.sock (localhost) failed

The permisssions look correct for the socket

srw-rw----  1 kermit   kermit     0 Mar 21 13:00 php7.0-fpm.kermit.sock=  

I do not know where it is getting that = sign though

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
QIS_Willie
  • 31
  • 3

3 Answers3

2

If you are using PHP-FPM, you should consider using mod_proxy_fcgi, which is newly available in Apache 2.4 and is just for this type of use case. The Apache wiki entry for PHP-FPM has some good guidance to get started.

The mod_proxy_fcgi documentation also includes specific examples for setting up PHP-FPM and the PHP documentation also has helpful information.

Colt
  • 1,939
  • 6
  • 20
  • 25
  • I've been staring at that apache wiki document for some time now and it's fairly high level. Can you suggest anything with step-by-step instructions for Ubuntu? I'm confused as to why this is so complicated. – S. Imp Mar 22 '18 at 17:32
  • @S.Imp I think the wiki is best read together with the referenced `mod_proxy_fcgi` documentation. It is really pretty straight forward: (1) use the correct modules, and (2) set up the desired `ProxyPassMatch` - either TCP socket approach or UDS approach – Colt Mar 22 '18 at 22:17
  • @S.Imp In any case, you should just start working through a set up, and if you run into problems come back with a new question of your own detailing what you have done, what errors you receive, how you have attempted to solve them, etc. I don't think it is appropriate to extend this answer any further as the OP is clearly interested in resolving the `mod_fastcgi` approach for PHP-FPM, and is getting help from a very knowledgeable HTTPD guy. – Colt Mar 22 '18 at 22:24
  • I have in fact done so [here](https://serverfault.com/questions/904065/switch-apache-from-prefork-to-event-in-ubuntu-16-get-php-7-working). It seems to be working but I'm not sure if the instructions I've captured are exactly correct. Surprising to me that Ubuntu doesn't offer an apt package to set this up. – S. Imp Mar 22 '18 at 22:35
  • @S.Imp Why would there be an `apt` package for this? They are just Apache modules and directives and `php` configurations. – Colt Mar 22 '18 at 22:40
  • And I just looked at you new question - @ezra-s is telling you exactly what to do there – Colt Mar 22 '18 at 22:45
  • he's certainly right in broad strokes, but leaves out a lot of stuff for someone less fluent. I've tried my best to spell out the details for those of lesser experience in a separate answer. – S. Imp Mar 22 '18 at 22:54
  • the question in my mind is why would the package maintainers install apache using a mode [specifically discouraged by the apache team](https://wiki.apache.org/httpd/php)? – S. Imp Mar 22 '18 at 22:56
  • @S.Imp - I don't think any part of a default installation is generally discouraged, but certainly may not be appropriate for various particular configurations. Apache, or any web server, is not really meant to be ran "out of the box," but rather configured to specific use cases, loads, etc. on and on. As to your quibble with the help you are getting here, you may be lucky that your question is not closed. This forum is for professional system administrators, and others often don't fair well here. ezra-s, by the way, is a maintainer of Apache, and if I were you I would try to learn from him – Colt Mar 23 '18 at 01:32
0

Your socket permissions are incorrect: "srw-rw---- 1 kermit kermit 0 Mar 21 13:00 php7.0-fpm.kermit.sock"

You say Apache runs with www-data.

You either need to add www-data to kermit or change the socket permissions in php-fpm pool config to something like kermit:www-data

ezra-s
  • 2,215
  • 1
  • 7
  • 13
0

I was able to fix this by changing the group to www-data along with a couple of other changes that occurred in later versions of apache-22 and 24

QIS_Willie
  • 31
  • 3