Sunday, June 19, 2011

HTTP Error 500, suexec and fcgi debugging tricks

I have been getting error 500 on my webserver in many occasions that i personally would consider inappropriate! because the error logs are simply cryptic, general and misleading, or even non-existent. I had to figure out a few tricks that allow me to figure out whats the reason for the errors without relaying much on the logs. here is a short documentation of them:

emulation of suexec+fcgi :

On the command line, switch to the user that is executing the php scripts, lets assume its "mywebsiteuser1"; so :

su - mywebsiteuser1

this might fail because this user might not have a login shell (login shell set to /bin/false for example); thus you might need to edit /etc/passwd and set a loginshell for this user; lets say /bin/bash. its a good idea to use vipw instead of vi (you need to do this as root).

Now cd to the directory where you have your .php files, and try something like this:

cat index.php | /var/www/fcgi/mywebsite.tld/php5-fcgi-starter


This should reveal more info about the error that what you are getting (or not getting) in the logs or in the browser. the file output is being piped to is the fcgi php wrapper.

I hope a similar thing can be doable in real life, imagine to be able to track and debug the problems in palestine/israel, where the logs are also very messy, cryptic or even non-existent. and you usually end up with the Israeli error 500 (internal system error) hiding the details of the permissions denied for liberty of Palestinians; my people.

Note that permissions must be correct on every part of this mess! the file owners, the user running the code, the wrapper owner ...etc.

No comments: