How to use a symlink in Apache Web Server

36,858

A symlink should work fine. You may or may not need to add the directory to /etc/apache2/apache2.conf so that apache knows it is allowed to access the non-standard directory.

Example (note: I do not use the -d option):

doug@s15:/var/www/html$ ln -s /media/newhd/test_web bla2
doug@s15:/var/www/html$ ls -l
total 44
...
lrwxrwxrwx 1 doug doug   21 May 11 22:14 bla2 -> /media/newhd/test_web
...

Excerpt from '/etc/apache2/acpahe2.conf'

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

<Directory /media/newhd/test_web/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

Make sure all permissions, including parents, are in order. You can do it manually, directory by directory or:

$ namei -m /media/newhd/test_web
f: /media/newhd/test_web
 drwxr-xr-x /
 drwsrwsrwt media
 drwxr-xr-x newhd
 drwxr-xr-x test_web

Now, there are some files systems that do not work with Apache, my example was an ext4 filesystem. And some disks that are automounted (mine is not) need an fstab entry to work properly.

Otherwise help us to help you with a little more information, such as any /var/log/apache2/*.log entries.

Share:
36,858

Related videos on Youtube

Guy D'Amico
Author by

Guy D'Amico

Updated on September 18, 2022

Comments

  • Guy D'Amico
    Guy D'Amico over 1 year

    I Installed Apache2. In the the folder "var/www/html" I created a symlink to a different HDD that holds a number of movie files. My thinking is that it would be easy to access the movies through a browser from any computer on my local network.

    I used the following command string while in the html directory, and created the symlink:

    ln -sd /media/guy/movie1/Movies test
    

    While sitting at the server if I click on "test" it opens the correct directory and exposes the files. If I surf to apache from another machine it does not show the symlink.

    Excerpt from Apache access log:

    192.168.1.158 - - [12/May/2015:08:40:07 -0400] "GET /favicon.ico HTTP/1.1" 404 502 "-" "Mozilla/5.0 (X11; Linux i686; rv:24.7) Gecko/20140802 Firefox/24.7 PaleMoon/24.7.1"
    192.168.1.158 - - [12/May/2015:08:40:07 -0400] "GET /favicon.ico HTTP/1.1" 404 502 "-" "Mozilla/5.0 (X11; Linux i686; rv:24.7) Gecko/20140802 Firefox/24.7 PaleMoon/24.7.1"
    192.168.1.158 - - [12/May/2015:08:40:07 -0400] "GET /favicon.ico HTTP/1.1" 404 502 "-" "Mozilla/5.0 (X11; Linux i686; rv:24.7) Gecko/20140802 Firefox/24.7 PaleMoon/24.7.1"
    192.168.1.158 - - [12/May/2015:08:50:38 -0400] "GET / HTTP/1.1" 200 584 "-" "Mozilla/5.0 (X11; Linux i686; rv:24.7) Gecko/20140802 Firefox/24.7 PaleMoon/24.7.1"
    192.168.1.158 - - [12/May/2015:08:50:39 -0400] "GET /icons/blank.gif HTTP/1.1" 304 178 "http://192.168.1.178/" "Mozilla/5.0 (X11; Linux i686; rv:24.7) Gecko/20140802 Firefox/24.7 PaleMoon/24.7.1"
    
    • Guy D'Amico
      Guy D'Amico almost 9 years
      You mention that I ensure all the permissions are correct, including the parents. I am not sure how to determine that they are correct , I am quite new to this. I created a new symlink since making the changes you described. Here is the ouput of the ls -l command lrwxrwxrwx 1 root root 24 May 12 08:27 new_link -> /media/guy/movie1/Movies lrwxrwxrwx 1 root root 24 May 11 19:56 test -> /media/guy/movie1/Movies
  • Guy D'Amico
    Guy D'Amico almost 9 years
    My problem is permissions but I am unable to change them using chmod. The HDD is NTFS f: /media/guy/movie1/Movies drwxr-xr-x / drwxr-xr-x media drwxr-x--- guy drwxrwx--- movie1 drwxrwx--- Movies
  • Doug Smythies
    Doug Smythies almost 9 years
    Yes, NTFS is probably the problem. My understanding, which might be wrong, is that NTFS doesn't conform well enough to POSIX standards.
  • Doug Smythies
    Doug Smythies almost 9 years
    Have a look at this.