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 :)