# php-fpm + apache configuration issue



## yarex (Oct 3, 2019)

I have issue to run php code on my website after i switched to php-fpm

php-fpm service looks like started fine but when i try to show php webpage, it shows service unaivable or empty page and code is not getting executed.

Attached all configuration and log files.

Please advice


----------



## 20-100-2fe (Oct 3, 2019)

You have a SetHandler in httpd.conf and another in httpd-ssl.conf.
You may try and remove the one in httpd.conf.
You may also want to increase error log verbosity.


----------



## SirDice (Oct 3, 2019)

I would suggest not editing httpd.conf (besides enabling a few of the 'extra' configs) and add your virtualhosts, each in their own config file, in /usr/local/etc/apache24/Includes. That will make it much easier to maintain and troubleshoot.

You can create them in a specific order like so:

```
000_default.conf
001_site1.conf
002_site2.conf
```


----------



## anlashok (Oct 3, 2019)

In the php-fpm configuration file www.conf you set the unix socket to

```
listen = /var/run/php-fpm.sock
```

but in ssl.conf you told Apache it was a different location, note the extra php in the file path, so its not finding the unix socket


```
<FilesMatch \.php$>
        SetHandler "proxy:unix:/var/run/php/php-fpm.sock|fcgi://localhost/www/mixx_nabytok/"
</FilesMatch>
```

change it to this, you might also need to remove the www/mixx_nabytok/ part as well, I think that's not needed

```
<FilesMatch \.php$>
        SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/www/mixx_nabytok/"
</FilesMatch>
```


----------



## D-FENS (Oct 3, 2019)

Can you try something?
In your httpd.conf try and comment out the line with "mpm_event_module", then uncomment the line with "mpm_prefork_module" and see if this solves your problem. Apache restart is necessary.


----------



## yarex (Oct 4, 2019)

Now getting "No input file specified." in all cases - when i specify domain/index.php and when i dont specify php file.
(attached configs spit out that)
And log contains following: Unable to open primary script: /www/mixx_nabytok//www/mixx_nabytok/index.php

When i change httpd-ssl.conf to

```
<FilesMatch \.php$>
        SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
```

