Nginx - PHP-FCGI broken

SYSTEM INFORMATION
Debian 10 REQUIRED
1.981 REQUIRED
6.17 REQUIRED
Virtualmin RECOMMENDED

I have been running Virtualmin with NGINX for hosting servers for several years. After doing apt-get upgrade to the server, all the hosts have lost PHP, via FCGI.

Switching to FPM, I am able to get PHP working again, but PHP-FCGI is now broken.

You can replicate the problem on a brand new server that is using Virtualmin with NGINX, and make a phpinfo file. With PHP-FCGI, the phpinfo will show 502 Gateway error (I’m using CloudFlare). And when I switch to PHP-FPM, the phpinfo works again.

Can anyone advise what has broken with Virtualmin/NGINX PHP-FCGI?

Did You see any error log relate? maybe You could copy paste here

Also, what about from fresh install instead of upgrading?

1 Like

No need for a fresh install. But, relevant error log entries would be absolutely necessary to make any progress. The browser has no useful information about why something failed on the server, we need to see what the server thinks happened.

Here’s the error log from /var/log/virtualmin/example.net_error_log

2021/10/07 00:32:33 [crit] 28568#28568: *3 connect() to unix:/var/php-nginx/163353028311931.sock/socket failed (2: No such file or directory) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: example.net, request: “GET /php.php HTTP/1.1”, upstream: “fastcgi://unix:/var/php-nginx/163353028311931.sock/socket:”, host: “example.net

Here’s the nginx config file for example.net from /etc/nginx/sites-available/example.net.conf:

server {
server_name example.net www.example.net;
listen xxx.xxx.xxx.xxx;
root /home/example.net/public_html;
index index.php index.htm index.html;
access_log /var/log/virtualmin/example.net_access_log;
error_log /var/log/virtualmin/example.net_error_log;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME /home/example.net/public_html$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT /home/example.net/public_html;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS $https;
location ~ .php(/|$) {
try_files $uri $fastcgi_script_name =404;
fastcgi_pass unix:/var/php-nginx/163353028311931.sock/socket;
}
fastcgi_split_path_info ^(.+.php)(/.+)$;
location /cgi-bin/ {
gzip off;
root /home/example.net/cgi-bin;
fastcgi_pass unix:/var/fcgiwrap/163353028311931.sock/socket;
fastcgi_param SCRIPT_FILENAME /home/example.net$fastcgi_script_name;
}
listen xxx.xxx.xxx.xxx:443 ssl;
ssl_certificate /home/example.net/ssl.combined;
ssl_certificate_key /home/example.net/ssl.key;
include /etc/nginx/sites-directives/*.conf;
}

Seems like either the fcgi process isn’t running (explaining the missing socket) or maybe there’s a permission problem creating the socket.

Does /var/php-nginx exist?

Also, I assume you’ve checked “Validate Virtual Servers” for errors?

Does /var/php-nginx exist?

Yes, here is the contents of /var/php-nginx:

drwxrwxrwx 4 root root 4096 Oct 7 00:28 .
drwxr-xr-x 17 root root 4096 Oct 6 13:48 …
drwxrwx— 2 www-data example.net 4096 Oct 7 00:28 163353028311931.sock
drwxrwx— 2 www-data example.net 4096 Oct 6 14:38 163353045713341.sock

Also, I assume you’ve checked “Validate Virtual Servers” for errors?

Here’s the output from Validate Virtual Servers:

Failed to validate servers : virtualmin-nginx::feature_get_web_ssl_file failed : Can’t use string (“ssl_certificate_key”) as an ARRAY ref while “strict refs” in use at /usr/share/webmin/virtualmin-nginx/virtualmin-nginx-lib.pl line 210.

Also, what about from fresh install instead of upgrading?

All the results I have provided is from a fresh install as a test server (non production).

That looks like a bug (maybe triggereed by an nginx config that’s confusing our parser). I seem tor recall someone else reported something similar, but I can’t search for it right now…might be worth doing a search for a bit of that error, though.

This is just a test server, so if you want remote access to take a look, just let me know.

This is a fresh install, so I haven’t made any modifications that would affect the PHP-FCGI. As I mentioned, PHP-FPM works.

Virtualmin/Apache works with both PHP-FCGI and PHP-FPM (on a different server).

We never want remote access. Concerns include lack of time, potential liability, etc. We occasionally break the rule for particularly hard to troubleshoot problems, but, in this case, you’ve already posted your nginx config and the error. That’s probably all we’d need to see…and Jamie can ask for more, if not.

Completely understandable. If there’s anything else I can provide, please don’t hesitate to ask.

I have same versions (Debian, VM, etc) as you and got the last upgrade on sunday , I have many sites on it both FPM and FCGI which runs well. The probelm is at install of Virtualmin with NGINX, is not vey well parametered and unstable and you can not stay with only the Virtualmin menus, you have to go in the files:
ex to pass the site “mysite” in FPM , you have to remove :slight_smile: but
rm: cannot remove ‘mysite/fcgi-bin/php5.fcgi’: Operation not permitted
and do
sudo lsattr mysite/fcgi-bin/php7.3.fcgi
----i---------e---- mysite/fcgi-bin/php7.3.fcgi
The file is immutable (cannot be changed, removed etc).

As root user do the following:
chattr -R -i mysite/fcgi-bin/php7.3.fcgi
and then the rm is ok

test on services>PHP-FPM config, edit config manually
with going fetch /etc/php/7.3/fpm/php-fpm.conf and manage it
then /etc/php 7.3/fpm/pool.d file of you site and work on it. This is not obvious in actual VirtualMin version for Nginx !

Sorry for wrong reply up there. :slight_smile: I had similar problem with php-fpm and this is what solved my problem. I’ve misread and thought it is php-fpm issue.