7

I have a VPS from 1&1 with CentOS 5.2 64-bit.

Last Tuesday I've upgraded PHP and installed ImageMagick which had to upgrade many other packages, including Apache, MySQL, Perl, etc. Lots of stuff got upgraded in the process but being a complete noob I just went with it.

Now the problem is that all the websites look like this:

1.
2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/    xhtml1/DTD/xhtml1-transitional.dtd">

(a new line on every single PHP file before output)

I even tried ob_start(); and die(trim(ob_get_clean())); with no luck. The new line continues to persist.

I briefly checked /etc/php.ini with nothing standing out.

What can I do?

Silviu-Marian
  • 10,565
  • 6
  • 50
  • 72
  • And what does one of your PHP pages look like? – Jon Feb 12 '13 at 05:30
  • It doesn't do this locally. Worked very well before the upgrade. It's not BOM, I just tried `header("Content-type: text/html; charset=utf-8");` nothing good. The problem is still here. – Silviu-Marian Feb 12 '13 at 05:33

2 Answers2

6

Shot in the dark, but check your php.ini for an auto-prepend-file value. It might be pointing to a blank default file which happens to have a line break.

AlienWebguy
  • 76,997
  • 17
  • 122
  • 145
  • Just checked `/etc/php.ini`, I have `; auto_append_file = ` and `; auto_prepend_file = ` both commented out. :( – Silviu-Marian Feb 12 '13 at 05:44
  • 1
    +1 for those ini directives, I had forgotten those tricky guys were in there. I could also see some sneaky plugin/upgrade using it to make their code 'globablly' available. – Patrick M Feb 12 '13 at 05:51
  • `pear list: Archive_Tar, Console_Getopt, Mail, PEAR, Structures_Graph, XML_RPC; pecl list: imagick.` compacted for convenience. – Silviu-Marian Feb 12 '13 at 05:56
  • After a major struggle I discovered that the `php.ini` had an extra `[COM] auto_prepend_file=/tmp/.tmp.err` which contain the God-damn new line. commented that out and everything is fine!!!!!! whew! – Silviu-Marian Feb 12 '13 at 07:00
  • HAH! The shot in the dark strikes again! :) Glad I could help man, cheers! – AlienWebguy Feb 12 '13 at 07:02
3

The most probable cause of this is some base include file having whitespace at the end of it. If any include file has any characters outsite of the <?php and ?> tags, including line breaks or spaces, then apache will write a blank line to the beginning of the response, like you're seeing.

Unfortunately, any file in your include chain could be the culprit. If you're on a shared hosting provider, then you may need to contact their support to ensure they don't have any wacky php auto-include behavior or apache directives, like AlienWebguy mentions. Here's a good Stack Overflow question about best practices for include files. (It even points out that Smarty, a 3rd party php templating plugin had spare whitespace in its include files, even in recent/current releases.)

And here's a likely looking article for how to find and kill pages with whitespace on them. If your *nix-fu is strong enough, you could grep your file structure with a regex to try and find any such culprit. Preventatively, Mario in the SO question linked posts a few php directives which can warn about it, which could be thrown into an svn commit hook to catch any such future errors.

Community
  • 1
  • 1
Patrick M
  • 10,547
  • 9
  • 68
  • 101