21

I tried to create a virtual host magento.developers.com in Ubuntu 12.04 using XAMPP.
First I have edited the /opt/lampp/etc/extra/httpd-vhosts.conf and added the following lines:

<VirtualHost *:80>
    ServerAdmin webmaster@magento.developers.com
    DocumentRoot "/opt/lampp/htdocs/magento"
    ServerName magento.developers.com
    ErrorLog "logs/magento.developers.com-error_log"
    CustomLog "logs/magento.developers.com-access_log" common
</VirtualHost>


I have restarted XAMPP using the command sudo /opt/lampp/lampp restart and then I have edited
the hosts file and added:

127.0.0.1   magento.developers.com

Then I tried to access magento.developers.com using the browser and it's not accessing

/opt/lampp/htdocs/magento

What I have to do to make it work and access magento folder instead of htdocs (the root)?

Ahmed Jolani
  • 2,872
  • 2
  • 20
  • 24

3 Answers3

29

The virtual hosts conf by defualt is disabled in httpd.conf, in order to allow virtual hosts
in XAMPP under Ubuntu you have to uncomment line 480 in httpd.conf:

MAINSTEP: Uncomment line 480 as below:

479. # Virtual hosts
480. Include etc/extra/httpd-vhosts.conf

The httpd.conf file is located under /opt/lampp/etc, to modify it just follow these steps:

1. run sudo gedit /opt/lampp/etc/httpd.conf
2. apply MAINSTEP

Ahmed Jolani
  • 2,872
  • 2
  • 20
  • 24
  • @AmitGarg: does your htdocs work after you enable virtual hosts? My projects inside htdocs don't show up if I enable virtual hosts.. thats wierd :/ – Ghazanfar Mir Mar 10 '13 at 14:07
  • @GhazanfarMir My other projects on localhost was not working after creating vartualhost. So I have desabled virtual host. – Amit Garg Mar 11 '13 at 10:49
  • @AmitGarg: Ok - I have figured out why my virtual hosts weren't working.. I had missed the entry for default htdocs directory which is ` DocumentRoot "/opt/lampp/htdocs" ServerName localhost ErrorLog "logs/localhost-error.log" CustomLog "logs/localhost-access.log" combined ` – Ghazanfar Mir Mar 11 '13 at 11:36
  • Once I put this entry for htdocs on top of other virtual hosts it started working.. I hope this would be of help – Ghazanfar Mir Mar 11 '13 at 11:37
  • 1
    Do not forget to setup correctly your /etc/hosts file (equivalent to DNS entry). When adding vistual hosts, DNS table must be edited by you, then system do not do it automatically! – devasia2112 Apr 23 '14 at 22:04
  • I was going nuts... you saved me. Tanks a lot. We are in 2020, and most of the time in developing applications is trying to figure out configuration, not programming solutions... is there a good apache2 tutorial that doesn't assume a lot of previous knowledge? Thank you again... – RolandoEfren Oct 20 '20 at 07:07
4

Step 1: Edit apache configuration

sudo nano /opt/lampp/etc/httpd.conf

and find below the line and uncomment (remove #) and save

Include etc/extra/httpd-vhosts.conf

Step 2: Edit vhost configuration to Add Virtual Host

sudo nano /opt/lampp/etc/extra/httpd-vhosts.conf

and add below code with your DocumentRoot (/opt/lampp/htdocs/example) and ServerName (URL)(example.local)

<VirtualHost *:80> ServerAdmin your@email.com DocumentRoot "/opt/lampp/htdocs/example" ServerName "example.local" ErrorLog "logs/example.local-error_log" CustomLog "logs/example.local-access_log" common </VirtualHost>

Step 3: Edit host file to add your URL (example.local)

sudo nano /etc/hosts

and add this line to the bottom with your URL (example.local) and save

127.0.1.1 example.local

Step 4: Restart server

sudo /opt/lampp/lampp restart

namal
  • 1,164
  • 1
  • 10
  • 15
0

Create Vertual Host:-

sudo vi /opt/lampp/etc/httpd.conf

and uncomment following line

Include etc/extra/httpd-vhosts.conf

Now Create n number of host below commands:

sudo nano /opt/lampp/etc/extra/httpd-vhosts.conf (enter host entry).

sudo nano /etc/hosts                 (do host file entry)

then restart xampp

sudo /opt/lampp/lampp restart