Search code examples
phpapache.htaccessinternal-server-error

Apache Internal Error 500 on PHP syntax errors (htaccess)


Recently something changed on my server, which has been causing an internal error 500 to be thrown everytime there is a syntax or logical error in PHP. These errors are handling in the exception class and I dont want them throwing the 500 error.

Forgot To Mention : when the page doesnt exist => 404 errors work just fine

I current have error_reporting on to strict. I am thinking it could be my apache config file

 <Directory /var/www/public/>
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{QUERY_STRING} (.*)(http|https|ftp):\/\/(.*)
    #RewriteRule ^(.+)$ - [env=rfi:true]
    #RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^domain\.com$ RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
    </IfModule>
    #CustomLog /path/to/logs/rfi.log combined env=rfi
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    ErrorDocument 404 http://www.domain.com/404.php
    #ErrorDocument 403 http://www.domain.com/403.php
    ErrorDocument 500 http://www.domain.com/500.php
 </Directory>
 <Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
 </Directory>
 ErrorLog ${APACHE_LOG_DIR}/error.log

Does anyone see anything that might be causing the 500 error?


Solution

  • A syntax error cannot be caught by PHP. If a file can't be parsed, you'll get an unavoidable 500 error. You can setup your php.ini to not display the errors on the client, but it will still log the error.

    To suppress all errors from being sent to the client, in the php.ini file set

    display_errors = Off

    When a 500 error is encountered they'll just see a white blank screen.

    There is no way to email you when this happens outside than having some script monitor your apache an php error logs. You might be able to set a error.php file to show on 500 error by configuring it in you htaccess file, but i dont know. If you can, you could put some basic php email code into that, but it would be generic--it couldn't tell the actual error.