Fix Virtualmin Nginx error: Executable path is not absolute

How to fix Virtualmin & Nginx 502 Bad Gateway Error Caused by "Executable path is not absolute"

This is an error I came across on a new VPS setup on Ubuntu 18.04 with Virtualmin and Nginx. Tricky part about it is that the nginx Error: Executable path is not absolute only appear after a reboot. Everything works fine until then. But after the first reboot of the server, you start to see 502 Bad Gateway across all sites hosted on the server.

So I didn’t have a clue what went wrong. Everything was working fine before the reboot. Looking at the error log, I found following lines that are related to the error,

2020/12/19 04:18:10 [crit] 20981#20981: *6 connect() to unix:/var/php-nginx/160827070023515.sock/socket failed (2: No such file or directory) while connecting to upstream, client: 205.169.39.30, server: domain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/php-nginx/160827070023515.sock/socket:", host: "domain.com"
2020/12/19 04:25:24 [crit] 20981#20981: *9 connect() to unix:/var/php-nginx/160827070023515.sock/socket failed (2: No such file or directory) while connecting to upstream, client: 112.135.13.47, server: domain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/php-nginx/160827070023515.sock/socket:", host: "domain.com"

According to it nginx is having trouble connecting to the fastcgi socket. So I tried to start it by going to Webmin > System > Bootup and Shutdown and got the following error.

Failed to restart php-fcgi-domain-com.service: Unit php-fcgi-domain-com.service is not loaded properly: Exec format error.
See system logs and 'systemctl status php-fcgi-domain-com.service' for details.

At this point I knew this is related to php-fcgi Virtualmin uses by default. Switching to php-fpm by going to Virtualmin > Server Configuration > Website Options for each domain would fix it. But I like to use php-fcgi with Virtualmin because it create individual services for each domain you have. So I started digging further.

Next I executed systemctl status php-fcgi-domain-com.service on terminal. And this is what I got,

root@user:~# systemctl status php-fcgi-domain-com.service
● php-fcgi-domain-com.service - Starts Nginx PHP FastCGI server for domain.com (Virtualmin)
   Loaded: error (Reason: Exec format error)
   Active: inactive (dead)

Dec 15 13:51:55 domain.com systemd[1]: /lib/systemd/system/php-fcgi-domain-com.service:5: Ignoring unknown escape sequences: "su user -c PHPRC\=\/home\/user\/etc\/php7\.3\ PHP_FCGI_CHILDREN\=4\
Dec 15 13:51:55 domain.com systemd[1]: /lib/systemd/system/php-fcgi-domain-com.service:6: Executable path is not absolute: su user -c kill\ \`cat\ \/var\/php\-nginx\/160827070023515\.php\.pid\`
Dec 15 13:51:55 domain.com systemd[1]: /lib/systemd/system/php-fcgi-domain-com.service:5: Ignoring unknown escape sequences: "su user -c PHPRC\=\/home\/user\/etc\/php7\.3\ PHP_FCGI_CHILDREN\=4\
Dec 15 13:51:55 domain.com systemd[1]: /lib/systemd/system/php-fcgi-domain-com.service:6: Executable path is not absolute: su user -c kill\ \`cat\ \/var\/php\-nginx\/160827070023515\.php\.pid\`
Dec 15 13:58:24 domain.com systemd[1]: /lib/systemd/system/php-fcgi-domain-com.service:5: Ignoring unknown escape sequences: "su user -c PHPRC\=\/home\/user\/etc\/php7\.3\ PHP_FCGI_CHILDREN\=4\
Dec 15 13:58:24 domain.com systemd[1]: /lib/systemd/system/php-fcgi-domain-com.service:6: Executable path is not absolute: su user -c kill\ \`cat\ \/var\/php\-nginx\/160827070023515\.php\.pid\`
Dec 19 04:57:14 domain.com systemd[1]: /lib/systemd/system/php-fcgi-domain-com.service:5: Ignoring unknown escape sequences: "su user -c PHPRC\=\/home\/user\/etc\/php7\.3\ PHP_FCGI_CHILDREN\=4\
Dec 19 04:57:14 domain.com systemd[1]: /lib/systemd/system/php-fcgi-domain-com.service:6: Executable path is not absolute: su user -c kill\ \`cat\ \/var\/php\-nginx\/160827070023515\.php\.pid\`
Dec 19 04:57:15 domain.com systemd[1]: /lib/systemd/system/php-fcgi-domain-com.service:5: Ignoring unknown escape sequences: "su user -c PHPRC\=\/home\/user\/etc\/php7\.3\ PHP_FCGI_CHILDREN\=4\
Dec 19 04:57:15 domain.com systemd[1]: /lib/systemd/system/php-fcgi-domain-com.service:6: Executable path is not absolute: su user -c kill\ \`cat\ \/var\/php\-nginx\/160827070023515\.php\.pid\`

It pointed me to the root cause of the error which is Executable path is not absolute in file /lib/systemd/system/php-fcgi-domain-com.service. The log also points to the exact line within the file that produce the error which is line 6.

I opened the file and this is what I saw at line 6,

ExecStop=su user -c kill\ \`cat\ \/var\/php\-nginx\/160827070023515\.php\.pid\` ; sleep 1

It’s pretty clear now. systemd will not accept commands that are not given with absolute path. So you can’t just su into a user. You need to call a shell. So I changed line 6 to look like below.

ExecStop=/bin/sh -c 'su user -c kill\ \`cat\ \/var\/php\-nginx\/160827070023515\.php\.pid\` ; sleep 1'

And then did,

systemctl daemon-reload

This solved the nginx error: Executable path is not absolute and I was able to restart the php-fcgi services. I think this may be a bug on Virtualmin which I’m sure will be corrected in the next release. But until they do I have to edit these files manually and correct the error for each new site which is a pain.

Anyways I’ve brought it to Virtualmin dev’s attention here.

Tharindu

Hey!! I'm Tharindu. I'm from Sri Lanka. I'm a part time freelancer and this is my blog where I write about everything I think might be useful to readers. If you read a tutorial here and want to hire me, contact me here.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button