Skip to content

Instantly share code, notes, and snippets.

@Adirael
Created August 17, 2012 23:16
Show Gist options
  • Save Adirael/3383404 to your computer and use it in GitHub Desktop.
Save Adirael/3383404 to your computer and use it in GitHub Desktop.
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
WS_GROUP=www-data # <-- webserver group
# reset to safe defaults
find ${WP_ROOT} -exec chown ${WP_OWNER}:${WP_GROUP} {} \;
find ${WP_ROOT} -type d -exec chmod 755 {} \;
find ${WP_ROOT} -type f -exec chmod 644 {} \;
# allow wordpress to manage wp-config.php (but prevent world access)
chgrp ${WS_GROUP} ${WP_ROOT}/wp-config.php
chmod 660 ${WP_ROOT}/wp-config.php
# allow wordpress to manage wp-content
find ${WP_ROOT}/wp-content -exec chgrp ${WS_GROUP} {} \;
find ${WP_ROOT}/wp-content -type d -exec chmod 775 {} \;
find ${WP_ROOT}/wp-content -type f -exec chmod 664 {} \;
@Lysak
Copy link

Lysak commented Mar 1, 2021

like magic

@juanpgarciac
Copy link

If you are having "No such file or directory" problems and you use windows to upload the file a quick fix is changing the format to unix again:

#vim fix_permision.sh
:set fileformat=unix
:wq

#sh fix_permision.sh

@morsine
Copy link

morsine commented Aug 7, 2021

Thank you!! This worked, while everything else on internet failed.

@DevAly
Copy link

DevAly commented May 3, 2022

Thanks, it works very well

@rubo77
Copy link

rubo77 commented May 4, 2022

@MassStash
Copy link

MassStash commented Jul 26, 2022

I'm using centos/cpanel/litespeed and I have the following error:
chown: invalid user: www-data:www-data
chgrp: invalid group: www-data
how should I fix it ?

@msesxi I use VPS with Openlitespeed 1.6.8 try change group with nogroup and user with nobody should be like this : WP_OWNER=nobody # <-- wordpress owner (if you use shared host, but if use VPS like me try your user and group instead) WP_GROUP=nogroup # <-- wordpress group WP_ROOT=$1 # <-- wordpress root directory WS_GROUP=nogroup # <-- webserver group

Yeeaaa, something like this... Not sure if just, they didn't mention cpanel in the mix... or cloudlinux specific ontop centos...
From my current research nobody is right, but not the nogroup.

Just stumbled back upon this piece out of a general 403 error troubleshoot KB:

Incorrect File Ownership After Migration[¶](https://docs.litespeedtech.com/lsws/cp/cpanel/403-error/#incorrect-file-ownership-after-

migration)
When migrating or uploading files to a cPanel account, some image files might incorrectly be assigned to nobody:nobody, when they should be user:user.

/home/jsmith/public_html>ls -ald images/detailed/130/Untitled-1-Recovered_urba-uz.jpg
-rw-rw-rw- 1 nobody nobody 103609 Apr 12 11:21 images/detailed/130/Untitled-1-Recovered_urba-uz.jpg
/home/jsmith/public_html>ls -ald images/detailed/130
drwxrwxrwx 2 nobody nobody 36864 Apr 14 15:12 images/detailed/130
/home/jsmith/public_html>ls -ald images/detailed
drwxrwxrwx 51 jsmith jsmith 4096 Apr 11 13:16 images/detailed
/home/jsmith/public_html>ls -ald images
drwxrwxrwx 48 jsmith jsmith 4096 Mar 31 16:30 images
The Force Strict Ownership setting in LSWS Admin specifies whether to enforce strict file ownership checking. If it is enabled, the web server will check if the owner of the file being served is the same as the owner of the virtual host. If it is different, a 403 Access Denied error will be returned.

To fix the problem, either change all files user:group to user:user ( in the above example, that would be jsmith:jsmith), or disable Force Strict Ownership in LSWS Admin.

leaving these tabs open now, think I'm going to make a master doc on this craziness lol. Likely become very popular since it's been a nightmare getting all the right little config info on this lsws cpanel cl setup lol. Installed CL manually on linode with custom distribution installation and custom recommended for performance cpanel partitions. That was a 3 - 5 day battle lol. Documented the heck out of that one... Literally could not find one person on the net with a guide on custom install Cloudlinux 8, for cPanel specific partition setup. Definitely gave me some food feature requests for linode tho lolol.

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