Configure Apache2 Userdir

Scenario#- Consider a situation that you are a normal user rather a sudo user. You are desperate to run php program or anything require of Apache server. Ohho! You don’t have permission to edit anything in the directory /var/www/html(considering it as DocumentRoot Directory).

No worry, Apache2 provides here you a solution. You can even run everything from your home directory. It’s a job of 10 minutes. Believe me. 🙂

Steps Involved

$cd /home/username/
$mkdir public_html

Don’t make it with sudo as it will come under the owner root.

Change the permissions of certain directories.

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

Now, move to the directory mods-available

$cd /etc/apache2/mods-available
$sudo touch userdir.load           //don't replace userdir with your username
$sudo vim userdir.conf

Add the following code in it and save.

<IfModule mod_userdir.c>
        UserDir public_html
        UserDir disabled root
        <Directory /home/*/public_html>
                AllowOverride FileInfo AuthConfig Limit Indexes
                Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
                <Limit GET POST OPTIONS PROPFIND>
                     Require all granted
                </Limit>
                <LimitExcept GET POST OPTIONS PROPFIND>
                     Require all granted
                </LimitExcept>
        </Directory>
</IfModule>

 

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

And you are done! Now you can browse to http://localhost/~username

Apart from it, I tried to set up Apache virtual hosts using the link.

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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