I.el-sayed
I.el-sayed

Reputation: 325

Uploading media in Wordpress

I am trying to upload images or any other media type to my wordpress application, but I get this error:

Unable to create directory /home/admin/video/wp-content/uploads/2012/07. Is its parent directory writable by the server?

even though I am sure that the parent directory is writable. It actually has 777 permissions. What might be the problem?

Thank you.

Upvotes: 0

Views: 814

Answers (2)

user604234
user604234

Reputation:

You may also see if is correct your "Settings->Media" and then look to "Uploading Files" section.

The folder(and all subfolders) indicated into "Store uploads in this folder" must have 755 permissions.

Upvotes: 0

Conner
Conner

Reputation: 31060

The question is... writable by who or what? You probably need to make the entire "uploads" directory writable by PHP (a.k.a. the web server). Often, apache and other servers default to the user-group www-data, but it could be different. Check your apache or lighttpd (or whatever) configuration files to see what user and user-group it runs as. Often these are in /etc/apache or /etc/lighttpd et cetera. Then, make the uploads directory recursively writable to that group.

Using 777 permissions is a very bad idea. You always want to give the minimal amount of people access to any given directory. So, here's a short discourse on file permissions....

drwxrwxrwx   20  connermcd     staff    680 Jul 25 20:38  img
-rw-r--r--    1      admin  www-data  18530 Jul 26 21:46  example

The first character of the permissions string denotes the type. In this case, img is a directory and example is a file. This could also be an l for a symbolic link (among other things). The remaining characters of the string (rwxrwxrwx) define permissions. As you can see, it's a repeating triplet of "read, write, execute". The first triad represents permission for the file or directory's owner. The owner is shown in the third column (connermcd for img and admin for example). The second triad denotes permission for the file or directory's group (staff for img and www-data for example). The last triad denotes permissions for anyone (even someone you gave temporary access to your server or a hacker, hint hint).

Each of the "read, write, execute" triads can be represented by a number. It's easy for me to think about rwxrwxrwx as 421421421. It's the only way multiples of two can add up to 7 if that helps you. So, the 4 stands for read, the 2 stands for write, and the 1 stands for execute. If you add these together then you can denote a triad with three numbers. So what chmod 777 img is really doing is giving "read, write, and execute" permission to everyone. It is also only setting those permissions for that directory and not the directories underneath it. To do this recursively you can use the -R flag -- chmod -R.

In your case, you just want to make the uploads folder and all its subdirectories available to the user group your server runs as. In most cases that's www-data, so I'll use that as an example. You probably want to set your project files as owned by your user to make them easier to move, edit, etc. So let's assume you are the owner of the files (use chown to set) and that they belong to the www-data group (use chgrp to set). In that case we want to give the owner full permissions and the group read and write permissions, and we want to do it recursively. So go to the parent directory of the uploads folder and do chmod -R 760 uploads.

Upvotes: 1

Related Questions