Archive for September 22nd, 2012

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

Saturday, September 22nd, 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