WordPress is turning into quite a learning experience for me. After last night’s joy revolving around the version upgrade, I thought things would be smooth sailing for a while. Then today I tried to post about Google Latitude on the iPhone. I took some screen shots and attempted to upload them to my site. The upload attempt failed with an “Error saving media attachment” message. Unfortunately this is not very descriptive, and without additional diagnostic information I was at a bit of a loss.
Much Googling led me to the following knowledge: WordPress is a PHP application, and my hosting provider runs PHP in Safe Mode. This means that there are additional restrictions on PHP scripts which made creating directories and writing to files more difficult. Nearly Free Speech explains their position in a blog post which proved to be most informative. I experimented with changing the permissions on the directory, and changing the group of the PHP script and the directory. However, it was not until I finally understood chmod sgid bit that I had a breakthrough. This is also known as the “sticky” bit. The owner of a directory can set this bit with chmod g+s directory_name and all subsequent directories or files created in that directory will inherit the group id of the directory automatically.
Here’s the necessary steps:
- Change the group of the script to match the group of the user who runs the Web server.
- Change the group of the directory to match the same group.
- Give the same group write permissions on the directory.
- Issue the command
chmod g+sdirectory_name.
You’ll need to do this before there are any subdirectories in the directory, because the inheritance only applies to new directories. Finally, go the Admin screen of your WordPress site and make sure in the Miscellaneous Settings section the correct directory is identified for storing uploaded media.
Let me know in the comments if this works for you, or if I’ve misunderstood something. Here’s the image I was trying to upload:
