How to set permission for WordPress in DigitalOcean WordPress Droplet or with Ubuntu?

How to set permission for WordPress in DigitalOcean WordPress Droplet or with Ubuntu?

To Set the proper Permission for WordPress you needs to execute the following command.

Step 1: Connect command line interface using Putty/ Using Command-line Interface provided by DigitalOcean.
Step 2: Execute Following Command
sudo usermod -aG www-data $USER
This will adds the currently logged in user to the www-data group.

Step 3: Change ownership
sudo chown -R www-data:www-data /var/www
This will Changes the ownership of the /var/www directory to www-data group.

Step 4: Set permission for WordPress ( Here www contain all the WordPress files and folder)
sudo chmod -R 755 /var/www

Note: If you want to change the only permission for WordPress Folder without a group. You can execute the following command
find /var/www -type d -exec chmod 755 {} \;
find /var/www -type f -exec chmod 644 {} \;

If you still having error ‘could not create directory’ when updating a plugin
Please add define(‘FS_METHOD’,’direct’); to your wp-config.php.

Hope this will helps.