[HowTo] Make Apache User Directory on Ubuntu

On system (in my case is Ubuntu server) with have multiple user and each user permit to have their own home directory, then you need to install mod_userdir on your apache. So you can have the address like this: www.anyurl.com/~username/. Each user will have their own subdirectory specified by UserDir driective in the configuration.

To install userdir module in apache on ubuntu server is not hard. Only need a couple steps and change directory permission.

Follow these steps below:

  1. Open your terminal and login as root
  2. Go to apache directory, in Ubuntu default setting it would be in /etc/apache
  3. Now you need to install userdir module, type this command to install:
    a2enmod userdir
  4. Then now edit the file userdir.conf, it would be in /etc/apache/mods-enabled directory
  5. Copy and paste this setting:
           <ifModule mod_userdir.c>
            UserDir public_html
            UserDir disabled root
    
            <directory /home/*/public_html>
                    #AllowOverride FileInfo AuthConfig Limit Indexes
                    suPHP_Engine on
                    AllowOverride All
                    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec FollowSymLinks
                    <limit GET POST OPTIONS>
                            Order allow,deny
                            Allow from all
                    </limit>
                    <limitExcept GET POST OPTIONS>
                            Order deny,allow
                            Deny from all
                    </limitExcept>
            </directory>
    </ifModule>
  6. Up to this step, you already activate userdir module. Now open another terminal with normal user. Then create public_html in home directory. Then change the directory group owner to www-data, with this command:
    chgrp www-data public_html/
  7. Back to root terminal, then restart apache with this command:
    /etc/init.d/apache restart
  8. Now open your browser and type: http://localhost/~username/ , you should see “It Works” if you got it right.

That’s it for now, leave me any comment if you find this article is helpful or if you want to ask anything. Thank you for visiting and have a nice day.

Comments

  1. Francis (Grizzly) Smit says:

    this is no good without suPHP installed and I don't want that as it wants to install the cgi php which is not what I want

  2. Francis (Grizzly) Smit says:

    this is no good without suPHP installed and I don't want that as it wants to install the cgi php which is not what I want

  3. Egor says:

    There is a little less complicated decision at http://ubuntuforums.org/showthread.php?t=1521010&page=1

  4. Thanks mate

  5. Parul_payalgupta says:

    i have no permision to made mods-enabled… please help me how we change the permission??

  6. maurora says:

    it works! thank you so much. Your document just solve my problem. !!

  7. Dan says:

    I have had to remove the line of code "suPHP_Engine on" from the userdir.conf file so apache could start again. An now without it php does not work when browsing to a users public_html folder. But it does still work in /var/www/

    Please help

  8. Isogashii says:

    I was struggling since the first days I started using Kubuntu as my operating system, I really wanted something similar to cpanel installations in my development environment.
    Your article did the trick, good luck 😉

  9. Rashi Dhing says:

    Hi, I followed your instructions but when I visit the http://localhost/~username/ page, it triggers a download and I get the following download error in a window: "/tmp/SeJ0SBf_.phtml-1.part could not be opened, because the associated helper application does not exist. Change the association in your preferences."
    I looked online but could not find any solution . What can possibly be wrong ?

  10. Simon_george70 says:

    I've tried this (and just about everything else) but still get this error
    Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0

    Fatal error: Unknown: Failed opening required '/home/lonetree/public_html/index.php' (include_path='.:/inc:./inc:../inc:../../inc:../../../inc:../../../../inc:/usr/share/php') in Unknown on line 0

    Please help

  11. I opened the /etc/apache2/mods-enabled directory, then see the php5.conf

    <IfModule mod_php5.c>
    <FilesMatch ".ph(p3?|tml)$">
    SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch ".phps$">
    SetHandler application/x-httpd-php-source
    </FilesMatch>
    To re-enable php in user directories comment the following lines
    # (from <IfModule …> to </IfModule>.) Do NOT set it to On as it
    #prevents .htaccess files from disabling it.
    <IfModule mod_userdir.c>
    <Directory /home/*/public_html>
    php_admin_value engine Off
    </Directory>
    </IfModule>
    </IfModule>

    So, I followed the instruction, voila!

  12. I opened the /etc/apache2/mods-enabled directory, then see the php5.conf

    <IfModule mod_php5.c>
    <FilesMatch ".ph(p3?|tml)$">
    SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch ".phps$">
    SetHandler application/x-httpd-php-source
    </FilesMatch>
    To re-enable php in user directories comment the following lines
    # (from <IfModule …> to </IfModule>.) Do NOT set it to On as it
    #prevents .htaccess files from disabling it.
    <IfModule mod_userdir.c>
    <Directory /home/*/public_html>
    php_admin_value engine Off
    </Directory>
    </IfModule>
    </IfModule>

    So, I followed the instruction, voila!

Give me your feedback

This site uses Akismet to reduce spam. Learn how your comment data is processed.