6

I have created a virtualhost for one of my localhost websites:

<VirtualHost *:80>
  ServerName mysite 
  DocumentRoot /var/www/html/mysite/public
  <Directory /var/www/html/mysite/public>
    Options Indexes FollowSymLinks
    AllowOverride All 
    allow from all 
  </Directory>
</VirtualHost>

Now, I can't access other local websites anymore. for example when I go to localhost/anotherwwebite I get redirected to mysite.

user16948
  • 4,801
  • 10
  • 30
  • 41
  • Do you also have a virtual host for your other local websites? – smang Aug 18 '12 at 03:13
  • From httpd.conf: # Almost any Apache directive may go into a VirtualHost container. The first VirtualHost section is used for requests without a known server name. – Vic Aug 18 '12 at 03:59

2 Answers2

18

To get it work please follow these steps:

  1. Enable Virtual host configuration file from httpd.conf 1

    un comment (remove # from start) below entry

    #Include conf/extra/httpd-vhosts.conf`

  2. Configure httpd-vhost.conf 2

    Here you have to write two configurations set one for localhost and one for virtual host.

    put following

<VirtualHost *:80>
ServerAdmin localhost.admin
DocumentRoot "C:\wamp\www"  >> For UBUNTU /opt/lampp/htdocs/
ServerName localhost
</VirtualHost>

(prior to virtual host)

<VirtualHost *:80>
ServerAdmin pimcore.test
DocumentRoot "C:\wamp\www\pimcore-latest"
ServerName pimcore.test
ErrorLog "logs/pimcore.test.log"
CustomLog "logs/pimcore.test.log" common
</VirtualHost>
  1. and following entries in system hosts 3

    127.0.0.1 localhost

    127.0.0.1 pimcore.test

of course these will vary depends of Your virtual server names.


1 : C:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf OR /opt/lampp/etc/httpd.conf

2 : C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf OR /opt/lampp/etc/extra/httpd-vhosts.conf

3 : C:\WINDOWS\system32\drivers\etc\hosts: OR /etc/hosts

Regards

xkeshav
  • 53,360
  • 44
  • 177
  • 245
masteryoda
  • 272
  • 2
  • 20
  • You are gem.This is straight forward and simple.Why this isn't accepted yet? – xkeshav Dec 10 '14 at 16:59
  • **Worked like a charm**. After searching for 5 hours... finally got something that worked for me! Thanks a ton. – Vivek Padhye Jan 22 '15 at 12:14
  • Thank you! Before, my localhost is redirecting me to the project I set in virtual host. I just added the step no.2 and my localhost works again. – kriscondev Sep 28 '17 at 03:48
  • I'm having the same issue, not on local host however, I do not have a httpd.conf file what would the solution look like on Ubuntu 16.4 ? – user2841639 Jan 07 '20 at 07:42
0

I think you need to add some line in

C:\Windows\System32\drivers\etc\host

add this line

127.0.0.1 yoursitename

for example let ur site name is stack.overflow

127.0.0.1 stack.overflow

in ur browser you can you stack.overflow instead of localhost

so that you can now use yoursitename instead of localhost

hope this help....

Hla Min Swe
  • 291
  • 3
  • 5