How To Configure public_html folder in home dirctory same as /var/www in Apache2?

If you want to set up Apache2 so that users have personal websites in their home directories, with /home/user/website linking to or localhost/~user  . You can do this using the userdir module of Apache.

Follow the following steps:

1. Create public_html folder in home. Remember don’t use sudo with it.

$mkdir public_html

2. Now open you apache server config file and edit to enable public_html for that uncomment UserDir public_html and comment UserDir disabled and also uncomments the lines below from where Directory start to ends.

$ sudo vi /etc/apache2/httpd.conf

Here is the /etc/apache2/httpd.conf file after editing:

# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.

<IfModule mod_userdir.c>
    # Note that the name of the user directory ("public_html") cannot easily be
    # changed here, since it is a compile time setting. The apache package
    # would have to be rebuilt. You could work around by deleting
    # /usr/sbin/suexec, but then all scripts from the directories would be
    # executed with the UID of the webserver.
    # To rebuild apache with another setting you need to change the
    # %userdir define in the spec file.

    # not every user's directory should be visible:
    UserDir disabled root

    # to enable UserDir only for a certain set of users, use this instead:
    #UserDir disabled
    #UserDir enabled user1 user2

 # the UserDir directive is actually used inside the virtual hosts, to
    # have more control
    UserDir public_html

    <Directory /home/*/public_html>

        AllowOverride FileInfo AuthConfig Limit Indexes
        Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

            Order allow,deny
            Allow from all

            Order deny,allow
            Deny from all



3. Next, we will need to make sure the permissions are set correctly. Your /home directory needs to have permissions 711, the same goes for your users home directory. The public_html on the other hand needs to be 755, and it’s content world readable (minimum 604, or o+r):

$ chmod 711 /home
$ chmod 711 /home/priyanka
$ chmod 755 /home/priyanka/public_html
$ chmod o+r /home/priyanka/public_html/index.html

4.  There are only two commands you need to enter to activate the User Directory feature, and then one command to reload the configuration files. The last command includes an absolute path, so it doesn’t matter where you execute it from. The first two “ln” commands assume you are in the directory /etc/apache2/mods-enabled. What you need to do is create two symbolic links (soft links, symlinks) in the stated directory pointing to the corresponding module in /etc/apache2/mods-available. So, if “$” is your prompt,

$ cd /etc/apache2/mods-enabled
$ sudo ln -s ../mods-available/userdir.conf userdir.conf
$ sudo ln -s ../mods-available/userdir.load userdir.load
$ sudo /etc/init.d/apache2 restart 

Now open in browser http://localhost/~priyanka It will show indexof priyanka and you are done.

About Priyanka Kapoor

Simple, Hardworking & friendly.....
This entry was posted in Uncategorized. Bookmark the permalink.

7 Responses to How To Configure public_html folder in home dirctory same as /var/www in Apache2?

  1. I am really delighted to glance at this website posts which consists of plenty of useful data, thanks for providing these kinds of information.

  2. Aicha says:

    thanks for the useful information.

  3. Ester says:

    nice thank you for sharing most informative ideas and also your good view.

  4. Pingback: CGI Configuration on Apache | Mandeep Simak

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s