Also changed permissions for /www/mixx_nabytok using chmod -R a+rwx /www
(i'll tune that later back to original minimal permission state)

Worker log spitted out following:

[04-Oct-2019 09:32:27] WARNING: [pool www] child 25325 said into stderr: "NOTICE: PHP message: PHP Warning:  Unknown: failed to open stream: No error: 0 in Unknown on line 0"
[04-Oct-2019 09:32:27] WARNING: [pool www] child 25325 said into stderr: "ERROR: Unable to open primary script: //www/mixx_nabytok/index.php (No error: 0)"
[04-Oct-2019 09:32:28] WARNING: [pool www] child 25325 said into stderr: "NOTICE: PHP message: PHP Warning:  Unknown: failed to open stream: No error: 0 in Unknown on line 0"
[04-Oct-2019 09:32:28] WARNING: [pool www] child 25325 said into stderr: "ERROR: Unable to open primary script: //www/mixx_nabytok/index.php (No error: 0)"

There is double slash in the beggining, so updated httpd-ssl.conf to:
<FilesMatch \.php$>
        SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost"
</FilesMatch>

[Fri Oct 04 09:35:03.332957 2019] [proxy_fcgi:error] [pid 25400:tid 34386254080] [client 194.160.184.40:60454] AH01071: Got error 'PHP message: PHP Warning:  Unknown: failed to open stream: No such file or directory in Unknown on line 0Unable to open primary script: proxy:fcgi:/localhost//www/mixx_nabytok/index.php (No such file or directory)'

[Fri Oct 04 09:35:48.031532 2019] [proxy_fcgi:error] [pid 25425:tid 34385931776] [client 194.160.184.40:60460] AH01071: Got error 'PHP message: PHP Warning:  Unknown: failed to open stream: No such file or directory in Unknown on line 0Unable to open primary script: /www/mixx_nabytok/index.php (No such file or directory)'
[Fri Oct 04 09:37:01.031934 2019] [proxy_fcgi:error] [pid 25475:tid 34370614016] [client 194.160.184.40:60494] AH01071: Got error 'PHP message: PHP Warning:  Unknown: failed to open stream: No such file or directory in Unknown on line 0Unable to open primary script: /www/mixx_nabytok/index.php (No such file or directory)'

The path is ok now, even user chown -R www /www
But still getting same error message when accessing the page

Also cgi.fix_pathinfo=1 is in php.ini

..... why basic freebsd programs installations and configurations can't be same painless as in windows :-(


----------



## yarex (Oct 4, 2019)

roccobaroccoSC said:


> Can you try something?
> In your httpd.conf try and comment out the line with "mpm_event_module", then uncomment the line with "mpm_prefork_module" and see if this solves your problem. Apache restart is necessary.



I dont have any problem with prefork, that one is works fine, just wanted to tune php and switch apache to fpm/event and that one is causing issues, i just simply can't get it executing php scripts


----------



## anlashok (Oct 4, 2019)

try this, based on a working php-fpm setup I have on my server, substituted with your server names etc.

This assumes that you have your website php files are located in /www/mixx_nabytok/*.php

I'd remove these sections from httpd.conf

```
# this is only needed if you are running php via the php_module which you aren't if using php-fpm
<FilesMatch "\.php$">
   SetHandler application/x-httpd-php
</FilesMatch>
...
# easier to have this next to the definition of the :443 virtual host
<VirtualHost www.mixxnabytok.sk:80>
    ServerName www.mixxnabytok.sk
    Redirect permanent "/" "https://www.mixxnabytok.sk"
</VirtualHost>
```

Replace the current virtualhost block in httpd-ssl.conf file with this virtualhost config, it should work with your existing SSL section untouched. You can add any extra bits back in when you've resolved the php issue.

```
# I've just moved the virtualhost:80 address to the SSL file from http.conf to keep all related configs together
<VirtualHost www.mixxnabytok.sk:80>
    ServerName www.mixxnabytok.sk
    Redirect permanent "/" "https://www.mixxnabytok.sk"
</VirtualHost>
<VirtualHost www.mixxnabytok.sk:443>
    ServerAdmin info@mixxnabytok.sk
    DocumentRoot "/www/mixx_nabytok/"
    Protocols h2 h2c http/1.1
    ServerName www.mixxnabytok.sk
    ErrorLog "/var/log/apache/mixx_nabytok_https.log"
    TransferLog "/var/log/apache/httpd-access.log"

    SSLEngine on

    SSLCertificateFile /usr/local/etc/letsencrypt/live/www.mixxnabytok.sk/cert.pem
    SSLCertificateKeyFile /usr/local/etc/letsencrypt/live/www.mixxnabytok.sk/privkey.pem
    SSLCertificateChainFile "/usr/local/etc/letsencrypt/live/www.mixxnabytok.sk/fullchain.pem"
    SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4

    <FilesMatch \.php$>
        <If "-f %{REQUEST_FILENAME}">
        SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/"
        </If>
    </FilesMatch>
   
</VirtualHost>
```

and the fpm pool config file minimised to just this: www.conf

```
[www]
user = www
group = www

listen = /var/run/php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0660

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
; adding this limits the php-fpm to only process php files and not any other file type fed to it
security.limit_extensions = .php
```


----------



## anlashok (Oct 4, 2019)

I should add that these errors were happening because your file path isn't set to what you thought it was in your modified configs

```
[04-Oct-2019 09:32:27] WARNING: [pool www] child 25325 said into stderr: "ERROR: Unable to open primary script: //www/mixx_nabytok/index.php (No error: 0)" 
Unable to open primary script: proxy:fcgi:/localhost//www/mixx_nabytok/index.php (No such file or directory
```
is actually telling you that is looking for a file called /www/mixx_nabytok//www/mix_nabytok/index.php which doesn't exist. Remember that setting a DocumentRoot defines all script files relative to that DocumentRoot, eg www.nabytok.sk/index.php refers to the file system location /www/mixx_nabytok/index.php


----------



## yarex (Oct 7, 2019)

Thank you Anlashok for trying to help, i just get connection issues when i try your config..... and all logs are empty.

I will try to build a new machine to play with this until i get it running.
Just last question, should i use ZTS thread safety or turn it off? (i had it unticked during installation)


----------

