I am pretty new to development and this is why I am stuck at such a "beginners" problem.

I want to have a directory under /var/www/mysite with a index.html and access it via web browser on my PC (Win10 64 Bit) by typing mysite.example into it.

I don't want to publish anything into the internet with that. I only want to test and develop a site which later might be hosted.

I have created a VirtualMachine using Oracle VirtualBox and installed Ubuntu16.04 (64-Bit, also enabled Virtualization at my i5 2500 in Bios so I get these 64-Bit displayed).

Then I installed apache2, mysql and php.

ip addr show gave me an address:

So if I type into my browser I get to the apache2 default page - It works!

I created the directory /var/www/mysite and put a simple index.html for testing purpouse into it. I said sudo chown -R 775 to /var/www/.

Now I need to create a vhost so I can access to this index.html in this specific directory by typing in a specific string into my browser. But it just won't work!

I went to /etc/apache2/sites-available/ and created mysite.conf.

This is the content:

<VirtualHost *80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/mysite
ServerAlias mysite.example

I did a2ensite mysite.conf, sudo service apache2 reload and restart

So there I am. If I type mysite.example into my browser I only get errors.

Site not reached. DNS-Server for mysite.example not found and so on (ERR_NAME_NOT_RESOLVED).


Please note that if you are using mysite.local instead of mysite.org* (or other popular extension) you may type http:// in front of it every time, because the browser may not recognise .local as a domain extension.

  • .google, .dev, .foo, .page, .app, .chrome domain extensions are not good idea for similar purposes since December 2017, read more... and more...

If you want to access mysite.local and www.mysite.local from the local machine, edit /etc/hosts and bind these two domain names to the loopback interface -    localhost mysite.local www.mysite.local
  • Add this line somewhere inside of /etc/hosts.

  • Note that, in this context the local 'machine' is the Virtual Machine with Ubuntu.

If you want to access mysite.local through another computer from your LAN, edit its host file and bind the two domain names to the servers IP address:    mysite.local www.mysite.local

Another option is to create your local DNS:

Here is a basic virtual host configuration applicable for your case:

<VirtualHost *:80>

        ServerName mysite.local
        ServerAlias www.mysite.local

        ServerAdmin webmaster@mysite.local

        DocumentRoot /var/www/mysite

        <Directory /var/www/mysite>
                Options Indexes FollowSymLinks
                AuthType None
                AllowOverride All
                Order allow,deny
                Allow from all
                Require all granted

        ErrorLog ${APACHE_LOG_DIR}/mysite.local-error.log
        CustomLog ${APACHE_LOG_DIR}/mysite.local-access.log combined

  • In the beginning put some basic content in /var/www/mysite. The function phpinfo(); is a good idea:

      echo '<?php phpinfo(); ?>' | sudo tee /var/www/mysite/index.php

Restart Apache and try to access http://mysite.local via the browser.

Read also:

  • Hello pa4080! Thank you for you answer! I have followed your instructions step by step but I still cannot really visit the site via browser on my local machine. It now says ERR_CONNECTION_REFUSED as I try to visit the site.
    – nico
    Jul 31 '17 at 13:44
  • Hi, @nico, what you meant when said "local machine" - Ubuntu inside the VirtualBox - or the computer that runs Oracle VirtualBox?
    – pa4080
    Jul 31 '17 at 14:05
  • The PC that runs the VirtualBox. Sorry for beeing not clear :(
    – nico
    Aug 1 '17 at 13:31
  • 1
    Alright, now I have got it! At least I'm pretty close! Now I get the apache2 Ubuntu Default Page on mysite.dev, which I don't really unterstand. I have rechecked the mysite.conf and de Docroot is correct /var/www/mysite/
    – nico
    Aug 2 '17 at 10:36
  • 1
    This post right here stackoverflow.com/questions/23713061/… got me thinking, I deleted my .conf in sites-available and in sites-enabled, started all from new. Now it finally work! Thank you very much for helping me out with this!
    – nico
    Aug 2 '17 at 11:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.