It happened again. When I logged into the WordPress dashboard, I saw that the NextGen Galleries plugin had a new update available. Updating WordPress plugins has become so routine that I take it for granted that pressing the magical “Update All” button will magically make my WordPress installation shiny and new. I can drink my coffee and watch plugin after plugin happily announce a successful update, one after another after another after another. And then NextGen Galleries takes a big dump all over my day with a “can’t delete directory” message.
As anyone whose worked on a few WordPress sites knows, WordPress is pretty finicky about file and user permissions, and setting file permissions incorrectly can break WordPress outright, or (more likely) open it up to being hacked. I typically follow the guidelines covered in the WordPres Codex article “Hardening WordPress,” but after verifying my file permissions were set correctly via my FTP client, and even after connecting to the server and running CHMOD against the directory and files, I was still getting the same “can’t delete directory” message.
After banging my head against the wall trying to figure out what was so “special” about my NextGen Galleries installation, I remembered that I had originally uploaded the plugin via FTP rather than via WordPress’ automatic plugin installer.
Even though my file permissions were set correctly, the “owner” of the files and directories was set to my FTP client account. To work properly, the files and directories needed to be owned by the same user and part of the same group as the web server (in this case an Apache server).
To fix my plugin ownership issues, I used my favorite SSH client, PuTTY, to connect to my Linux host server. After navigating to my WordPress “plugins” directory, I ran the following command:
chown -R apacheusername:apachegroupname /path/to/wp-content/plugins/nextgen-gallery
In the example above, the “-R” flag tells chown to recurse the subdirectories and files.
This same technique works for themes, plugins and anything else WordPress needs to be able to write. Of course, the most important lesson to be learned from the “can’t delete directory” message is to install plugins and themes from inside WordPress whenever possible, and save yourself the headache.
For more information about how to use CHOWN, check out this article.