Premature End of Script Headers – Apache Error

Premature End of Script Headers

Premature end of script headers’ is really uncertain error message and difficult to resolve. In this article, we will discuss about possible solutions to resolve this error.

Sometimes when executing a PHP script you will see the following error in Apache error log:

Premature end of script headers: /home/user/public_html/index.php

This error occurs because the server is expecting a complete set of HTTP headers (one or more followed by a blank line), and it doesn’t get them. There are many reasons for this error as follow:

[1] If you have upgraded your PHP version, it is possible that there is another line in httpd.conf mentioined different PHP version. You can check your installed PHP version using php -v command via SSH. If you find a line mentioning different version in httpd.conf, comment it, distill the httpd.conf and restart Apache service.

[2] The RLimitCPU and RLimitMEM directives in the httpd.conf may also be responsible for the error if a script was killed due to a resource limit.

[3] A configuration problem in suEXEC, mod_perl, or another third party module can often interfere with the execution of scripts and cause the error. If there is a configuration problem, you should get more information from Apache error logs.

[4] If suphp’s log reaches 2GB in size or larger you may see the premature end of scripts headers error. You can zip old logs or null it and then restart Apache and then check the suphp logs. The suphp log is located at: /usr/local/apache/logs/suphp_log (for cPanel server).

[5] The script’s permissions may also cause this error. CGI scripts can only access resources allowed for the User and Group specified in the httpd.conf. If the ownership of the script is different then allowed user/group in httpd.conf, you will receive premature end of script headers error.

Leave a Reply