When timthumb.php returns a 404 Error in WordPress
We recently migrated some of our websites to a new VPS with Inmotion hosting. After the migration, everything went smooth (pretty much.. but as smooth as a server transfer can be), except one issue – all the timthumb.php scripts were not working well in WordPress, which meant that blog thumbnails were not generating.
So for example, the following URL returned a 404 error, and defaulted to WordPress’ 404 page:
This happened on this very blog (www.jeffkee.com) as well. So then I went to check other things out, and found out that other .php scripts that run from within the wp-content/themes/ folder were not working either! So, the problem was not just timthumb.php, but rather, all .php files within the folder. I tried restarting apache, and the server. No dice.
So I finally looked into the apache error logs, and bingo:
[Thu Feb 04 01:56:02 2010] [error] [client 174.6.169.139] SoftException in Application.cpp:610: Directory “/home/sonikas/public_html/wp-content” is writeable by others
[Thu Feb 04 01:56:02 2010] [error] [client 174.6.169.139] Premature end of script headers: timthumb.php
[Thu Feb 04 01:56:07 2010] [error] [client 174.6.169.139] SoftException in Application.cpp:610: Directory “/home/sonikas/public_html/wp-content” is writeable by others
[Thu Feb 04 01:56:07 2010] [error] [client 174.6.169.139] Premature end of script headers: test.php
So yes, some servers have more advanced PHP security set up, so that PHP files cannot run from within folders that are writable by others.
Many of us have the common (and bad) habit of setting the permission to 777 for folders that should be writable by our PHP applications. However this is not the case. It must be set to 755, in which the “group” and “others” users cannot write the folder.
The “Premature end of script headers” error happens when the script stops running before it outputs the content type headers and dates etc. In any file served through a browser, the content type and other items are defined even before the first string of the file (for example, <html>) are fed out. So when this failed, it returned a 404 error, which in turn triggered WordPress to default to the 404.php error page!
So the lesson here: instead of 777, let’s use 755 for folders that need to be modified/written by your PHP scripts.
I had help from a great guy at StackOverflow.com (username jsalonen). Without his guidance of the server error log locations I would not have figured this out anytime soon. Please see the original question at StackOverflow.com.




(4.67 out of 5)
Thanks Jeff, This sorted it out for me!
Hi Jeff, sadly this didn’t work for me.
I too am getting 404 error messages when I try to access timthumb.php, or really, any php file on my server. WordPress keeps throwing 404 error messages even when I try to access files in my WordPress root folder, such as http://mydomain.com/header.php or http://mydomain.com/footer.php.
It seems like WordPress does not want to process any URLs typed directly, but works fine otherwise when I go through my blog to pages, categories and posts. But accessing .php files directly throws a 404 error.
Any ideas? Thanks.
Getting into the raw Apache error logs is the best way to diagnose this. Is this happening even within the root folder? Cause if that’s the case you may have a different problem than me…
I just setup wordpress on a dedicated WIN2003 server, was having a lot of the same access rights issues. Glad to see you got them figured out.
Hi Jeff!
I’m from Italy and I was looking for a site like yours. I’m using form my Blog the same theme: Arthemia. I’m having a really bad issue with Facebook Share not showing any Thumbnail when someone shares a Post! I tried sharing one of yours and I’ve noticed that prewiew shows perfectly! Could you please tell me how did you fix the problem?
I’d really appreciate that!
I had a customer that migrated from a Plesk powered server to my cPanel based one.
This article saved their blog, as no thumbs were showing on their either, after migration.
Thank you.
I cannot thank you enough!