Setting up vhost on VirtualBox with Ubuntu 16.04 [duplicate]
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 - 127.0.0.1
:
127.0.0.1 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:
192.168.178.31 mysite.local www.mysite.local
-
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:
- How To Configure BIND as a Private Network DNS Server on Ubuntu 14.04
Here is a basic virtual host configuration applicable for your case:
<VirtualHost *:80>
ServerName mysite.local
ServerAlias www.mysite.local
ServerAdmin [email protected]
DocumentRoot /var/www/mysite
<Directory /var/www/mysite>
Options Indexes FollowSymLinks
AuthType None
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/mysite.local-error.log
CustomLog ${APACHE_LOG_DIR}/mysite.local-access.log combined
</VirtualHost>
-
In the beginning put some basic content in
/var/www/mysite
. The functionphpinfo();
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:
- Virtual Host not working as expected when I'm using .dev domain extension
- Creating additional Virtual Host Ubuntu Server