Unable to change ownership of Folder in Ubuntu 10.04 w/ chown? - wordpress

I am having trouble getting a few plugins to play nicely in wordpress. On top of that I can't even deactivate or delete several of them, they appear to be locked. I apologize I am somewhat of a linux newb, I have learned a lot but am baffled. I think it has to do with one of two things I did when I setup my VPS, which was guided by a tutorial. One was to install this script which would make commands wpupgrade for installing / deleting plugins and wpsafe for reverting to safe ownership.
### Edit the 2 values first, then post the whole lot.
#
export DOMAIN="mydomain.com"
export USER="myusername"
#
echo '
#########################
### WordPress 'chown' ###
#########################
## Allow WordPress Upgrades/Plugin Installs
alias wpupgrade="sudo find /home/USERNAME/public_html/DOMAIN/public/wp-admin -exec chown -R www-data:webmasters {} \; && sudo find /home/USERNAME/public_html/DOMAIN/public/wp-content -exec chown -R www-data:webmasters {} \;"
## Revert to Safe WordPress Ownership
alias wpsafe="sudo find /home/USERNAME/public_html/DOMAIN/public/wp-admin -exec chown -R USERNAME:webmasters {} \; && sudo find /home/USERNAME/public_html/DOMAIN/public/wp-content -exec chown -R USERNAME:webmasters {} \;"
' >> /home/$USER/.bashrc
sed -i "s/USERNAME/$USER/g" /home/$USER/.bashrc
sed -i "s/DOMAIN/$DOMAIN/g" /home/$USER/.bashrc
source /home/$USER/.bashrc
source /root/.bashrc
However, now all my wp-content and wp-includes are owned by www-data:webmasters and I cannot delete or modify them. I never created a www-data user. I try to use:
chown -R myusername:webmasters /home/myusername/public_html/mydomain.com/public/wp-content
and it tells me
chown: changing ownership of `/home/myusername/public_html/mydomain.com/public/wp-content': Operation not permitted
I have no idea what I'm doing wrong or what to do to fix this.. any help?

data is the user which executs apache. You must be running the script through apache user on you machine. To do a chown you must be the owner or a super user try sudo chown -R. Or log into super-user mod type su - in your terminal then enter the root password. Beware as root you can do anything you have all rights, think twice before executing a commande.
[edit]
I see that your script is in public_html -> this is tha apache folder for your user maybe that is why it has changed the script to www-data as owner.
try this sudo setfacl -R -m u:www-data:rwX -m u:myusername:rwX /home/myusername/public_html/mydomain.com/public/wp-content
to add you and www-data as uses

1) To change the ownership of a single file, run the command below.
$ sudo chown username:groupname filename
For Ex.
$ sudo chown richard:richard lockfile
Replace with the username of the account you wish to take ownership of the file. And is the group that will assume ownership of the file.
2) Now that you know how to change the ownership of a single file, the below commands show you how to change the ownership of a folder and all sub-folders within.
$ sudo chown -R username:groupname FolderName
For Ex.
$ sudo chown -R richard:richard Songs/
That’s it! And I hope you liked it.

Related

AWS EC2 Ubuntu File permissions issue

I'm running a EC2 instance with:
Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-119-generic x86_64)
Bitnami LAMP 5.6.30-5
My problem
I have a Wordpress site that isn't working very well on the backend, so I decided to update and I get an error "Can not create the directory..." when updating. So I did a research and it's related to file permissions. So I get to this conclusion:
I having the following issues with the file permissions:
Can't write files from server
I used is_writable() (PHP) to detect if server can edit and it returns false.
Can edit files from Filezilla
I login to the server with the "bitnami" user and everything works good.
I tried
sudo chown -R bitnami:www-data htdocs/
I added the default user "bitnami" to the www-data group and changed the /htdocs owner.
And, yes the user is in the www-data group.
find htdocs/ -type d -exec sudo chmod 2775 {} +
Changed directory permissions
find /var/www -type f -exec sudo chmod 0664 {} +
Changed the files permissions
How to solve this?
I tried all that and also giving the owner to root:root, www-data:www-data and bitnami:bitnami.
If someone knows the original user and group owner of the /htdocs folder I could try a test, but I forgot.
I would appreciate if anyone can help me to solve this. I just want to be able to write/edit files from server side.
Many thanks.
I solved this by doing the following:
Set htdocs owner to bitnami:bitnami
sudo chown -R bitnami:bitnami htdocs/
Inside /htdocs, changed file and directories owner to bitnami:daemon
sudo chown -R bitnami:daemon
Changed files and directories permissions
sudo find * -type d -print0 | xargs -0 chmod 0755 # for directories
sudo find . -type f -print0 | xargs -0 chmod 0644 # for files
Changed wp-content directories permissions to 775
sudo find wp-content/ -type d -exec chmod 0775 {} \;
And with that now I'm able to edit and upload via FTP and in the WP admin dashboard.

correct rights linux webserver

I have installed a LAMP server (Ubuntu) on a VPS and everything seems to be running fine. After uploading and installing WordPress I ran into a couple of rights issues (not being able to upload, not being able to create/change the .htaccess file from within WordPress, the usual) so I chmod the directory so the www-data user is owner:
sudo chown -R www-data:www-data /var/www/domain.com/public_html/
Now all of the above works fine, but...
When I upload a file or directory the owner/group is set to the user I'm using to "FTP" with. This results in WordPress not being able to update the files (e.g. a plugin). The user I'm using for FTP transfer is part of the www-data group.
What should/can I do to prevent this and thus automagically add the www-data owner/group to uploaded files? And is this the way to go?
Think I found it: https://help.ubuntu.com/lts/serverguide/httpd.html
Sharing Write Permission
sudo chgrp -R www-data /var/www/domain.com
sudo find /var/www/domain.com -type d -exec chmod g=rwxs "{}" \;
sudo find /var/www/domain.com -type f -exec chmod g=rw "{}" \;

Unable to write cache symfony2

RuntimeException in ClassCollectionLoader.php line 239:
Failed to write cache file "/var/www/fareast/app/cache/dev/classes.php".
I have this error when I run my project in symfony2.
I have nginx as my web server and centOS 7 as my OS.
I tried deleting the cache folder manually and by
php app/console cache:clear
then I did a bad practice to app/cache and app/logs
chmod -R 777
but I have the same error.
/var/log/nginx/error.log is also empty.
Do you recommend other solutions?
Or do I have to install some php5 libraries for cache?
Setting 777 permissions do nothing, because when webserver user write folders to it, the folders belong to this user, and you, as command line user haven't access to them, and vice versa. Set permissions in correct way: http://symfony.com/doc/current/book/installation.html#book-installation-permissions
In symfony3 i've faced the same issue...
So, problem would not solve only using "cache clear"
You have to change (R/W)permission of cache folder in your project
For ex: "projectname/var/cache"
Now refresh...
If still issue is coming, change(R/W)permission of logs folder in your project
For ex: "projectname/var/logs"
You have to use the following script to determine your web server user and grant the needed permissions:
rm -rf var/cache/*
rm -rf var/logs/*
HTTPDUSER = `ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo chmod -R +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" var
sudo chmod -R +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" var

