Ubuntu – WordPress can’t upload files

Apache2lampMySQLpermissionsWordpress

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.

Best Answer

You can use this script to fix wordpress permission:

#!/bin/bash
#
# 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

https://gist.github.com/Adirael/3383404

Related Question