Symptom:
When attempting to add media to a WordPress post, the image is rejected and the following error message appears:
Cause:
The WordPress uploads directory (typically located at /var/www/html/wordpress/wp-content/uploads) on the web server does not have write permission enabled and/or the web user (likely www-data) is not a member of the group which the uploads directory belongs to.
Solution:
Give the group which owns the uploads directory write access
sudo chmod -R g+w /var/www/html/wordpress/wp-content/uploads
The -R option will add group write access recursively to all the subdirectories and files beneath the uploads directory.
Add the apache group (www-data on Debian) to the group which owns the uploads directory
sudo adduser www-data groupname
Troubleshooting Steps:
- Check the apache logs for error messages:
- /var/log/apache2/access.log
- /var/log/apache2/error.log
- Try adding www-data to the group which owns the uploads directory
- Change the permissions of the upload directory recursively to allow group write access to all subdirectories and files