Error: EACCES: permission denied [Solved]


Sometimes when we’re working with files, our user is not able to save or edit the files on the server.

This tutorial will help you fix that issue.

For example, if while trying to save a file on vs code, you get this error:

Failed to save ‘functions.php’: Unable to write file ‘vscode-remote://ssh-remote+domain.com/var/www/html/wp-content/themes/default/functions.php’ (NoPermissions (FileSystemError): Error: EACCES: permission denied, open ‘/var/www/html/wp-content/themes/default/functions.php’)

This is because the user that you’re logged into is not allowed to make the changes to the files.

Solve ownership & permissions issues for wordpress or other servers

Follow these steps to fix the issue for your ubuntu or any other linux distro server for wordpress or any other files.

First of all, add your user to the www-data group. You can do it via:

sudo usermod -aG www-data $USER

Then, you need to sudo yourself once, then logout and then log back in:

su $USER

Next, make sure that your user is part of www-data group too. Do this via:

id

Once confirmed, now we need to make sure that the files are owned by www-data group too.

Do that by using these commands (edit the directory paths to your own ones):

sudo chmod -R ug+rw /var/www/html
sudo chown -R www-data:www-data /var/www/html

If you want to give different permissions to files and folders, do this through:

sudo find /var/www/html/ -type d -exec sudo chmod 755 {} \;
sudo find /var/www/html/ -type f -exec sudo chmod 644 {} \;

Make sure that you restart vs code after this. You might also have to reboot the server if changes don’t apply.

Please let me know if you have queries or need any help.


Leave a Reply

Your email address will not be published.