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: 192.168.178.31.
So if I type into my browser http://192.168.178.31/
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
</VirtualHost>
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).
Best Answer
Please note that if you are using
mysite.local
instead ofmysite.org
* (or other popular extension) you may typehttp://
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
andwww.mysite.local
from the local machine, edit/etc/hosts
and bind these two domain names to the loopback interface -127.0.0.1
: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 itshost
file and bind the two domain names to the servers IP address:How to Edit Your Hosts File on Windows, Mac, or Linux
The host computer that runs Oracle VirtualBox must be regarded as machine from the virtual LAN, that you've created during the setup of VirtualBox.
Another option is to create your local DNS:
Here is a basic virtual host configuration applicable for your case:
In the beginning put some basic content in
/var/www/mysite
. The functionphpinfo();
is a good idea:Restart Apache and try to access
http://mysite.local
via the browser.Read also: