Question

I have two versions of the site which I have to swap really fast, multiple times.

In my home directory, I have:

drwxr-x---  8 lorem  nobody      4096 Jul 12 20:50 public_html/
drwxr-x---  3 lorem  nobody      4096 Jul 13 12:59 public_html_3.0/

public_html holds the current website, public_html_3.0 holds the new website.

I wish to replace the two by doing:

//move the complete current site to another tmp location
mv public_html public_html_2.0 
//move the new site in place
mv public_html_3.0 public_html 

After trying it on a test account, I get a Forbidden You don't have permission to access / on this server. error.

I have made sure that the public_html_* folders have identical permissions, but I guess it's a symlink issue? Am I trying to do something unthinkable and highly not recommended?

Using VPS WHM/Cpanel with root privileges on CentOs 5.9.

EDIT

After some webreading, I have removed public_html (moved to temp) and sym-linked public_html -> public_html_3.0 resulting in:

lrwxrwxrwx  1 lorem nobody           15 Jul 13 14:11 public_html -> public_html_3.0/
drwxr-x---  3 lorem nobody      4096 Jul 13 12:59 public_html_2.0/
drwxr-x---  2 lorem nobody      4096 Jul 13 14:02 public_html_3.0/
lrwxrwxrwx  1 lorem lorem            11 Jul  9  2012 www -> public_html/

Still the same result.

Was it helpful?

Solution

Moving the public_html as you have mentioned above is not a big issue.

mv public_html public_html_2.0 mv public_html_3.0 public_html

These are harmless commands if you are aware what you are actually doing.

Make sure that both directories are having 750 permission.

chmod 750 public_html*

Then make sure that the files inside both directories are having correct permissions.

find /home/user/public_html/ -type f -exec chmod -R 644 {} \; find /home/user/public_html_3.0/ -type f -exec chmod -R 644 {} \;

find /home/user/public_html/ -type d -exec chmod -R 755 {} \; find /home/user/public_html_3.0/ -type d -exec chmod -R 755 {} \;

Also make sure that the ownership also correct. Change those recursively

chown -R lorem: /home/user/public_html/* chown -R lorem: /home/user/public_html_3.0/*

In case if you are using suphp handler, you can use lorem:nobody also. Let us know if that helped you.

OTHER TIPS

The error I was experiencing (Forbidden You don't have permission to access / on this server.) was a misplaced root folder of the new site, not a filesystem issue. The new site was actually located in ~/public_html_3.0/public_html/, because I unzipped it wrong. The new sym-link I put in place, public_html => public_html_3.0, was now pointing to a folder without an index file, hence the error.


Alternative solution

Leo Prince's answer is right, but I will offer an alternative solution with a single-command switch, which also worked for me (explained for newbs like myself):

This solution requires you to have FollowSymlinks enabled for the server or this specific VirtualHost and assumes your vhost is pointing to /home/user/public_html (~/public_html). See accepted answer for permission/ownership instructions.

Let's assume that your old site is in ~/public_html and your new site is in ~/app2.

-public_html
   -index.html
   -other.html
-app2
   -index.html
   -other_new.html

First, copy your old site to a new directory:

# mkdir app1
# cp -a public_html/. app1/.
// -a option copies recursively with permissions/owners/groups 
// but doesn't follow symbolic links

Then move (rename) the public_html to a temporary directory and then create a symbolic link from public_html to the old app.

# mv public_html public_html_bak
// moves the public_html "out of way"
# ln -s app1 public_html
// creates a symbolic-link
# ls -l
drwxr-x---  user nobody app1/
drwxr-x---  user nobody app2/
lrwxr-x---  user nobody public_html -> app1/
drwxr-x---  user nobody public_html_bak/

This makes ~/public_html POINT to ~/app1. Read more on symbolic links. The server sees public_html, but the files are from app1.

If it don't work, go back to previous state:

# rm public_html 
//// use rm, NOT rmdir, since it's a symlink, not a dir
# mv public_html_bak public_html
// return backup to previous location

If it works, the instant you wish to switch to the new site (app2), you need to change the symbolic link to point to the app2 directory:

# rm public_html; ln -s app2 public_html
// remove existing link, create new link with a single line (instant change)
# ls -l
drwxr-x---  user nobody app1/
drwxr-x---  user nobody app2/
lrwxr-x---  user nobody public_html -> app2/
drwxr-x---  user nobody public_html_bak/

Although this is approximately the same as doing two folder renames in a row, it makes for a clean review of app versions, which is what I'm trying to achieve:

# ls -l
drwxr-x---  user nobody app2.3/
drwxr-x---  user nobody app3.0/
drwxr-x---  user nobody app3.1/
drwxr-x---  user nobody app3.2b/
lrwxr-x---  user nobody public_html -> app3.0/ <- the current active version

# rm public_html; ln -s app3.1 public_html
/// a one-line switch to a different app version
/// first remove the symbolic link; then create new

Of course, all the app directories have to have proper permissions, as described in the accepted answer above and the owner:group of the directories have to be the same as the original public_html. Also, the symbolic link must belong to the same user:group with same permissions in case your server configuration allows only symlinks from the same user.

Note that for removing the symbolic link, you should use rm, not rmdir, since it would fail if you are trying to remove an actual directory.

I'm still learning *NIX, so there might be some issues with this solution I am unaware of. But for frequent version changes, this works like magic :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top