Apache PHP-FPM setup results in File not found
I have Googled a lot and there certainly are a lot of results (even on serverfault.com) about this issue. However, I have not been able to solve my issues with it.
My setup
I have been setting up Ubuntu 20 on WSL2 and am trying to provision it with Ansible. I am trying to setup Apache with PHP-FPM-7.4.
Apache
Apache seems to be working fine. I have a document root with an test.html in it. When I call the direct URL to that HTML file I see the contents like I should.
Vhost
Note: for ease of reading I left out all the comments
DirectoryIndex index.php index.html
<VirtualHost *:80>
ServerName paul.test
ServerAlias *.paul.test
<FilesMatch \.php$>
Require all granted
SetHandler proxy:fcgi://127.0.0.1:9000
</FilesMatch>
UseCanonicalName Off
VirtualDocumentRoot /var/www/hosts/%-4.0.%-3.0/%-5+
<Directory "/var/www">
AllowOverride All
Options -Indexes +FollowSymLinks
Require all granted
</Directory>
ProxyPassMatch ^/(.*\.php(/.*)?)$ "fcgi://127.0.0.1:9000/var/www/hosts/%-4.0.%-3.0/%-5+"
</VirtualHost>
<VirtualHost *:443>
ServerName paul.test
ServerAlias *.paul.test
<FilesMatch \.php$>
Require all granted
SetHandler proxy:fcgi://127.0.0.1:9000
</FilesMatch>
UseCanonicalName Off
VirtualDocumentRoot /var/www/hosts/%-4.0.%-3.0/%-5+
SSLEngine on
SSLCipherSuite AES256+EECDH:AES256+EDH
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder On
SSLCompression off
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
<Directory "/var/www">
AllowOverride All
Options -Indexes +FollowSymLinks
Require all granted
</Directory>
ProxyPassMatch ^/(.*\.php(/.*)?)$ "fcgi://127.0.0.1:9000/var/www/hosts/%-4.0.%-3.0/%-5+"
</VirtualHost>
PHP FPM
Now the problem is when I call a PHP file: then I see "File not found." in the webbrowser.
pool.d/www.conf
Note: for ease of reading I left out all the comments
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 5
listen.allowed_clients = 127.0.0.1
Error logs
The PHP-FPM error log says it's running fine:
[24-Dec-2020 12:16:06] NOTICE: fpm is running, pid 26532
[24-Dec-2020 12:16:06] NOTICE: ready to handle connections
[24-Dec-2020 12:16:06] NOTICE: systemd monitor interval set to 10000ms
The Apache error log shows an error:
[Thu Dec 24 12:44:38.779511 2020] [proxy_fcgi:error] [pid 26424:tid 140510559713024] [client ::1:57178] AH01071: Got error 'Primary script unknown'
How to fix / investigate?
To begin with, I find the error message "File not found." very unclear. Who did not find what file? It would help me and others who have this error in the future to explain who throws this error and what it means exactly.
My conclusion up to this point would be that the error message is being thrown by Apache and means that it cannot find the PHP-FPM process. Is that correct?
How should I further investigate and fix this?
Edit: Adding my Apache and PHP-FPM setup.
Edit / important note
While improving this post and investigating the problem I found out that the base setup of Apache and PHP-FPM is working fine.
The problem apparently is caused by the following statement:
ProxyPassMatch ^/(.*\.php(/.*)?)$ "fcgi://127.0.0.1:9000/var/www/hosts/%-4.0.%-3.0/%-5+"
This statement worked fine on a previous setup (with Centos), but it doesn't right now. When I replace this statement for a static path to the document-root, then it works fine.
I will investigate further, but if someone knows how to fix this, please let me know.
After more investigation I found out that my ProxyPassMatch
statement caused the error. And then I found a post on StackOverflow saying that the whole ProxyPassMatch statement shouldn't be used.
Simply SetHandler proxy:fcgi://127.0.0.1:9000
(which was already in my vhost) makes PHP work.