creating virtual host in WAMP - php

I'm using Win7 and all my asp.net applications are running at port 80
I've WAMP installed at c:\wamp and i've my php project folder under c:\wamp\www\ as proj1,proj2 etc.,
Now i tried to create virtual host with below steps
1) edited 'hosts' file and added below
127.0.0.1:9091 testsite1.mymachine.com
2) Opened the file "httpd.conf" at "C:/wamp/bin/apache/Apache2.2.22/conf/" and uncommented the line "Include conf/extra/httpd-vhosts.conf".
3) Opened the file "httpd.vhosts.conf" at "C:/wamp/bin/apache/Apache2.2.22/conf/extra" and added the below
<Directory C:/wamp/www/proj1>
Order Deny,Allow
Allow from all
</Directory>
after the above code added the below
<VirtualHost *:9091>
DocumentRoot "C:/wamp/www/proj1"
ServerName testsite1.mymachine.com
</VirtualHost>
4) Saved all the above edited files from step 1 through step 3, restarted the wamp server services.
But, i'm unable to access my proj1 using "testsite1.mymachine.com". did i missed anything ? Also please take note by using "http://localhost:8081/" i'm able to see wampserver - server configuration page.
Many Thanks

goto F:\wamp\bin\apache\Apache2.2.21\conf and open httpd.conf file in text editor
change line from #LoadModule vhost_alias_module modules/mod_vhost_alias.so
to this LoadModule vhost_alias_module modules/mod_vhost_alias.so (uncomment)
find following lines
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
replace it with
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
now goto F:\wamp\bin\apache\Apache2.2.21\conf\extra and open httpd-vhosts.conf
at the end add following code to httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/wamp/www/(project folder name)"
ServerName (the name with which you want to deploy your project in the browser)
ServerAlias (copy paste the ServerName)
ErrorLog "logs/(deploy_name)-error.log"
CustomLog "logs/(deploy_name)-access.log" common
<Directory "/">
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
finallly update the hosts file in windows system
goto C:\Windows\System32\drivers\etc open hosts using notepad (open notepad as administrator).
find line 127.0.0.1 localhost
under it write 127.0.0.1 (copy paste the ServerName from "httpd-vhosts.conf")
restart all the services from wamp.
this should get the virtual host running, just type the server name in the addres bar of browser and hit enter.

Related

How do you create virtual hosts (that also use SSL) on localhost with MAMP and Apache?

Suppose you have a local project at /Users/yourname/Sites/example and want to be able to use both http://example.local and https://example.local to reach it on your Mac, using MAMP (I'm using MAMP version 6.6).
Read the answer for the steps to take.
1) Add your custom domain to the hosts file
Open the Finder and choose the Go to folder command from the Go menu. Enter /private/etc/hosts as the path; this will open a Finder window where you will find the hosts file.
Open the hosts file and map your custom domain to 127.0.0.1 (localhost):
127.0.0.1 localhost
127.0.0.1 example.local
Now, when you visit http://example.local, the browser will redirect you to localhost and show your list of local sites (which is not what we want yet, but hey, this is just the first step).
2) Configure MAMP to use Apache's and MySql's default ports
Open MAMP, click on Preferences, then go the Ports tab. By default, MAMP uses port 8888 for Apache and 8889 for MySQL, but it gives you the option to use Apache's default port (80) as well as MySQL's default port (3306): click the 80 & 3306 button to use these ports rather than 8888 and 8889.
3) Enable virtual hosts in Apache
Go to and open the /Applications/MAMP/conf/apache/httpd.conf file. Look for this line:
# Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Uncomment the line by removing the asterisk at the beginning: uncommenting the line enables virtual hosts. (If the line is already uncommented, you're good to go for this step).
4) Configure Apache to listen to port 80
While you have /Applications/MAMP/conf/apache/httpd.conf open, also look for this line:
Listen 8888
and change it to
Listen 80
Listen 443
In the previous step, you told MAMP to use port 80 for Apache, so the first line tells Apache to listen to port 80 rather than port 8888; the second line tells Apache to also listen to requests incoming on port 443: this is the port typically used by SSL connections, so it is an essential step to be able to reach your local site at https:// besides http://.
5) Create a SSL certificate for your local site
You need a SSL certificate to be able to reach your site at https://example.local as well. This can be easily done using the mkcert tool. You can read the instructions on Github, but basically it's about installing the tool, then running:
$ mkcert example.local
This generates two files: a certificate (example.local.pem) and a certificate key (example.local-key.pem).
Move these two files somewhere within your project. For example, you could create a hidden folder at the root of your project called .crt and put them in there.
6) Create a virtual host for your local site
Finally, it's time to actually create a virtual host for your local site. Go to and open the /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf file and include the following:
// These first two lines tell Apache to check for virtual hosts
// whenever a request comes in on port 80 (http://) or 443 (https://)
NameVirtualHost *:80
NameVirtualHost *:443
// This first directive tells Apache to serve the files at "/Users/yourname/Sites/example"
// whenever "http://example.local" is visited
<VirtualHost *:80>
ServerName example.local
DocumentRoot "/Users/yourname/Sites/example"
</VirtualHost>
// This second directive tells Apache to serve the files at "/Users/yourname/Sites/example"
// whenever "https://example.local" is visited, and provides paths to the certificates
// we previously created
<VirtualHost *:443>
ServerName example.local
DocumentRoot "/Users/yourname/Sites/example"
SSLEngine On
SSLCertificateFile "/Users/yourname/Sites/example/.crt/example.local.pem"
SSLCertificateKeyFile "/Users/yourname/Sites/example/.crt/example.local-key.pem"
</VirtualHost>
That's it! Now you can view your site at both http://example.local and https://example.local
(Remember to adapt the paths to wherever your project and certificates are located though).
7) Need virtual hosts for multiple local sites?
Want to add virtual hosts for more local sites you have, eg. for a site you want to reach at http://test.local?
Go to /private/etc/hosts and add 127.0.0.1 test.local
127.0.0.1 localhost
127.0.0.1 example.local
127.0.0.1 test.local
Generate SSL certificates with mkcert test.local (like we did earlier on step 4).
Finally, update the virtual hosts file as follows:
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
ServerName example.local
DocumentRoot "/Users/yourname/Sites/example"
</VirtualHost>
<VirtualHost *:443>
ServerName example.local
DocumentRoot "/Users/yourname/Sites/example"
SSLEngine On
SSLCertificateFile "/Users/yourname/Sites/example/.crt/example.local.pem"
SSLCertificateKeyFile "/Users/yourname/Sites/example/.crt/example.local-key.pem"
</VirtualHost>
// Basically, copy and paste the virtual hosts for the example project
// and update the domain and paths accordingly
<VirtualHost *:80>
ServerName test.local
DocumentRoot "/Users/yourname/Sites/test"
</VirtualHost>
<VirtualHost *:443>
ServerName test.local
DocumentRoot "/Users/yourname/Sites/test"
SSLEngine On
SSLCertificateFile "/Users/yourname/Sites/test/.crt/test.local.pem"
SSLCertificateKeyFile "/Users/yourname/Sites/test/.crt/test.local-key.pem"
</VirtualHost>
8) Bonus: add extra configuration to your virtual hosts
The VirtualHost directive can accept a number of extra instructions that tell Apache what to do when a certain request is received.
For instance, suppose our example project is a Node application that can be reached at http://localhost:3000, but we want to use http://example.local to access it. We would have to tell Apache to forward any request made to http://example.local to http://localhost:3000.
NameVirtualHost *:80
NameVirtualHost *:443
// This line loads a module that enables proxying (it's turned off by default)
LoadModule proxy_http_module modules/mod_proxy_http.so
// The ProxyPass and ProxyPassReverse lines tell Apache
// to forward the request to http:// and https://localhost:3000
<VirtualHost *:80>
ServerName example.local
DocumentRoot "/Users/yourname/Sites/example"
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
<VirtualHost *:443>
ServerName example.local
DocumentRoot "/Users/yourname/Sites/example"
SSLEngine On
SSLCertificateFile "/Users/yourname/Sites/example/.crt/example.local.pem"
SSLCertificateKeyFile "/Users/yourname/Sites/example/.crt/example.local-key.pem"
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>

MAMP all virtual hosts point to htdocs folder

