Symlink /var/www directory
Solution 1
Delete (or move, for safety) the www
directory before you create the symlink.
So, you should have a /var
, but there should be no /var/www
. Then, and only then, will a symlink called www
be created that points to your localhost/code/project folder.
Solution 2
I think you have the ln -s
'source' and 'target' the wrong way round
WRONG:
sudo ln -s /var/www /home/USER/code
RIGHT:
sudo ln -s /home/USER/code /var/www
you will end up with a symlink in your /home/USER/code
folder pointing to var/www
which is wrong.
For example, I have a folder for sally's site in /home/webs/sallybydesign/
cd /var/www
There should be no folder or file called sallybydesign
in /var/www
because we are about to make one.
sudo ln -s /home/ndmaque/webs/sallybydesign /var/www/sallybydesign
to see the new file (a symbolic link)
ls -l
you will see a file called sallybydesign
, it is a symlink to your home/webs/sallybydesign
folder and if you run
ls sallybydesign/
you will see the files in your home/webs/sallybydesign
folder.
If so you can point your vhost file at /var/www/sallybydesign
and it will automagically inherit all the apache /var/www
permissions and solve a shed load of issues.
Related videos on Youtube
user236603
Updated on September 18, 2022Comments
-
user236603 over 1 year
I have been trying to create a symlink:
/var/www -> /home/USER/code/
Following https://stackoverflow.com/questions/9104337/create-a-symbolic-link-of-directory-in-ubuntu , I entered the following command:
sudo ln -s /var/www /home/USER/code
However the result isn't what I expect. My link is stored inside the /www directory instead of linking the www directory itself. I use apache as the local web server, for my case, i have to access my code as
localhost/code/PROJECT
whereas I wish to have something like
localhost/PROJECT
The
code
directory should just serve as a directory where I store all my projects.Anything I'm missing out?
-
Mendhak over 10 yearsDid you delete the
www
directory? It'll create a symlink inside www if www exists. It should create a symlink called www if www does not exist. -
user236603 over 10 yearsNo
www
is there intact. Symlink inside thewww
directory doesn't serve the purpose I mentioned -
Rmano over 10 yearsYou can't have two entries with the same name (a directory and a symlink in your case) in the same directory. What would you mean when you say /var/www/file.txt? You have to decide...
-
GabrielF over 10 yearsYou should re-read @Shah's comment... you need to delete
www
and then create the symlink.
-
-
Daniel almost 9 yearsDid something change in the symbolic linking the last couple of updates to Ubuntu? I can't seem to do the symlinkning anymore and I get the famous 403 error.
-
emrecnl over 8 years@Daniel so do I
-
sarah.ferguson over 8 yearsthis accepted answer is wrong, first of all you say "delete" or "move" while we are talking about commands so you should put the respective shell command as well. Secondly he has the source and destination wrong in the ln command!
-
Adi Prasetyo over 6 yearsls sally/, got
Too many levels of symbolic links
. -
Shadur over 5 years-1 for answering the question that wasn't asked and not pointing out the actual problem the user was suffering from.
-
Eric Duminil over 2 yearsIn order to remember in which order it should be written, I simply use the same order as
cp
.