How can I access vhosts using an IP address?

September 3, 2014 4k views

Whenever I signed up for a web hosting account powered by cPanel, I would receive a welcome e-mail providing an address for accessing my site without the domain name.

Usually would look something like...

However, now that I am using Digital Ocean, I am no longer using cPanel, but sometimes I might to access a vhost using just the IP address. How could I go about doing that?

2 Answers is an apache mod called userdir. If enabled, it allows any user on the system to create a publichtml folder inside of their home folder and it can be accessed via the method above. For example, if the mod was enabled and my account on the server was mark and my home directory was /home/mark, I could create a folder called publichtml and put web files in there and access them via

If you have multiple IP addresses you can set up IP based virtual hosting. This means accessing different websites uising different IPs all on the same server.

You also have name based virtual hosts, which lets you use multiple domains (or sub domains) and have them 'resolve' or map to different websites, all on the one IP address. This lets, and all map to different websites, even though they're all hosted on the one server. You just need to set up virtual host required.

cPanel typically uses a mix of both named based virtual hosting and user dir mod, which gives it the functionality you describe. This is a common set up in shared hosting.

Since you seen to be more interested than the userdir mod, I'll focus on that.

Log in as root and type

a2enmod userdir
nano /etc/apache2/mods-enabled/userdir.conf

Make sure it looks like below (as per debian instructions):

<IfModule mod_userdir.c>
        UserDir public_html
        UserDir disabled root

        <Directory /home/*/public_html>
                AllowOverride All
                Options MultiViews Indexes SymLinksIfOwnerMatch
                <Limit GET POST OPTIONS>
                        Order allow,deny
                        Allow from all
                <LimitExcept GET POST OPTIONS>
                        Order deny,allow
                        Deny from all

Edit php config to allow php in user dirs

nano /etc/apache2/mods-available/php5.conf

Ensure it looks like this:

<IfModule mod_php5.c>
    <FilesMatch "\.ph(p3?|tml)$">
        SetHandler application/x-httpd-php
        Require all granted
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
        Require all denied
    # 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

Assuming you have a basic LAMP stack installed and configured, you should be able to add a user to the system, create a public_html folder in there and put some php/html pages and access them via

Remember to add files as the username you created, not root. Make sure the files have correct permissions. If you get access forbidden, run this command as the user you want the web pages in.

chmod 0775 -R ~/public_html
by Etel Sverdlov
This tutorial shows you how to set up a new directory, how to grant the correct permissions, how to add content to a new page, how to turn on virtual hosting, and how to, if needed, set up local hosts. Virtual Hosts are used to run more than one domain off of a single IP address and allows you to run multiple sites off of a single DigitalOcean droplet. This tutorial describes how to set up virtual hosts with Apache.
Have another answer? Share your knowledge.