I have installed LAMP stack and Wordpress on a local apache2 server using the tutorials here-

  1. https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu

  2. https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-14-04

But when I try to upload a media file (image/sound) I get the error-

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

What might be wrong? I have added my user to www-data group and chown'd the directory /var/www/ as well.

3 Answers 3


You can use this script to fix wordpress permission:

# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
WS_GROUP=www-data # <-- webserver group

# reset to safe defaults
find ${WP_ROOT} -exec chown ${WP_OWNER}:${WP_GROUP} {} \;
find ${WP_ROOT} -type d -exec chmod 755 {} \;
find ${WP_ROOT} -type f -exec chmod 644 {} \;

# allow wordpress to manage wp-config.php (but prevent world access)
chgrp ${WS_GROUP} ${WP_ROOT}/wp-config.php
chmod 660 ${WP_ROOT}/wp-config.php

# allow wordpress to manage wp-content
find ${WP_ROOT}/wp-content -exec chgrp ${WS_GROUP} {} \;
find ${WP_ROOT}/wp-content -type d -exec chmod 775 {} \;
find ${WP_ROOT}/wp-content -type f -exec chmod 664 {} \;

save it to a file and run it and pass it your wp installation directory:

wget https://gist.github.com/Adirael/3383404/raw/6c5446d56477426faeb709e5b807f00422acdea2/fix-wordpress-permissions.sh
chmod +x fix-wordpress-permissions.sh
sudo ./fix-wordpress-permissions.sh /var/www/html


  • This did the trick (as is often the issue, files were owned by a user that copied them, rather than www-data). Thanks for providing this helpful script.
    – jwinn
    Commented Sep 14, 2016 at 22:23
  • At the risk of adding a "me too" comment, I'd like to say that I exhausted numerous search results on the topic from StackOverflow and elsewhere, and this is the set of commands that actually worked for my situation (like OP, I just wanted a WordPress site to be owned by a non-privileged user, but was receiving issue when trying to upload). This answer should be first in Google searches. Thanks! Commented Aug 8, 2018 at 19:37
  • Here is the link to the recommended permissions: codex.wordpress.org/Hardening_WordPress#File_Permissions
    – kjones
    Commented Jan 31, 2019 at 0:51
  • 1
    this made my site 403 forbidden omg ://////
    – Danish
    Commented Jun 30, 2019 at 9:38

Hopefully this helps solve your problem and explain whats going on, to help you in the future too. When you go into the wordpress "dashboard" and upload files - the "user" that is performing the changes to the filesystem iswww-data (i.e. libapache2-mod-php5 via apache webserver). Therefore in order to make changes in wp-content/uploads/2015/01., www-data needs to either have write permissions to the directory or own the directory. This means you can either give the folder liberal permissions by running:

chmod -R 777 wp-content/uploads

Note: you will have to cd into the wordpress directory first, and if you dont currently own the folder, you will need to use sudo

However in my experience, this will result in problems , i.e. once you fix that permission issue, you will likely run into more problems when wordpress tries to write files to other directories e.g. when it updates, new plugins etc. so in that case i would use:

sudo chown -R www-data <wordpress-parent-directory>

and let www-data own the entire folder.

Note: its not such a big deal on local install but when you move to production server, need to be careful with permissions, and generally only give webserver absolute minimum permissions it needs to do its job.

  • @goelakash I sure hope you did not do this chmod -R 777 wp-content/uploads. The answer from sajjadG is what you should follow.
    – Rinzwind
    Commented May 23, 2015 at 14:42
  • I agreed with @Rinzwind do not give 777 permission to uploads directory, It means anyone ( including your visitor) can upload files in this directory. it will make your application vulnerable, instead follow sajjadG 's instructions, I would like you to consider reading this article smashingmagazine.com/2014/05/08/… Commented Jun 25, 2015 at 12:54

Is the wp-content directory really where you think it is?

I notice that the article in question created a directory in /var/www/html/ but wordpress will thing it will be under the wordpress directory that you extracted from the compressed tarfile. In my case it was /var/www/html/wordpress/wp-content which was a softlink to another directory. Once I had fixed the privs and ownership in this location it worked for me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .