Goper Leo Zosa
Goper Leo Zosa

Reputation: 1283

How to modify web address in localhost using wamp?

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.

Upvotes: 1

Views: 1172

Answers (2)

Tamás Bolvári
Tamás Bolvári

Reputation: 3044

http://localhost/add_vhost.php

(Just use that link, and read the instructions.)

Upvotes: -1

Armfoot
Armfoot

Reputation: 4921

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>

Upvotes: 3

Related Questions