I've read through all the questions I could find but none of them have worked for me. I'm trying to set up a couple of virtual hosts on my MAMP apache install. Currently, typing localhost takes me to my htdocs as expected. However, typing mysite.dev should take me to another directory but it instead drops me off at htdocs.
hosts
##
# Host Database
#
#
# localhost is used to configure the lookback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 mysite.dev
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
I've uncommented in httpd.conf
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
And I've set up my httpd-vhosts.conf a bunch of different ways with the same result. The current state is:
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin mysite.dev
DocumentRoot "/Applications/MAMP/htdocs/mysite/public"
ServerName mysite.dev
ServerAlias www.mysite.dev
ErrorLog "logs/mysite.dev"
CustomLog "logs/mysite.dev" common
</VirtualHost>
Any help would be greatly appreciated. Thanks!
You might miss some steps. First of all
run mamp with apache 80 and mysql 3306 port. this will automatically change the httpd.conf file with those port. close mamp
go to httpd.conf and go to line: 575 and uncomment this line from
# Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
to
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
If it is not line 575 search with the text and u will find the line.
Next in httpd-vhosts.conf, add your virtual urls/hosts. sample below
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/Project"
ServerName dev.project.com
ServerAlias www.dev.project.com
</VirtualHost>
dev.project.com is just sample and you can name it however you want. server alias is optional but better to keep it just likeserver name but with an extra "www." as it is shown above.
next add those to hosts file like
127.0.0.1 dev.project.com
better to add all possibilities like below
127.0.0.1 dev.project.com http://dev.project.com www.dev.project.com http://www.dev.project.com
save the hosts file and restart mamp. Cheers!!!
I THINK YOU GUYS MISSED STEP 2

Configuration of virtual host

I was trying to create a virtual host on my localhost, I followed a tuto on the internet. Here're the steps :
1) I created my project on desktop (using laravel 5)
2) I opend the file "httpd-vhosts.conf" (C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-binaries\httpserver\apache2418x161221110224\conf\httpd-vhosts.conf ) to uncomment this line : "Include conf/extra/httpd-vhosts.conf"
3) I edited the file "httpd-vhosts.conf" I added the following lines :
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:\Users\Sony\Desktop\links"
ServerName links.localhost
</VirtualHost>
4) I edited the file "hosts" (C:\Windows\System32\drivers\etc\hosts)
and added this line "127.0.0.1 links.localhost"
5) Then I restarted easyphp and executed the following command on my command line : ipconfig /flushdns
--> Results :
The file "httpd-vhosts.conf" is empty
This line is commented again : "Include conf/extra/httpd-vhosts.conf"
When I try to access the vhost "http://links.localhost", is just like if i am accessing the localhost
This is what I have at the end of "httpd.conf"
# VIRTUAL HOSTS
## Virtualhost localweb
<VirtualHost 127.0.0.1>
DocumentRoot "C:/Program Files (x86)/EasyPHP-Devserver-16.1/eds-www"
ServerName 127.0.0.1
<Directory "C:/Program Files (x86)/EasyPHP-Devserver-16.1/eds-www">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
</VirtualHost>
#Costumized vhost config file
Include conf/links-vhost.conf
First create a file (say) name it links.conf and add your Virtual host
<VirtualHost *:80>
DocumentRoot "C:\Users\Sony\Desktop\links"
ServerName links.localhost
</VirtualHost>
Now at the the end of your httpd.conf add : Include conf/links.conf.

XAMPP 3.2.1 Virtualhost is not working

I am using XAMPP 3.2.1 and creating new virtual host in http-vhosts.conf file in Apache the code below
<VirtualHost *:8080>
DocumentRoot "C:/xampp/htdocs/support/srinet"
ServerName supportcenter.sevplcorp.com
Alias /mrpdf "E:/temp"
<Directory "C:/xampp/htdocs/support/srinet">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
When I open supportcenter.sevplcorp.com in browser windows it shows like below
You have to edit your host file located at : %WINDIR%\system32\drivers\etc\hosts.
Add a newline 127.0.0.1 supportcenter.sevplcorp.com
Probably you haven't altered your hosts file to map the host domain to server's IP address. Assuming that you're running XAMPP on your own PC, open your editor as Administrator (notepad is sufficient), then open this file:
c:\Windows\System32\Drivers\etc\hosts
...and add this line to the bottom:
127.0.0.1 supportcenter.sevplcorp.com
Save the file and, after that, visiting supportcenter.sevplcorp.com should work. Basically, by altering the hosts file you're telling the browser (and everything else that might want to access supportcenter.sevplcorp.com) that it's actually your PC.

Hosting multiple local sites with XAMPP

