Enable Apache2 userdir

 ·  · 

Notes about how to enable userdir module of Apache2.


1 What is userdir

userdir module of Apache2 allow user of server to access the real directory in their home directory by web request.

For example, assume there is a CV HTML file named cv.html locates in /home/USER_NAME/public_html/cv.html.

With userdir module enabled, user can publish or access it in browser by URL: http://SERVER_NAME/~USER_NAME/cv.html.


2 Enable userdir

Enable userdir is easy. Firstly ,enable userdir module by Apache command line tool:

$ sudo a2enmod userdir

Secondly, make sure both the home directory and the userdir folder have correct permissions.

# make sure $HMOE has execute permission, or add it by:
$ chmod +x $HOME

# make sure Apache has permissions to access userdir folder, or add it by:
$ chmod 755 $HOME/public_html

Then if you want to turn on or turn off running PHP scripts under userdir folder, you can edit IfModule section of the configuration file: /etc/apache2/mods-available/php5.conf

<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        php_admin_value engine Off

        # or
        # php_admin_value engine On


3 Restart Apache And Test

Don't forget to restart Apache2.

$ sudo /etc/init.d/apache2 restart

# or
$ sudo service apache2 restarat

Test it by accessing URL in browser: http://SERVER_NAME/~USER_NAME/xxx.html