sudo chown -R $OWNER:$OWNER command error
When I try to create new domain on Ubuntu 12, I used these commands:
sudo mkdir -p /var/www/domain.com/public_html
sudo chown -R $OWNER:$OWNER /var/www/domain.com/public_html
but my mistake when I copy the command I just copy this:
sudo chown -R $OWNER:$OWNER
then hit ENTER, it show lot of errors.
Now all my websites are not working anymore. I can't access to phpmyadmin
too.
Please help me fix this error.
Solution 1:
It seems you have a bigger problem with your websites because the errors from running that command sudo chown -R $OWNER:$OWNER
should be this:
chown: missing operand after ‘:’
Try 'chown --help' for more information.
Basically stating that the command does absolutely nothing because it makes no sense as no file was specified (missing operand) and so no changes were made to your system.
No changes so no problem. Now, go ahead and proceed with running the rest of your commands.
The bigger problem I spoke of earlier is that you cannot access your websites anymore. You may want to ask a separate question for that problem to get the help you need.
However, here are some of the basics:
I will say that I'm not so sure $OWNER is correct and it very well may also do absolutely nothing as well but this time with no errors.
You can list all the files ownership and permissions in the current directory with the following command:
ls-l
to list the files of a specific directory, you can specify it like so to show the ownership and permissions for public_html:
ls -l /var/www/domain.com
Typically, all files and directories should be owned by root like so:
sudo chown -R root:root /var/www
If you would like to change ownership to the current user instead of root, you can use this command which is similar to the command you were trying to run earlier:
sudo chown -R $USER:$USER /var/www/domain.com/public_html
All directories should be set with chmod to 755 (drwxr-xr-x).
All non-directory files (index.html for example) should be more restrictive and should be set using chmod to 644 (-rw-r--r--)
You could first go ahead and set 755 recursively to all files and directories under /var/www before then setting the individual files to 644 like this:
sudo chmod -R 755 /var/www
and this example of setting an individual file to 644
sudo chmod 644 /var/www/domain.com/index.html
and this example would set all files (assuming there are no more directories) contained in the directory public_html to 644.
sudo chmod 644 /var/www/domain.com/public_html/*
Again, use ls -l
to verify the permissions are set properly.
example command and output for a directory with permission set to 755:
ls -l / | grep var
drwxr-xr-x 1 root root 30 Nov 22 19:25 var
example command and output to list all files in a directory with proper permission set to 644:
ls -l /var/domain.com/public_html
-rw-r--r-- 1 root root 425 Dec 19 03:18 index.html
-rw-r--r-- 1 root root 425 Dec 19 03:18 example.html