If you are experiencing permission issues with your web directories and files, use the following commands to resolve it, This solution is very helpful if you are trying to run Wordpress/Other CMS in localhost environment:
1. Adds the currently logged in user to the www-data group.
2. Changes the ownership of the /var/www directory to www-data group.
3. Sets the proper permissions so you can upload files via sftp, manage files via command-line, and upload plugins and media directly in WordPress.
1. Adds the currently logged in user to the www-data group.
sudo usermod -aG www-data $USER
2. Changes the ownership of the /var/www directory to www-data group.
sudo chown -R www-data:www-data /var/www directory_name
3. Sets the proper permissions so you can upload files via sftp, manage files via command-line, and upload plugins and media directly in WordPress.
sudo chmod -R 774 /var/www
directory_name