#!/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 {} \; |
This comment has been minimized.
This comment has been minimized.
this worked perfect for me. Thanks! |
This comment has been minimized.
This comment has been minimized.
This saved me! thank you! my site was totally offline for some reason and this solved it. double thumbs up |
This comment has been minimized.
This comment has been minimized.
So, I used this because my wp-content/uploads was giving me permission errors (on a new install). |
This comment has been minimized.
This comment has been minimized.
https://codex.wordpress.org/Changing_File_Permissions Typically, all files should be owned by your user (ftp) account on your web server, and should be writable by that account. On shared hosts, files should never be owned by the webserver process itself (sometimes this is www, or apache, or nobody user). |
This comment has been minimized.
This comment has been minimized.
This works link a charm. Thank for the resource. |
This comment has been minimized.
This comment has been minimized.
Worked like magic. |
This comment has been minimized.
This comment has been minimized.
Fixed all my problems thanks |
This comment has been minimized.
This comment has been minimized.
I'm sorry, but i dont know how this works, someone can explain it pls? I've got a problem w/ wordpress permissions and this seems to be a solution. |
This comment has been minimized.
This comment has been minimized.
thanks |
This comment has been minimized.
This comment has been minimized.
thanks man.. |
This comment has been minimized.
This comment has been minimized.
hi bro, why show me this:
|
This comment has been minimized.
This comment has been minimized.
Also getting the
|
This comment has been minimized.
This comment has been minimized.
You need to supply the folder your wordpress is in, e.g. |
This comment has been minimized.
This comment has been minimized.
Thank you!!! |
This comment has been minimized.
This comment has been minimized.
NaitNog - "You need to supply the folder your wordpress is in, e.g. ./fix-wordpress-permissions.sh wordpress". I get a permission denied when trying to run this. Also just wondering, is it necessary to set this? Is this something that should be set when installing wordpress out of the box every time? I'm just wondering because I had a few permissions issues after installing wordpress with wget in terminal, but it was resolved by running chown -R ftpusername:ftpusername * |
This comment has been minimized.
This comment has been minimized.
That is happening because that is not the path to your directory. You may need to add /var/www/vhosts/domainname.com/httpsdocs/wp-content/ which would be the full folder path. This example path might not be the same as yours, it is just an example. Basically you need a more precise path. |
This comment has been minimized.
This comment has been minimized.
#create fix-wordpress-permissions.sh ("sudo nano fix-wordpress-permissions.sh" and put the content in it) |
This comment has been minimized.
This comment has been minimized.
@Adirael Thanks for this script - it worked fine! Many of the questions above would go away if you could add this explanation after line 6 of the original script: # Source for this script: http://www.conigliaro.org/script-to-configure-proper-wordpress-permissions/
#
# To use this script, supply the full path to your wordpress directory
# That directory is often in /var/www, and the wordpress directory is frequently named 'wordpress'
# The example below operates on /var/www/wordpress directory
#
# sudo sh ./fix-wordpress-permissions.sh /var/www/wordpress |
This comment has been minimized.
This comment has been minimized.
thanks! |
This comment has been minimized.
This comment has been minimized.
Thank you so much! Can't believe I just found this now. |
This comment has been minimized.
This comment has been minimized.
the struggle for this one is real. tried so many time and failed. finally worked with the help @richb-hanover comment. So i will explain the thing further.
now comes the tricky part. you need to upload the file, where your website or wordpress is being hosted i.e. the directory/path/wordpress for eg. /home/admin/web/mywebsite/public_html I am using Ubuntu 16 on amazon ec2 and i have installed VestaCP. Therefore the path of my directory is the one mentioned. You path can be /Var/www/wesite/yourwebiste or something. It all depends where the website is installed. How i got here? I used SSH to login and navigated here using CD command. cd /home/admin/web/mywebsite/public_html.
chmod +x fix-wordpress-permissions.sh (gives execute permissions) You need to be in the directory of your wordpress (do remember this prior executing the command) sudo sh ./fix-wordpress-permissions.sh /home/admin/web/yourwebsite-goes-here/public_html (use this command to execute). Please do note that this is my directory and your directory can be different. you need to be in the directory of your wordpress installation to execute the command. |
This comment has been minimized.
This comment has been minimized.
Works great! Thank you :D |
This comment has been minimized.
This comment has been minimized.
It's work. Thanks !! |
This comment has been minimized.
This comment has been minimized.
i love this and use it frequently, you rock |
This comment has been minimized.
This comment has been minimized.
Very helpful! Thanks |
This comment has been minimized.
This comment has been minimized.
Thanks, it works perfect, but something like this, at start, would be fine to prevent no parameter error: |
This comment has been minimized.
This comment has been minimized.
Thanks a lot! |
This comment has been minimized.
This comment has been minimized.
nice work |
This comment has been minimized.
This comment has been minimized.
Thank you! I only regret not finding this earlier. |
This comment has been minimized.
This comment has been minimized.
Holy crap, what a simple and elegant solution! THANK YOU!!!! |
This comment has been minimized.
This comment has been minimized.
Great script, but it did not fix my update problems, at least not for Wordpress version updates. It is still necessary to enter FTP credentials. However it works for plugin or theme updates. Any ideas on avoiding to enter FTP data when trying to update? |
This comment has been minimized.
This comment has been minimized.
Thanks it worked! |
This comment has been minimized.
This comment has been minimized.
Just wanted to say thanks, I use this all of the time and it's a life saver! |
This comment has been minimized.
This comment has been minimized.
This worked perfectly and is definitely something all WP developers should have on hand since nothing did the job as well as this. Thanks! |
This comment has been minimized.
This comment has been minimized.
Adirael- @daudi250 |
This comment has been minimized.
This comment has been minimized.
Wouldn't it be faster to use
instead of
? |
This comment has been minimized.
This comment has been minimized.
It worked great! thank you! |
This comment has been minimized.
This comment has been minimized.
I'm using centos/cpanel/litespeed and I have the following error: how should I fix it ? |
This comment has been minimized.
This comment has been minimized.
Very helpful. I especially appreciate daudi250's comments. |
This comment has been minimized.
This comment has been minimized.
That saves lifes and files haha. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
if the .sh file is in root directory run sudo sh ./fix-wordpress-permissions.sh ./ |
This comment has been minimized.
This comment has been minimized.
Following daudi250 I had to change around based on CentOS usage
However it still did not fix my permission issues. I don't understand how my permissions got messed up, was updating fine, haven't installed any plugins, then today I couldn't do it. I had to run:
Perform the update then revert permissions back
|
This comment has been minimized.
This comment has been minimized.
Thx it works for me. |
This comment has been minimized.
This comment has been minimized.
thanks man. save my day ;) |
This comment has been minimized.
This comment has been minimized.
thanks! perfect way to restore messed up permissions. |
This comment has been minimized.
This comment has been minimized.
Thanks |
This comment has been minimized.
This comment has been minimized.
Great solution! Thanks! |
This comment has been minimized.
This comment has been minimized.
Great work, solved my problems (well, the Wordpress one anyway :-)) |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Worked for me, thank you. |
This comment has been minimized.
This comment has been minimized.
Been trying to fix my permissions to get my VPS install of WP working for days now, scratching my head and getting extremely pissed off but this solved it instantly! Thank you! |
This comment has been minimized.
This comment has been minimized.
Thanks!! |
This comment has been minimized.
This comment has been minimized.
Kudos for this script ! |
This comment has been minimized.
This comment has been minimized.
Voila this script helped save my wordpress instances. |
This comment has been minimized.
This comment has been minimized.
We have a fix for this. |
This comment has been minimized.
This comment has been minimized.
thank you very much |
This comment has been minimized.
This comment has been minimized.
I have been scratching my head since days and finally it worked like a charm for me too. Thanks to this post, which explains various aspects of the issue in a well defined manner. I think you should have a look at this post - How to Fix WordPress File and Folder Permissions Error?. Thanks! |
This comment has been minimized.
This comment has been minimized.
$1 need to be replace with the path to wordpress root directory, or, is it obtained otherwise? |
This comment has been minimized.
This comment has been minimized.
Just use it like "fix-wordpress-permissions.sh /var/www/your-wordpress-folder" |
This comment has been minimized.
This comment has been minimized.
@ZeroCool In bash, $1 is the first command line argument given to your program (see : https://stackoverflow.com/questions/29258603/what-do-0-1-2-mean-in-shell-script). As said by https://gist.github.com/Adirael/3383404#gistcomment-3133780, if you want the script to point to your wordpress folder, you have to call it with, as first argument, a string that contains the path to your wordpress folder. |
This comment has been minimized.
This comment has been minimized.
Oh ! Ok. But, i use read, and not $1. |
This comment has been minimized.
This comment has been minimized.
OMG - thanks so much - a few echo 's would have been icing on the cake - maybe i will fork it :-) thank you |
This comment has been minimized.
This comment has been minimized.
@msesxi |
This comment has been minimized.
This comment has been minimized.
Great improvements in these forks:
I added those and anhanced it in a Github repository here: especially those is an enhancement:
|
This comment has been minimized.
This comment has been minimized.
Now I use the passage of the site by parameter. If anyone wishes to test my script, I would like to have your opinion. |
This comment has been minimized.
This comment has been minimized.
Thank you! |
This comment has been minimized.
This comment has been minimized.
Anyone guide me where I paste that query to solve my problem.......?Or tell me how I put my .sh file to fix that bug.Thanks.Waiting for reply. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@M-Faizan480 it is a script not a web query. You need shell / ssh access to your server. Login to the Linux terminal of your host then execute the file. |
This comment has been minimized.
This comment has been minimized.
Many thanks for this. It works like a charm. |
This comment has been minimized.
This comment has been minimized.
It's 2020. Still works like a charm! Thank you |
This comment has been minimized.
This comment has been minimized.
Isn't putting everything to www-data going to be insecure? |
This comment has been minimized.
This comment has been minimized.
www-data is for developpement. If you use root, a file can't be modified by apache |
This comment has been minimized.
This comment has been minimized.
still I am getting the errors although I did what you have suggested . I am using architect theme Call stack: Redux_Colors::sanitize_hex() |
This comment has been minimized.
This comment has been minimized.
thanks |
This comment has been minimized.
This comment has been minimized.
Hi all, |
This comment has been minimized.
This comment has been minimized.
I'm not really sure if you are at the right place to find a solution for correcting the error with cropping photos!! |
This comment has been minimized.
This comment has been minimized.
like magic |
This comment has been minimized.
thanks! :)