Multiple user Web server

I'm wanting to set up users on a webserver, I'm setting up a public_html folder in their home location. I'm also setting up folders in /usr/local/www/apache22/data/example.com for each domain. I'm trying to set a symlink from the home directory to their respective domain folder using ln -s /usr/local/www/apache22/data/example.com public_html, but when I go to /usr/home/username/public_html it goes to /usr/local/www/apache22/data/ and shows all the folders I have set in there, and doesn't go to the folder I set in the symlink.

Should I have the folders set in /usr/local/www/apache22/data or am I going the wrong path altogether?
 
Please note that on my server I use /var/www/data instead of /usr/local/www/apache22:

Code:
[cmd=#] df -h[/cmd]

Filesystem      Size    Used   Avail Capacity  Mounted on
/dev/ada0s3a    991M    356M    555M    39%    /
devfs           1.0k    1.0k      0B   100%    /dev
/dev/ada0s3d    9.7G    624M    8.3G     7%    /usr
/dev/ada0s3e     19G    137M     17G     1%    /home
/dev/ada0s3f    4.8G     56M    4.4G     1%    /var
/dev/ada0s3g    174G     72M    160G     0%    /var/www
/dev/ada0s3h     29G    184M     26G     1%    /var/db/mysql
tmpfs           1.0G    8.0k      1G     0%    /tmp

I did the following in an attempt to recreate your configuration ;)

  • Create the home directories:

    [cmd=root@althusser:/] mkdir -p /home/example.com/public_html[/cmd]
    [cmd=root@althusser:/] mkdir -p /home/example2.com/public_html[/cmd]


  • Populate with a simple index.html:

    [cmd=root@althusser:/] echo '<html><h1>Example.com under construction</h1></html>' > /home/example.com/public_html/index.html[/cmd]
    [cmd=root@althusser:/] echo '<html><h1>Example2.com under construction</h1></html>' > /home/example2.com/public_html/index.html[/cmd]


  • Change directory to the directory that Apache will serve from:

    [cmd=root@althusser:/] cd /var/www/apache22/data[/cmd]

  • Create the symbolic links:

    root@althusser:/var/www/apache22/data # ln -s /home/example.com .
    root@althusser:/var/www/apache22/data # ln -s /home/example2.com .

  • Test them:

    Code:
    [cmd]root@althusser:/var/www/apache22/data # ls -l ex*com[/cmd]
    
    lrwxr-xr-x  1 root  wheel  17 May  4 20:25 example.com -> /home/example.com
    lrwxr-xr-x  1 root  wheel  18 May  4 20:26 example2.com -> /home/example2.com
  • Restart the server gracefully:

    # service apache22 graceful

From /usr/local/etc/apache22/extra/httpd-vhosts.conf

Code:
<VirtualHost *:80>
    DocumentRoot /var/www/data/example.com/public_html
    ServerName  www.example.com
    ServerAlias example.com *.example.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/data/example2.com/public_html
    ServerName  www.example2.com
    ServerAlias example2.com *.example2.com
</VirtualHost>

Then I messed around with my local name server configuration in such a way that DNS queries for these two domains returned the address of my local test web server:
Code:
[cmd=$] dig www.example.com[/cmd]

; <<>> DiG 9.4.2-P2 <<>> www.example.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63855
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.example.com.               IN      A

;; ANSWER SECTION:
www.example.com.        602509  IN      A       192.168.222.240

;; Query time: 1 msec
;; SERVER: 192.168.222.10#53(192.168.222.10)
;; WHEN: Sat May  4 21:58:17 2013
;; MSG SIZE  rcvd: 49

After that I could browse both sites from my local box and see those 'under construction' pages ;)
 
Harley said:
I'm wanting to set up users on a webserver, I'm setting up a public_html folder in their home location. I'm also setting up folders in /usr/local/www/apache22/data/example.com for each domain.
This sounds like a job for mod_userdir to me.

Unless of course I'm not fully grasping what it is you're trying to do here, but it sounds to me as if you're hosting several domains and now want to give your users access to actually use those. In my opinion that is best done using "user dirs" since that can save you a lot of hassle (like creating symlinks and all that, there should be no need for that).
 
Back
Top