Change the permissions of the files generated by WordPress on the server

I always upload my WordPress files on the server so the “owner” is my username and I can change the permission to, let’s say, 770. But when I install a plugin, the owner becomes “www-data” and the permission is rw-r-xr--. However, I need to modify some files. Can I do something in the WordPress config to change the generated file’s default permissions? I’m not the server’s root. Thank you.

Related posts

Leave a Reply

2 comments

  1. Its simple please see

    https://codex.wordpress.org/Editing_wp-config.php#Override_of_default_file_permissions

    It is as below::

    Override of default file permissions
    The FS_CHMOD_DIR and FS_CHMOD_FILE define statements allow override of default file permissions. These two variables were developed in response to the problem of the core update function failing with hosts (e.g. some Italian hosts) running under suexec. If a host uses restrictive file permissions (e.g. 400) for all user files, and refuses to access files which have group or world permissions set, these definitions could solve the problem. Note that the ‘0755’ is an octal value. Octal values must be prefixed with a 0 and are not delineated with single quotes (‘).

    define( 'FS_CHMOD_DIR', ( 0755 & ~ umask() ) );
    define( 'FS_CHMOD_FILE', ( 0644 & ~ umask() ) );
    

    Example to provide setgid:

    define( 'FS_CHMOD_DIR', ( 02755 & ~umask() ) );
    

    If you want to change file permissions see

    https://codex.wordpress.org/Changing_File_Permissions

    EDIT:

    Put these after putting any of the above code:

    chown www-data:www-data -R *          # Let apache be owner
    find . -type d -exec chmod 755 {} ;  # Change directory permissions rwxr-xr-x
    find . -type f -exec chmod 644 {} ;  # Change file permissions rw-r--r--
    
  2. Here is the correct file permissions for WordPress:

    chown www-data:www-data -R *          # Let apache be owner
    find . -type d -exec chmod 755 {} ;  # Change directory permissions rwxr-xr-x
    find . -type f -exec chmod 644 {} ;  # Change file permissions rw-r--r--
    

    Depending on your server configuration you may put your wp-content on 775. This permission will allow your group to write in this folder. Why add group permissions? Because in wordpress, you can have two users working on files, the www-data user (who executes the website) and the ftp user (who downloads plugins and updates from the webplatform wordpress). You can put your wp-content on 755 but you have to make www-data the owner of this folder and do your updates manually via FTP.

    Learn more about wordpress File Permissions