44

I am not able to upload any images to the Media section. I get this error message:

"Unable to create directory wp-content/uploads/2015/05. Is its parent directory writable by the server?"

I tried changing the permissions, gave full access 777 to both uploads, and wp-content directory but this didn't help.

I tried changing the owners to apache : apache for /wordpress/wp-content, but that hasn't helped either.

upload_path is set to wp-content/uploads in option-media.php. Still it is not working.

Tried defining upload path define(UPLOADS, 'wp-content/uploads');No Help.

(server: centos)

Someone, please help!!!

-Thanks in advance.

Aasim Hussain Khan
  • 1,137
  • 3
  • 15
  • 33

22 Answers22

42

Debian like:

chown -R www-data:www-data /var/www/{yourpath}/wp-content/uploads
  • 8
    This will only work if you are on a Debian/Ubuntu like distro. For RH/CentOS and the like you'll need to use apache:apache as those are the appropriate accounts. Also, you don't need that on the entire /var/www. That would be an insecure setup. Apache only need write access to places you intend to upload through the website. – Josiah Jul 16 '15 at 21:40
  • 1
    This works fine for me. However the path could vary depending on the installation. In my case it is /usr/share/wordpress/wp-content/uploads – Tushar Saxena Apr 22 '20 at 06:21
  • Works like charm on Ubuntu! – Professorval Feb 11 '21 at 11:49
13

I was having a similar problem after migrating from a development site to a production site. It turned out that the message is deceptive. Check Settings, Media. Verify the directory for media is accurate for the current site. If the site was migrated, the directory listed still be from the old site and may need to be updated.

MRMorrell
  • 131
  • 2
7

Change permissions on the /wp-content directory to 0775 and try it again.

sudo chmod 0775 {yourpath}/wp-content/uploads

If it fails, change the permissions to 0777 and try again.

sudo chmod 0777 {yourpath}/wp-content/uploads

Once it is successful, be sure to return the permissions on /wp-content to whatever they were when you started.

You may also want to put the permissions back on any other files you changed while attempting to resolve the issue.

More options you can find here: https://www.tipsandtricks-hq.com/how-to-fix-the-unable-to-create-directory-error-in-wordpress-5264

Reggards

Andaramis
  • 119
  • 1
  • 4
6

If this error is showed after migrating wordpress to new server check upload path in: settings->media->Store uploads in this folder

default value is wp-content/uploads.

Probably you have old path.

Sasa Jovanovic
  • 324
  • 2
  • 14
6

You may have to add a folder named uploads first before you change any permissions.

My environment is xampp in Ubuntu 18.04 and the Wordpress installation failed to create the folder 'uploads'.

cd into the wp-content directory.

mkdir uploads

while still in the wp-content path, use chmod 0777 to add the relevant permissions:

sudo chmod 0777 uploads

This worked for me.

Warui Kamiri
  • 111
  • 2
  • 7
5

Go to wp-admin/options.php
Under upload_path replace with exactly wp-content/uploads (no quotes, no extra slashes)
That worked for me after I had tried to all other solutions for days.

Adam Silenko
  • 3,025
  • 1
  • 14
  • 30
tussa33
  • 51
  • 1
  • 1
5

This is a solution when you are on your local but can be applied also on a server.

Sometimes if you get a backup from the database that is on a server and you recover it on your local you will have this problem: "Unable to create directory..." even if you have the correct permissions on your folder. This happens because WP points to a value on upload_path on the database.

So go to wp_options table.

Search for upload_path and check if the path is correct.

If not. (on mac and unix) Go to your upload folder, drag it to the terminal. And use pwd command copy the response on upload_path on the database.

Hopefully this will help someone.

perseus
  • 1,322
  • 1
  • 16
  • 22
4

I tried all the solutions from How to Fix the Unable to create directory Error in WordPress in my Centos7. But it won't work.

Then I found some useful message in /var/log/audit/audit.log

type=AVC msg=audit(1495357844.782:604): avc: denied { write } for pid=2721 comm="httpd" name="wp-content" dev="dm-5" ino=1074299184 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:etc_runtime_t:s0 tclass=dir type=SYSCALL msg=audit(1495357844.782:604): arch=c000003e syscall=83 success=no exit=-13 a0=7fffba9c62c0 a1=1ff a2=8 a3=5 items=0 ppid=1556 pid=2721 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)

Check the file infomation : ls -Z /data/web/wordpress

Found that SELinux prevented Httpd to access the files. So you can disable the SELinux, or modify the file context: chcon -R --type=httpd_sys_rw_content_t /data/web/wordpress . And it works.

Mahendra Gunawardena
  • 1,956
  • 5
  • 26
  • 45
RyanLei
  • 41
  • 1
  • You are a life saver. Been looking for a solution to this for a week and this was the only thing that worked. Never even heard of SELinux until this post. Moral of the story, never use CentOS for wordpress lol stick to debian. – Bigfatty Jun 02 '19 at 23:43
3

I have managed to solve this by updating the reference to Settings Media Store uploads folder.

Go to WordPress admin -> Settings -> Media, and update Store uploads in this folder option with what is in your public_html hosting account.

/home/<base_folder_name>/public_html/wp-content/uploads

