How can I access vhosts using an IP address?

  • Posted on September 3, 2014
  • booruguruAsked by booruguru

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?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others. is an apache mod called userdir. If enabled, it allows any user on the system to create a public_html 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 public_html 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