Change the ownership (chown) from 'root' to 'apache'

Christopher lee picture Christopher lee · Feb 21, 2017 · Viewed 20.4k times · Source

System OS: CentOS7.0-64 LAMP for VSI

Problem: I am attempting to change the ownership of two virtual directories from 'root' to 'apache', so that Apache can read and write data. I am using the following commands but to no avail.

 chown -R apache:apache /var/www/html/www.example-virtualhost1.com
 chown -R apache:apache /var/www/html/www.example-virtualhost2.com

When entering these commands I am receiving an error 'command not found.' Any reference material would be greatly appreciated.

Best.

Answer

rishikarri picture rishikarri · Feb 21, 2017

In order to change the ownership, try the following line:

sudo chown -R apache /var/www/html/

or

sudo chown apache /var/www/html/www.example-virtualhost1.com

The structure is as follows please note the parentheses as an attempt to explain each piece of the command:

sudo(run the command as root) chown(command to change ownership) -R(recursively change everything within the folder) apache(who you want to be the new owner) /var/www/html/(the folder you would like to modify ownership)

Once you have ran this command, you should be able to type in the following command:

ls -lr 

That command will show you who has ownership.

I hope this helps!