For me the <base_folder_name> was different than what was in the hosting account.

zfd
  • 31
  • 2
  • I tried everything for my GoDaddy Hosted account and this was it! this was only needed in my root application; any application in a sub-folder was OK. – azpc Mar 01 '18 at 04:41
3

To solve this annoying error, you need to change the path of the old uploads folder to the new one. Follow these steps to solve the problem:

Log in to your WordPress admin panel (wp-admin). In the left menu go to Settings » Media. Media Settings - WordPress In the Store uploads in this folder field, enter wp-content/uploads and click Save changes. Change WordPress Uploads Folder Now you are done, go and try to upload files to the media library again. NOTE: make sure that the Store uploads in this folder field container image description here wp-content/uploads only.

Follow this image for right direction

enter image description here

Another Way:-

If you can’t find the field on your media settings page you can solve the problem by adding the following code in your wp-config.php file:

Go to wp-config file........ using FTP or Local server paste the following code

define( 'UPLOADS', 'wp-content/uploads' ); require_once(ABSPATH . 'wp-settings.php');

And the “Unable to Create Directory wp-content/uploads. Is Its Parent Directory Writable by the Server” error will be fixed.

2

"The uploaded file could not be moved to wp-content/uploads/2015/05."

This error comes because of insufficient permission to your user on to the server.

One Quick and dirty way to solve this error is to set 777 permission but some time it may not also work.

Follow this link this will help you http://2surge.com/how-to-fix-the-uploaded-file-could-not-be-moved-to-wp-content-error-message/

Thanks

rajatsaurastri
  • 653
  • 3
  • 21
1

Try following. Make sure {yourpath} is replaced with correct path

Creates upload directory with super user permission

sudo mkdir -p /var/www/{yourpath}/wp-content/uploads

Change ownership to the current user

sudo chown -R $USER:$USER /var/www/{yourpath}/wp-content/uploads
Ruwantha
  • 2,603
  • 5
  • 30
  • 44
1

This is sometimes an issue with file and directory ownership than permissions. Find out the user the php code is executing as using phpinfo() page.

Once you know the system user, make sure the FTP account you are using is configured to upload the files as that user. If it has been uploaded using different user, use chown to change the ownership of the base path to match the user.

For example:

$ sudo chown -R <user> /path/to/public_html
Dilip Raj Baral
  • 3,060
  • 6
  • 34
  • 62
1

I had the same problem here on a Parallels Plesk server. I had to change the access permissions for the webserver/website user using the access options from within the file manager.

Hope this helps!

Mat
  • 958
  • 8
  • 18
1

This solution worked for me:

chown -R www-data:www-data /path-to-mywordpress-root-folde
Dinidu Hewage
  • 2,169
  • 6
  • 40
  • 51
1

I was looking for a MAC/ OSX solution and found this related question but it didn't help. The following works for me: 1- Right-click on wp-content and go to Get Info and change permissions as follow:

Changing permission for wp-content folder

After click on the setting gear icon and Apply to enclosed items....

Apply to selected items

Maihan Nijat
  • 9,054
  • 11
  • 62
  • 110
1

I'm an Arch Linux user. My WordPress location is (/srv/http/wordpress). I faced this problem before.

At first, I change my WordPress ownerships to $USER:http.

sudo chown -R -c $USER:http /srv/http/wordpress

(don't go root to change ownership with this command then $USER will be root)

you can check who is the user with

echo $USER

I created an uploads folder in wordpress/wp-content/uploads. Then give the read, write, and execute permission to the user and group of wp-content and wp-content/uploads directory.

sudo chmod 774 wp-content/
sudo chmod 774 wp-content/uploads/

hope it will helps someone.

0

Just run this command:

sudo chown -R www-data /path/to/wordpress

hope it helps.

Mao
  • 77
  • 2
  • 7
0

For manjaro Linux in the wordpress directory:

sudo chown -R  http:http wp-content

That worked for me.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • You should perhaps ask him first to check what user and group the directory is with something like `ls ll` and what user and group Apache uses on his CentOS server using: `egrep -i '^user|^group' /etc/httpd/conf/httpd.conf ` as suggested at https://serverfault.com/questions/416236/what-is-centos-5s-apache-user-group . Then you can change user and group rights when need be . NB `stat -c "%a %n" *` helps checking chmod rights in numbers. – rhand Sep 28 '19 at 00:37
0

For me it was a disk space issue - my account was simply over its quota and therefore would not allow any increase in the form of a folder creation or plugin installation.

Simply clear some disk space and try again.

roy650
  • 633
  • 1
  • 10
  • 18
0

For me I had migrated to another server and my media settings had got clobbered. I had to explicitly reset the uploads folder.

Here's what worked for me :

From your Wordpress dashboard go to Settings->Media and set

"Store uploads in this folder" to "wp-content/uploads"

pcodex
  • 1,812
  • 15
  • 16
0

these problem maybe you have faced after changed your hosting just log in your wordpress and and go to Media just change path wp-content.

you can check in deep:- https://blog.aaaenos.com/unable-to-create-directory-uploads-year-month-is-its-parent-directory-writable-by-the-server/

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 07 '22 at 09:27
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31698509) – jrswgtr May 11 '22 at 10:01