The other day, I’ve been pulling my hair because suddenly, the media upload on WordPress is not working properly on one of my servers. I’m sure this kind of problem happened to me before. For this time, I traced back what I did the previous days to identify the possible cause of problem.
Based on my log, I only did two things as listed below.
- Upgrade WordPress to 3.5
- Upgrade MySQL to 5.5 (see instructions here
I initially suspected it was a problem brought by WP 3.5 with their brand spanking new media upload module. But endless googling says otherwise. It must be an access rights problem.
Symptoms and Problems
To be clear, there are three different symptoms that I see on the websites loaded into this server.
- A website cannot create the folder (wp-content/uploads/2013/01). I created the folders but the problem stays.
- Another site says “Unable to move image.jpg to wp-content/uploads/2012/01”
- One website asks for FTP credentials when trying upgrade WordPress. It should be automatic.
By now, I’m pretty sure that I’m dealing with an access rights problem. So I started troubleshooting.
- Check File/Folder Owners – Since I run suPHP, I have different users for every group of websites. I made sure that all the folders are owned by the respective users. Even after doing that, the problem still persists.
- Check /tmp folder access – I made sure that all my suPHP users have access to this folder. they all have. I remove the access and the error message is now different. So I put back the access rights again Symptom #2 came back. That means Apache can upload the file but just can’t transfer it to the destination folder.
- Who is writing the file – This is where things get interesting. Remember I use suPHP? Files must be written by the suPHP users and not apache. So what I did was chmod wp-content/uploads/2013/ and wp-content/uploads/2013/01 to 777 (write accessible to the world) and then tried to upload a file. IT WORKED! I checked the owner of the file and found out that it was apache and not the suPHP user. So there must be something wrong on my server.
- Check if suPHP is running – As it turns out, suPHP is not running. I still don’t know when it started but somehow, it does not work. How I manage to bring it back will be for another post.
In the end, the root cause is that suPHP is not running on my server. That means it is the apache user that is actually running on all those sites. Since the files and folders are owned by different users, apache cannot write into those folders. It also cannot create folders.
Once I sorted out the problem with suPHP, re-ran chown on all the folders just to make sure that all files and folders are owned by the correct user. I also put back the correct folder rights(755) on wp-content/uploads/2013/ and wp-content/uploads/2013/01 folders so that it won’t be writeable by the world.