1

How to change localhost/sample/index.php to dev.sample.com? I make it in ubuntu using nginx I wonder how to make it in windows using wamp server.

Goper Leo Zosa
  • 1,185
  • 3
  • 15
  • 33
  • Here is a post that should help you create the proper requirements for setting up Virtual hosts. http://stackoverflow.com/questions/23665064/project-links-do-not-work-on-wamp-server/23990618#23990618 – RiggsFolly Jul 06 '15 at 14:18

1 Answers1

1

First you need to add this line:

127.0.0.1 dev.sample.com

To C:\Windows\System32\drivers\etc\hosts (edit with notepad).

After that, uncomment the line (around line number 512):

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

Of C:\wamp\bin\apache\apacheX.Y.Z\conf\httpd.conf by removing the inital #, so you get:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Finally, edit C:\wamp\bin\apache\apacheX.Y.Z\conf\extra\httpd-vhosts.conf by adding this to the end of the file:

<VirtualHost *:80>
    DocumentRoot "c:/YOURPROJECTPATH/sample"
    ServerName dev.sample.com
</VirtualHost>

The apacheX.Y.Z stands for the Apache version your WAMP is using.

You can check more examples on how to create virtual hosts in the Apache's docs examples (WAMP = Windows+Apache+MySQL+PHP).

Once you're done with these edits, left click the WAMP icon near the window's clock, go to Apache > Service > Restart Service and you can now use the new URL. A minor suggestion: you can choose more uncommon URLs, e.g. sample.developer so you don't end up on a real website when Apache service is down.

For keeping the http://localhost/ redirection

You can leave two lines in the C:\Windows\System32\drivers\etc\hosts file:

127.0.0.1 localhost
127.0.0.1 dev.sample.com

Or you can use the same line for this:

127.0.0.1 localhost dev.sample.com

However, I suggest that you don't pile up many references in one line (4 to 5 should be ok). It's preferable to have more lines to the same IP.

Along with your new site's virtual host, you can also have this in C:\wamp\bin\apache\apacheX.Y.Z\conf\extra\httpd-vhosts.conf (above or below the other):

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www"
    ServerName localhost
</VirtualHost>
Armfoot
  • 4,663
  • 5
  • 45
  • 60