Home   Profile   Fun
#160 Linux  07.01.2008

PHP scripts and HTTP error 500


If a PHP script causes a HTTP error 500 (internal server error) you may find the solution at a place totally unexpected. I assume here that the script is basically valid, has no syntax errors, the correct permission etc. One possible reason for this error is a misconfigured basedir parameter in the php.ini. That means if you have set the basedir to a certain directory and you try to run a PHP script outside of this directory tree you get the HTTP error 500.

In the Apache logs it looks like this:
84.169.241.11 - xyz [12/Mar/2008:05:21:38 +0100] "GET /test.php HTTP/1.1" 500 - "-" \ 
"Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.12) Gecko/20080203 \
SUSE/2.0.0.12-0.1 Firefox/2.0.0.12 FirePHP/0.0.5.26"

So open the Apache php.ini and verify that the open_basedir parameter has a correct value.
# vi /etc/php/apache2-php5/php.ini

; open_basedir, if set, limits all file operations to the defined directory
; and below.  This directive makes most sense if used in a per-directory
; or per-virtualhost web server configuration file. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
open_basedir = /var/www/www.domain.xyz/

# /etc/init.d/apache2 restart