Cannot Install or update WordPress plugin & WordPress core

When i try to update any plugin it will show blank page on the right. No errors displayed.
Uninstall is working perfectly.
Cannot install new plugin & cannot update WordPress Core
NO ERRORS DISPLAYED, only white page on right (you can see side menu of dashboard)
Hosting my Files in VPS - Centos 6 - Apache 2.4.6
Recently i updated PHP 5.3.26 to PHP 5.4.17
I tried Changing Owner Permission to Apache. (i was unable to login - then changes back to my username)
I tried chmod 777 no use.
I tried adding in wp-config.php - define('FS_METHOD', 'direct'); & chmod 777 to wp-content directory.
Please help.
NEVER use 777 permission! Wordpress only need 755 for folders, 644 for files, and 666 for themes and plugins directory recursively. And you might want to give 600 to wp-config.php.
I had this problem, I use CentOS 7 though, this is how I solved the issues.
Make sure all owned by Apache.
sudo chown -R apache:apache /var/www/html/sitedir
Give proper permissions
sudo find /var/www/html/sitedir -type d -exec chmod 755 {} +
that would give 755 permission to all folder inside sitedir
sudo find /var/www/html/sitedir -type f -exec chmod 644 {} +
that would give 644 to all files
sudo find /var/www/html/sitedir/wp-content/themes -type f -exec chmod 666 {} +
sudo find /var/www/html/sitedir/wp-content/plugins -type f -exec chmod 666 {} +
those two commands above make 666 permission to all files inside themes and plugins folder
If you use selinux
set this first
sudo chcon -R system_u:object_r:httpd_sys_content_t:s0 /var/www/html/sitedir
then this
sudo chcon -R system_u:object_r:httpd_sys_rw_content_t:s0 /var/www/html/sitedir/wp-content
Restart php-fpm service if you had one.
UPDATE:
If you don't get through until this point. You might also need to set a local policy module for selinux.
sudo grep php-fpm /var/log/audit/audit.log | audit2allow -M mypol
sudo semodule -i mypol.pp
Then restart php-fpm.
As I cover here more detail on my blog :)

To copy files each minute at /var/www without sudo

How can you copy a folder to /var/www without sudo?
My folder codes has the following permissions at /var/www
4 drwxr-xr-x 8 root root 4096 2009-08-09 03:01 codes
I can only sudo cp -r ~/Dropbox/codes/ /var/www to copy the files.
I cannot copy them without sudo.
Owning /var/www yourself might conflict with other options on your system. On my Debian system I would do this
sudo addgroup www
sudo adduser nr www # add myself to the www group
sudo chgrp -R www /var/www # make files in the group
find /var/www -type f -exec chmod g+w '{}' ';' # make each file group writable
find /var/www -type d -exec chmod g+ws '{}' ';' # make each directory group writable and sticky
If the directory is group writable and sticky, all files created in /var/www will be writable by anyone in the www group, no matter who or what creates them there. (Caveat: they have to be created by "normal" means; cp -a can circumvent the group sticky bit.)
Because Unix is insanely stupid about group membership, for your membership to be honored you will have to log in again, e.g., ssh localhost or log out and log back in. A nuisance.
What about adding the cron job to the root user. It's not a great idea, but it will get around the problem?
I also find it interesting that your www directory would have only root permissions and be owned by root. Usually they are owned by an apache user or have other permissions such that apache can access them.
Edit You probably don't want to edit the crontab file directy. But something similar to the following command should work:
sudo crontab -e -u root
You may not need the -u root but it's good so sudo doesn't confuse crontab.
Edit 2 You can change permissions with the chmod and chown commands:
sudo chmod 755 /path
sudo chown user:user /path
Be very very careful when using this. You can completely screw up the OS by changing permissions on the wrong files or folders. You'll probably want to add the -R option which will apply the permissions or owner recursively, but again, be very careful.
sudo chown yourusername /var/www
And you'll become the new owner of /var/www.

Resources