17

I'm trying to install Wordpress using the following installations. However, when I attempt to open the browser to set up Wordpress, I get an error that there is a problem establishing a database connection. I think it's because of an error I get when I run the chown command.

http://www.techkaki.com/2011/04/how-to-install-wordpress-locally-on-ubuntu-10-10-with-lamp/

chown -R www-data /var/www/wordpress

I get a ton of error messages:

...
chown: changing ownership of `/var/www/wordpress/wp-admin/network/themes.php': Operation not permitted
chown: changing ownership of `/var/www/wordpress/wp-admin/network/users.php': Operation not permitted
chown: changing ownership of `/var/www/wordpress/wp-admin/network/index.php': Operation not permitted
chown: changing ownership of `/var/www/wordpress/wp-admin/network/sites.php': Operation not permitted
chown: changing ownership of `/var/www/wordpress/wp-admin/network/user-new.php': Operation not permitted
chown: changing ownership of `/var/www/wordpress/wp-admin/network/setup.php': Operation not permitted
chown: changing ownership of `/var/www/wordpress/wp-admin/network/theme-install.php': Operation not permitted
chown: changing ownership of `/var/www/wordpress/wp-admin/network/plugins.php': Operation not permitted

Anyone know what's up with this?

Lekensteyn
  • 174,277
ATMathew
  • 1,236

3 Answers3

31

You have to be root to change the owner of files/directories.

sudo chown -R www-data /var/www/wordpress

If you're getting an error like Operation not permitted, just type:

sudo !!

at the prompt to execute the last command with root priviledges. This way, you don't have to retype chown -R www-data /var/www/wordpress.

n.st
  • 1,360
dsaint
  • 774
  • 11
    For those who've never seen this before: !! does history expansion, the last executed command in the shell to be precise. – Lekensteyn Jul 26 '11 at 09:33
  • @EricCarvalho he maybe meant that to *change to/from other users but yourself you need root – Braiam Nov 09 '13 at 00:43
  • @Braiam I'm not sure what he meant... The idea wasn't changed. I just reformatted it and the previous reviewer only increased the original text's verbosity. – Eric Carvalho Nov 09 '13 at 01:16
  • in my case that is not working. I am working with NFS could that be the problem? /home type nfs4 (rw,addr=147.142.39.202,clientaddr=147.142.39.163,_netdev) – user9869932 Jun 12 '15 at 17:11
  • even with 'sudo', it does not work. –  Sep 27 '18 at 13:34
3

Besides being root, as others have pointed out, there is another more flexibile way to manage this privilige. You can also give files away via chown if your process / thread has the CAP_CHOWN Posix capability. For more info, and how to get that capability, see http://manpages.ubuntu.com/manpages/intrepid/man7/capabilities.7.html Unfortunately it doesn't yet seem to be possible for a process to gain specific capabilities like this based on attributes of an executable file. Either the process would have to be configured this way by another privileged process, or the executable would have to be fully setuid, and then give itself the capability before dropping root priviliges as a normal safety precaution.

A tip of the hat to Can't change owner (user or group) of directory which I have all rights on? - Super User

nealmcb
  • 3,647
3

If you're not root, you'll need to become root to set these permissions:

sudo chown -R www-data /var/www/wordpress
Aric
  • 139