problems running under php/fastcgi (19 posts)

  1. scruby
    Posted 10 years ago #

    FastCGI is very picky about there being only one "Status" header being sent from apps. So, if like me you are running wordpress under php/fastcgi, you get errors like this:

    [Sat Apr 01 23:30:42 2006] [error] [client] FastCGI: comm with server "/var/www/fcgi-php/php" aborted: error parsing headers: duplicate header 'Status'

    This behavior is discussed on php bugs:

    According to php bugs, the resolution to this problem is at the programming level.

    In wordpress, in file /wp-includes/functions.php there is the following two lines of code:

    @header("Status: $header $text");
    @header("HTTP/1.1 $header $text");

    In order to make wordpress play nicely with fastcgi, I had to replace those two lines with the following four lines:

    if (substr(php_sapi_name(), 0, 3) == 'cgi')
    @header("Status: $header $text");
    @header("HTTP/1.1 $header $text");

    I'm hoping that the wordpress developers will incorporate this change into the next update of wordpress.

  2. Mark (podz)
    Support Maven
    Posted 10 years ago #

    If you file this over at http://trac.wordpress.org that would be very helpful.

  3. scruby
    Posted 10 years ago #

    Thanks. Opening a ticket.

  4. dje
    Posted 10 years ago #

    This solved the 404.php problem I had immediately. My server was running fastcgi with PHP5. I cannot believe how quickly that solved the problem that I thought was caused by an incorrect .htaccess file.

    Thank you very much for this solution. Can I vote for your ticket to prioritise it?

  5. sblamey
    Posted 10 years ago #

    I came across this solution when trying to troubleshoot a problem with my 404 page - whatever non-existing URL is typed, wordpress responds with index.php

    I thought the above might help since the blog in question is hosted on a server running PHP under cgi and not mod_php. However, having made the change, wordpress still shows index.php when trying to visit a non-existing URL.

    I set-up a test blog on some other web-space that I have that does use mod_php and the result is better - the apache server returns a 404 page, but not the 404.php in the defult template.

    It seems that many others are having problems with 404 and there are numerous tips that work for some and not others. Does anyone know if this is close to being nailed?

    I am using wordpress 2.0.3 for both installations.

  6. sblamey
    Posted 10 years ago #

    I did some more work on this and added .htaccess to my test blog. Everything works as expected with wordpress showing the 404.php for non-existent URLs.

    This must be something todo with the hosting setup on my other blog, where PHP runs under cgi. I've checked that .htaccess is being used and rewriting is taking place.

    Can anyone point me to another thread here as my problem does not seem related to the above.


  7. fak3r
    Posted 10 years ago #

    Not sure if this is a similar issue or not, but I can't get Permalinks running, so I've recompiled PHP5 w/o FastCGI support, now it just should be PHP running under CGI, but I can't get Permalinks to work, or the 404 page. See if any of my issues appear as yours:


    You'll see that the rewriting is working, but no 404 page is ever shown, just the rewriten URI, which it fails to find (even though my .htaccess file is good and I have mod_rewrite running and working on this server)



  8. dje
    Posted 9 years ago #

    I have upgraded to 2.0.4 and the above bug and I can see that the above fix has not been incorporated into the core. So I made the changes to functions.php as above and the problem was solved.
    How can we ensure the fix is incorporated?

  9. dje
    Posted 9 years ago #

    I have upgraded to 2.0.5 (from 2.0.4) and the above fix has still not been incorporated into the core as my error 404 page was not working after upgrade (I was just getting a server error). So I made the changes to functions.php as above and the problem was solved (again).
    How can we ensure the fix is incorporated into the next release?

  10. llizard
    Posted 9 years ago #

    I too just upgraded from wp2.0.4 to wp2.0.5 (with default permalink structure). I am in the minority of wp users who had to install the 500 server error fix plugin. There was some mention that it might be wp run with fastcgi (have NO idea what fastcgi is) that experience this 500 error problem with WP2.0.5.

    Thinking that perhaps FastCGI is what my host uses, I applied the fix to /wp-includes/functions.php. Some improvement: a 404 page now appears rather than the page just opening to the index page of my wordpress. However, my custom wordpress 404 page isn't appearing; it defaults over to the 404 page for my whole site.

    I've searched this forum but have not found a fix that works. Any ideas? (Please bear in mind that I only know enough about php coding to get me in trouble)


  11. hrachovec
    Posted 9 years ago #

    Hello. I believe I may be having a similar problem as mentioned in scruby's first post. However after using the suggested code tweak, there's no improvement: I still get a browser error message 'Failed to open page' when I try to access my wp-admin page. Can someone provide any suggestions or point me to another post?

    When I contacted my web host they revealed I had this problem when accessing the above page:

    The problem seems to be that a script is generating double headers, wich cause a 500 error:
    front05.web: [Fri Nov 10 14:07:36 2006] [error] [client] FastCGI: comm with server "/var/www/00/31/62/simonfanshawe.com/cgi-bin/php-fcgi-starter" aborted: error parsing headers: duplicate header 'Status'

    ..and they pointed me here. But after making scruby's suggested change to the /wp-includes/functions.php file, there's still no improvement.

    Any feedback would be welcome.

    PS: For what it's worth. I reloaded all WP files on the server and the admin page then worked. But as soon as I logged out, I got the same problem as stated above.

  12. hrachovec
    Posted 9 years ago #

    Oh no. I've spoken too soon. I got it sorted thanks to that patch listed by llizard. many thanks!

  13. Ghidra99
    Posted 9 years ago #

    scruby's fix helped get rid of my 404 Errors. Thanks!

  14. froggystone
    Posted 9 years ago #

    Yes i can confirm that the fix works

    In addition people who has b-one or one.com as host is gonna need this fix cause of the use of FastCGI

    further more, plz implement this fix till next release :)

  15. dje
    Posted 9 years ago #

    Now fixed in 2.0.6

    I have upgraded to 2.0.6 (from 2.0.5) and now I no longer have the problems mentioned above. In other words, whatever they have incorporated this fix into 2.0.6 and it now works!

  16. llizard
    Posted 9 years ago #

    I finally got the custom 404 page I created specifically for wordpress to display by adding a line to the .htaccess in the wordpress root folder:

    ErrorDocument 404 http://domainname/wordpress/404.shtml

    Why 404.shtml? Because I was getting an error message in the 404.php I created....

  17. llizard
    Posted 9 years ago #

    Excuse me for replying to myself...

    I also found I had to put the 404 page into the root folder of wordpress, which is why I was getting error messages on the 404.php

    To get my 404.php to work, I had to remove all instances of <?php bloginfo('name'); ?> and <?php _e('search '); ?> because of course, those functions will only work if the php page is in the theme folder...

    I have now switched to using 404.php

    However, because of the addition to the .htaccess file, I cannot use the following

    The page you were looking for at <strong>http://<?php echo $HTTP_HOST.$REQUEST_URI; ?></strong> does not exist on this site. Please check for typo(s)

    because it merely shows that ../404.php has been requested....

    Anyone know how I can get the 404 page to work correctly?
    (I'm running WordPress 2.0.7)

  18. llizard
    Posted 9 years ago #

    Please excuse me for replying to myself one last time... I was looking around in this forum and found the answer here:

    which pointed me to
    WordPress codex: Creating_an_Error_404_Page

    Using the instructions on that page, I put
    <?php header("HTTP/1.1 404 Not Found"); ?>
    at the top of my 404.php and the following in the body of 404.php:

    Whatever it is you were looking for at
    <strong>http://mydomainname<?php echo $_SERVER['REQUEST_URI']; ?></strong>
    does not exist here.
    Please check for typo(s) and/or use the search engine located on this page

    and then uploaded the 404 file in my theme folder.

    I then added the following to the .htaccess file that is in the blog root folder:

    ErrorDocument 404 /wordpress/index.php?error=404

    The 404 is now working as I had hoped and I believe this issue can be marked resolved.

  19. AskApache
    Posted 9 years ago #

    Also read

    FastCGI on DreamHost

    And dont ever pass a full url to ErrorDocument 404 because it will lose all the REDIRECT variables in apache.

Topic Closed

This topic has been closed to new replies.

About this Topic