I need this stuff quite often. Every time i need to create a new virtual host in Ubuntu i have to google/search to find this solution as i cannot remember these paths properly. I am posting it here for quick reference for myself. Bookmark it for yourself (which i am going to do after i have finished posting it ;))
1. Enable virtual hosts by editing httpd.conf, if it is not enabled already. Once you enable it you can skip this step next time.
sudo gedit /opt/lampp/etc/httpd.conf
Find #Include etc/extra/httpd-vhosts.conf and remove the # to un-comment this line
Include etc/extra/httpd-vhosts.conf
2. Add new virtual host by opening the httpd-vhosts.conf file
sudo gedit /opt/lampp/etc/extra/httpd-vhosts.conf
Usually, by default there are two virtual hosts in this file. You can edit one or create new one by copy-pasting one of them. The required entries are DocumentRoot and ServerName
<VirtualHost *:80> ServerAdmin your_email@domain_name.com DocumentRoot /opt/lampp/htdocs/mysite_folder ServerName mysite.local ServerAlias www.mysite.local ErrorLog logs/mysite.local-error_log CustomLog logs/mysite.local-access_log common </VirtualHost>
3. Next, you will need to tell Xampp server where to find the address you added above:
sudo gedit /etc/hosts
Add the following line:
127.0.0.1 mysite.local
4. Restart xampp server by doing
sudo /opt/lampp/lampp restart
5. Type http://local.mysite in browser’s address bar and it should work.
Thank u helpful
Thanku so much,
Welcome! :)
Thanks buddy. Concise and helpful
This is a simple and Great artical. Thank you a lot.
This was just a life saver. Thanks alot.
Dont forget to replace
ServerName mysite.local
ServerAlias http://www.mysite.local
the mysite.local to *mydomain.whatever*
Hi Arvind, your article is great and proved very helpful for me!! I had been struggling before reaching your blog.
Thanks!! :)
When i uncomment this line : Include etc/extra/httpd-vhosts.conf. My Localhost does not work. Any reasons why ??
Add the following line to your /opt/lampp/etc/extra/httpd-vhosts.conf :
DocumentRoot “/opt/lampp/htdocs”
ServerName localhost
Add the following line to your /opt/lampp/etc/extra/httpd-vhosts.conf :
DocumentRoot “/opt/lampp/htdocs”
ServerName localhost
It will be good to add following line while editing httpd-vhosts.conf (in Step2)
ServerAdmin your_email@domain_name.com
DocumentRoot "*YourLocation*"
ServerName mysite.local
ServerAlias www.mysite.local
ErrorLog logs/mysite.local-error_log
CustomLog logs/mysite.local-access_log common
Options All
AllowOverride All
Require all granted