WordPress: Unable to create directory wp-content/uploads… Is its parent directory writable by the server

While uploading the images on WordPress site if you are getting the following error:

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

then you need to follow these steps on Ubuntu server:

Let’s say the path of your WordPress site on the server is: /var/www/my.wordpresssite.com/.

Run the following commands on your Ubuntu server:

sudo groupadd www-my-grp

sudo chgrp -R www-my-grp /var/www

sudo chmod 2775 /var/www

sudo find /var/www -type f -exec chmod 2775 {} +

sudo find /var/www -type d -exec chmod 2775 {} \;

sudo chown -R www-data-my-grp /var/www/my.wordpresssite.com

sudo chmod -R 775 /var/www/my.wordpresssite.com/wp-content/uploads

After running the above commands the uploads folder will have the following permission and you will be able to upload the images, files etc.

drwxrwsr-x 4 www-data www-my-grp 4096 May 25 18:15 uploads