wordpress permissions

por | 21 enero, 2018

For those who have their wordpress root folder under their home folder:

Ubuntu/apache

  1. Add your user to www-data group:

    CREDIT Granting write permissions to www-data group

    You want to call usermod on your user. So that would be:

    sudo usermod -aG www-data yourUserName
    

    Assuming www-data group exists

  2. Check your user is in www-data group:
    groups yourUserName
    

    You should get something like:

    yourUserName : yourUserGroupName www-data
    

    yourUserGroupName is usually similar to you user name

  3. Recursively change group ownership of the folder keeping your user ownership
    chown yourUserName:www-data -R yourWebSiteFolder/*
    
  4. Change directory to yourWebSiteFolder
    cd yourWebSiteFolder
    
  5. Recursively change group premissions of the folders and sub-folders to enable write permissions:
    find . -type d -exec chmod -R 775 {} \;
    

    mode of /home/yourUserName/yourWebSiteFolder/' changed from 0755 (rwxr-xr-x) to 0775 (rwxrwxr-x)

  6. Recursively change group premissions of the files and sub-files to enable write permissions:
    find . -type f -exec chmod -R 664 {} \;
    

    The result should look something like:

    WAS:
    -rw-r--r--  1 yourUserName www-data  7192 Oct  4 00:03 filename.html
    CHANGED TO:
    -rw-rw-r--  1 yourUserName www-data  7192 Oct  4 00:03 filename.html
    

    Equivalent to:

    chmod -R ug+rw foldername
    

    Permissions will be like 664 or 775.

Assuming all files already belong to www-data user (you can check it with ls -slah command) who belongs to www-data group (next column after username in list of files) you can just add you user to the same www-data group to allow editing these files

# usermod -aG www-data username

for existing user, or

# adduser username www-data