I'm new to using XAMPP so this may be simple to some people.
I have a few php projects that I would like to be able to debug locally and view in the browser (not concurrently, but without having to change config files/copy project folders each time I want to work on a different project).
On IIS, you could set up multiple sites to serve from your machine, and I'm looking for something similar in XAMPP. When using IIS, I added multiple records to the Windows hosts file so I could access the locally hosted sites by typing friendly web-style addresses (like http://myproject1.dev)
Thanks.
Greg, you're almost there--you need (like Moses said) to setup virtual hosts.
So if your Windows hosts file has
127.0.0.1 localhost
127.0.0.1 mysite-dev.com
127.0.0.1 anothersite-dev.com
Your virtual hosts file (httpd-vhosts.conf) might look like:
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
ServerName mysite-dev.com
DocumentRoot "C:/sites/mysite-dev"
<Directory "C:/sites/mysite-dev">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName anothersite-dev.com
DocumentRoot "C:/sites/anothersite-dev"
<Directory "C:/sites/anothersite-dev">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Don't forget to restart the web server after you make any changes.
I would like to make an additional in terms of up to date information.
XAMMP uses port 80 by default and we are able to publish 1 website. I also use IIS for .Net projects. In this respect, I set the port to XAMMP except the 80 port. So I avoid a conflict.
When we want to publish more than one website, we should do the following operations to httpd.conf (this is the current name).
1. Setting the ports
Find the #Listen expression in the httpd.conf file.
Change Listen 80 to Listen 8000 (or whatever else you want)
Listen 8000
If you need 3 different websites, type the others, including 1 definition on each line, as follows.
Listen 8001
Listen 8002
Listen 8003
2. Define the file paths of sites accessed through ports
Again, find in the httpd.conf file.
Identify the folders of each website as follows.
As you would see, I've created 3 directories called 8000, 8001, 8002 and 8003 under the htdocs directory within the XAMMP directory.
<VirtualHost *:8000>
 DocumentRoot "C:\XAMPP\htdocs\8000"
 ServerName localhost:8000
<\ VirtualHost>
<VirtualHost *:8001>
 DocumentRoot "C:\XAMPP\htdocs\8001"
 ServerName localhost:8001
<\ VirtualHost>
<VirtualHost *:8002>
 DocumentRoot "C:\XAMPP\htdocs\8002"
 ServerName localhost:8002
<\ VirtualHost>
<VirtualHost *:8003>
 DocumentRoot "C:\XAMPP\htdocs\8003"
 ServerName localhost:8003
<\ VirtualHost>
Restart your Apahche server on XAMMP.
You can now view your 3rd site, such as http://localhost:8003 or http://192.168.1.1:8003/.
Hope to be useful.
This question was asked almost ten years ago, and the answers above are a bit dated. Note that XAMPP has a "How-To" for virtual hosts avilable off the dashboard, when you install it.
From the "Welcome to XAMPP for Windows" page (localhost/dashboard, the default when you first load localhost) click on the "HOW-TO" Guides in the top menu bar. From there, look for the link "Configure Virtual Hosts" which will lead you to the localhost page "http://localhost/dashboard/docs/configure-vhosts.html"
In a nutshell, the process involves editing the "httpd-vhosts.conf" file (typically in C:\XAMPP\apache\conf\extra) and replacing the contents of that file with something like this:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
# vhosts - note sample entry from XAMPP how-to throws an error, so try this:
<VirtualHost *:80>
DocumentRoot "C:/Users/jdoe/Documents/dev.mysite.com/htdocs"
ServerName mysite.local
<Directory "C:/Users/jdoe/Documents/dev.mysite.com/htdocs">
Require all granted
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Additional vhosts (including SSL hosts) can be had by cloning the entry, and modifying DocumentRoot and ServerName directives and port numbers (e.g. 443 for TLS (SSL)). You can find tutorials on the web for creating and signing your own certificate, if you want to go that route.
The final step is to get your Windows machine to point your browser to the Apache host for your virtual domain (e.g. above, http://mysite.local). Using a text editor (Notebook will do) as administrator append the following entry onto your hosts file, which lives here:
C:\Windows\System32\drivers\etc\hosts
Append this entry to the hosts file:
127.0.0.1 mysite.local
IMPORTANT - you must restart your Windows machine or the new host will not respond. Some documentations will tell you just to restart the browser and Apache server, but I've found that's not sufficient.
IME, the hosts system and Apache directives can be particular, so be patient. You may need to rebuild configs, restart Apache, and restart your machine more than once.

Categories