What is the “premature end of script headers” PHP error?
A common php error seen, however rarely known or understood is the “headers already sent” error. Which may look similar to this:
Premature end of script headers: /home/user/public_html/index.php
Why does it happen?
Premature end of script headers “actually means”, the script stopped for whatever reason before it returned any output to the web server. This can be an extremely difficult error to diagnose.
Debugging Premature end of script headers / Solutions
Some suggested areas to consider or debug for the loathed ‘Premature end of script headers‘:
PHP Version Changes
Have you upgraded or downgraded your version of PHP recently? It is possible that your websites code/core functionality is not compatible with the version of PHP you’ve changed to.
Required File Path Changes
If your website/program uses the require_once() function, it specifically requires a file at a certain location. If you’ve changed/renamed/moved files or folders recently, this could be the casue of your issue. Also, one of the easiest fixes I might add.
CPU and Memory Limits
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. Check your httpd configuration file ( /usr/local/apache/conf/httpd.conf
) for any RLimitCPU
or RLimitMEM
settings and adjust them accordingly.
Thirdy Party Apache Modules
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 these are the cause, additional information relating to specifics will be found in the apache error_log.
HUGE Log File
If suPHP’s log reaches 2GB in size or larger you may see the premature end of scripts headers error. See what the log contains and either gzip it or null it. Restart apache and then deal with any issues that the suphp log brought to light. The suphp log is located at: /usr/local/apache/logs/suphp_log
Permissions
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. In this case, the error may simply be pointing out that an unauthorized user is attempting to access a script.
Enable Error Reporting
Enabling error reporting on a PHP version of a website could help diagnose the error more in depth. Add the following snippet to your index.php file of the related site for possible additional information:
<?php error_reporting(E_ALL); ?>
Where’s the whitespace?!
Sometimes this error can be related to a trailing whitespace or returns after your closing ?>
in the script/site.
Content Management Systems
If you are using a commonly used Content Management System (ex. WordPress, Drupal, Joomla, etc.) there are numerous references to these errors available online. It’s beneficial to note any plugins, themes, or add-ons that you’ve recently installed as well as the version number of the installed CMS when searching for the issue.
Conclusion
Have a WordPress website? Check out our Managed WordPress Hosting and see if we are a good fit for you. KnownHost offers 365 days a year, 24 hours a day, all 7 days of the week best in class technical support. A dedicated team ready to help you should you need our assistance. You’re not using KnownHost for the best webhosting experience? Well, why not?