最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Permissions Script Not Working

programmeradmin0浏览0评论

I am running a LAMP dev environment on ubuntu 18.04 with wordpress 5.4.2. I found this awesome script meant to make adjusting permissions on wordpress installations easy, getting rid of 403 errors in a snap. However, I am stuck trying to get the script to work on my system. I am sure that I am making a simple mistake, but I am not a coder. Here is the original awesome script for every, big props to the author:

#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from 
#
# Author: Michael Conigliaro
#
WP_OWNER=changeme # <-- wordpress owner
WP_GROUP=changeme # <-- wordpress group
WP_ROOT=/home/changeme # <-- wordpress root directory
WS_GROUP=changeme # <-- 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 .htaccess
touch ${WP_ROOT}/.htaccess
chgrp ${WS_GROUP} ${WP_ROOT}/.htaccess
chmod 664 ${WP_ROOT}/.htaccess
 
# 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 {} \;


  [1]: 

Here are my edits based upon hosting provider's permissions:

#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from 
#
# Author: Michael Conigliaro
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=/var/www/html/<wp root directory>/ # &lt;-- wordpress root directory
WS_GROUP=www-data # &lt;-- 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 644 ${WP_ROOT}/wp-config.php
 
# allow wordpress to manage .htaccess
touch ${WP_ROOT}/.htaccess
chgrp ${WS_GROUP} ${WP_ROOT}/.htaccess
chmod 644 ${WP_ROOT}/.htaccess
 
# allow wordpress to manage wp-content
find ${WP_ROOT}/wp-content -exec chgrp ${WS_GROUP} {} \;
find ${WP_ROOT}/wp-content -type d -exec chmod 755 {} \;
find ${WP_ROOT}/wp-content -type f -exec chmod 644 {} \;

I use sudo chmod +x wp-permissions.sh to make the script executable and it executes without problem, but each and every time that I visit the website, I am greeted by a 403 error. I can successfully restart apache and mysql, so the problem is definitely permissions. Any tips on what I am doing wrong?

I am running a LAMP dev environment on ubuntu 18.04 with wordpress 5.4.2. I found this awesome script meant to make adjusting permissions on wordpress installations easy, getting rid of 403 errors in a snap. However, I am stuck trying to get the script to work on my system. I am sure that I am making a simple mistake, but I am not a coder. Here is the original awesome script for every, big props to the author:

#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro
#
WP_OWNER=changeme # &lt;-- wordpress owner
WP_GROUP=changeme # &lt;-- wordpress group
WP_ROOT=/home/changeme # &lt;-- wordpress root directory
WS_GROUP=changeme # &lt;-- 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 .htaccess
touch ${WP_ROOT}/.htaccess
chgrp ${WS_GROUP} ${WP_ROOT}/.htaccess
chmod 664 ${WP_ROOT}/.htaccess
 
# 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 {} \;


  [1]: https://gist.github/macbleser/9136424

Here are my edits based upon hosting provider's permissions:

#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro
#
WP_OWNER=www-data # &lt;-- wordpress owner
WP_GROUP=www-data # &lt;-- wordpress group
WP_ROOT=/var/www/html/<wp root directory>/ # &lt;-- wordpress root directory
WS_GROUP=www-data # &lt;-- 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 644 ${WP_ROOT}/wp-config.php
 
# allow wordpress to manage .htaccess
touch ${WP_ROOT}/.htaccess
chgrp ${WS_GROUP} ${WP_ROOT}/.htaccess
chmod 644 ${WP_ROOT}/.htaccess
 
# allow wordpress to manage wp-content
find ${WP_ROOT}/wp-content -exec chgrp ${WS_GROUP} {} \;
find ${WP_ROOT}/wp-content -type d -exec chmod 755 {} \;
find ${WP_ROOT}/wp-content -type f -exec chmod 644 {} \;

I use sudo chmod +x wp-permissions.sh to make the script executable and it executes without problem, but each and every time that I visit the website, I am greeted by a 403 error. I can successfully restart apache and mysql, so the problem is definitely permissions. Any tips on what I am doing wrong?

Share Improve this question asked Aug 6, 2020 at 2:35 mjonesmjones 1531 silver badge11 bronze badges 4
  • What file is the 403 error on? What does your apache error log show for the corresponding access? – mozboz Commented Aug 6, 2020 at 13:47
  • I checked both the apache access and error logs and they were empty... though oddly not located in my sites root directory (guessing I should move them to wp site root directory and try again?). I added and index.html at /var/www/html/index.html and it works fine. Index.html also worked at /var/www/html/<root directory>/index.html, so banging head on wall now. :-/ – mjones Commented Aug 7, 2020 at 2:04
  • Yeah, 403 should probably generate an error in a log somewhere. It is a pain but worth it to read up on how to configure apache error logs so you know where they are and also checkout the WP debug options. Solving problems like this goes 20X faster if you've figured out error logs – mozboz Commented Aug 7, 2020 at 12:22
  • @mozboz I figured out the log files pretty well (drupal refugee, wordpress newbie). The logs should actually be empty as this system is freshly installed and I hadn't accessed the sight. The real problem as I have learn after two weeks of googling is the mod_security module for apache is about as stable as an egg shell being hit with a hammer. So the above script s probably fine. It would have saved me a lot of time if wpbeginner mentioned that mod_security can cause 403 errors also. – mjones Commented Aug 11, 2020 at 4:29
Add a comment  | 

1 Answer 1

Reset to default 0

For anyone scratching the heads with the same problem. After, I removed the mod_security and evasive module from my local lamp development server, which was a bit overkill, I discovered that the above script worked perfectly. So if you are using WP and getting a 403 error that you can't figure out, also disable mod_security and/or evasive module as they might be causing your 403 error as well.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论