How to enable UserDir /home/*/public_html on Debian GNU / Linux 6.0.5 (Squeeze)

Saturday, 22nd September 2012

Enabling mod userdir on Apache server in Debian GNU Linux Squeeze

By default UserDir module is not enabled on Debian. The original documentation related to UserDir is found on Apache’s main website here
On Debain by default the module userdir is installed in directory /usr/lib/apache2/modules/, e.g.:


debian:~# ls -al /usr/lib/apache2/modules/*userdir*
-rw-r--r-- 1 root root 9696 Apr 1 09:40 /usr/lib/apache2/modules/mod_userdir.so

It is installed as external module (not compiled in Apache) – btw something interesting for many might be to see which modules are copmiled as static modules default in Apache by issuing:


debian:~# /usr/sbin/apache2 -l
Compiled in modules:
core.c
mod_log_config.c
mod_logio.c
prefork.c
http_core.c
mod_so.c

In Debian Apache is configured to use Debian’s standard directory locations and use Debian’s config, structure and how to generally manage it, hence in order to add (load) mod_userdir to Apache it is necessery to exec a2enmod perl script:


debian:~# a2enmod userdir
Enabling module userdir.
Run '/etc/init.d/apache2 restart' to activate new configuration!

Another way, which I personally prefer is to create directly symlinks loading the module:


debian:~# ln -sf /etc/apache2/mods-available/userdir.load /etc/apache2/mods-enabled/userdir.load
debian:~# ln -sf /etc/apache2/mods-available/userdir.conf /etc/apache2/mods-enabled/userdir.conf

Next restart Apache server to load the it as suggested by a2enmod:


debian:~# /etc/init.d/apache2 restart
Restarting web server: apache2 ... waiting .

If you want to Allow /home/*users* to be able to use .htaccess, php or simply install CMS systems or alike it is good idea to also change default AllowOverride settings for public_html for that edit /etc/apache2/mods-enabled/userdir.conf and change:



AllowOverride FileInfo AuthConfig Limit Indexes
....

to:



# AllowOverride FileInfo AuthConfig Limit Indexes
AllowOverride all
...

If you do so don’t forget to once again restart apache with /etc/init.d/apache2 restart.

One more thing is to enable PHP for /home/*/public_html, to do so edit /etc/apache2/mods-enabled/php5.conf and comment out:




php_admin_value engine Off




#
#
# php_admin_value engine Off
#

#

#

Thanks to Activating userdir on Debian server blog for pointing out how to enable php for userdirs 🙂

Another alternative way to enable userdirs is to directly create symlinks for each user public_html directory but I guess this is not a best practice, anyways if you prefer to use this instead of using mod_userdir do it with:


ln -sf '/var/www/~username' /home/username/public_html
ln -sf '/var/www/~username1' /home/username1/public_html
...

If you prefer to do symbolic links to public_html for all user homes, you can do it directly in a quick for bash loop by issuing:


for i in /home/*; do
f=$(echo $i | sed -e "s#/home/##g");
ln -sf "/var/www/~$f" /home/"$f"/public_html;
done

Share this on:

Download PDFDownload PDF

Tags: , , , , ,

One Response to “How to enable UserDir /home/*/public_html on Debian GNU / Linux 6.0.5 (Squeeze)”

  1. hip0 says:
    Firefox 3.0.10 Firefox 3.0.10 Windows XP Windows XP
    Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10

    One more thing, I forgot to mention. If you experience an oddity where it seems like you properly configured mod_userdir on the host but still http://domain-name.com/~username is trying to read from /var/www or some other document root different from /home/username/public_html, check out if everything is okay sym-links in /etc/apache2/mods-enabled/.

    ls -al *userdir*
    lrwxrwxrwx 1 root root 30 Sep 21 15:24 userdir.conf -> ../mods-available/userdir.conf
    lrwxrwxrwx 1 root root 30 Sep 21 15:24 userdir.load -> ../mods-available/userdir.load

    It might be that by mistake instaed of linking to /etc/apache2/mods-available/userdir.conf and /etc/apache2/mods-available/userdir.load you might have overwritten some of the two files. This happens for example if you by mistake in the hurry issue:

    ln -sf /etc/apache2/mods-enabled/{userdir.conf,userdir.load} /etc/apache2/mods-available/{userdir.conf,userdir.load} instead of the proper symlink cmd which is:
    ln -sf /etc/apache2/mods-available/{userdir.conf,userdir.load} /etc/apache2/mods-enabled/{userdir.conf,userdir.load}

    It took me about 2 hours of pondering to realize this stupid issue I asked a bunch of guys in freenode and checked closely everything until I finally found out /etc/apache2/mods-available/userdir.load was overwritten to fix this I had to reinstall apache:

    apt-get install –reinstall apache2

    View CommentView Comment

Leave a Reply

CommentLuv badge