Skip to content

Instantly share code, notes, and snippets.

@nasirkhan
Last active April 17, 2025 18:20
Show Gist options
  • Save nasirkhan/c34478580fa9e74929fb08e034964813 to your computer and use it in GitHub Desktop.
Save nasirkhan/c34478580fa9e74929fb08e034964813 to your computer and use it in GitHub Desktop.
Correct permissions for /var/www and laravel wordpress

First, you should ensure that your username is included in www-data group. If not, you can add your username as www-data group

sudo adduser $USER www-data

After that, you should change the ownership of /var/www to your username

sudo chown $USER:www-data -R /var/www

Next step, you should change permission to 755 (rwxr-xr-x), not recommend changing permission to 777 for security reason

sudo chmod u=rwX,g=srX,o=rX -R /var/www

Run the following command when you get the error: error: cannot open .git/FETCH_HEAD: Permission denied

sudo chmod g+w .git -R

For Wordpress or Joomla site, you may need to run the follwing command to fix the permission issues

sudo chown -R www-data:www-data /var/www/CMS_DIRECTORY


For directories only do this.

find . -type d -exec chmod 755 {} \;

For files only do this.

find . -type f -exec chmod 644 {} \;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment