I am trying to create a virtual host in xampp windows 7.
#NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/project/Trunk/xyz"
ServerName xyz.local
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
host
127.0.0.1 localhost
127.0.0.1 xyz.local
Edit 1: httpd -t -D DUMP_VHOSTS result is given below
VirtualHost configuration:
*:80 is a NameVirtualHost
default server abcd (C:/xampp/apache/conf/extra/httpd-vhosts.conf:45)
port 80 namevhost abcd (C:/xampp/apache/conf/extra/httpd-vhosts.conf:45)
port 80 namevhost localhost (C:/xampp/apache/conf/extra/httpd-vhosts.conf:49)
port 80 namevhost xyz.local (C:/xampp/apache/conf/extra/httpd-vhosts.conf:53)
*:443 www.example.com (C:/xampp/apache/conf/extra/httpd-ssl.conf:102)
Edit 2: Attachment - website not found error
Calling http://xyz.local/ shows the website not found error. But if I configure entire thing with only xyz (not .local in the string xyz.local) it is working fine after calling http://xyz/. I want it as http://xyz.local/. How can I achieve this?
Related
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>
My Apache and MySQL instance starts up fine. For some reason, when I attempt to browse to phpmyadmin
I am redirected to
http://localhost:8081/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/https:--localhost/phpmyadmin/
I am sure where to look and the only thing I can think of is that I was trying to add a free SSL certificate to my localhost but it never worked.
This is my current settings.
httpd.conf
Listen 8081
ServerName localhost:8081
httpd-ssl.conf
Listen 8081
ServerName localhost:8081
<VirtualHost _default_:8081>
# General setup for the virtual host
DocumentRoot "C:/xampp/htdocs"
#ServerName www.example.com:8081
ServerName localhost:8081
With the code above I get endless redirections
but changing it to
Listen 4433
ServerName localhost:4433
<VirtualHost _default_:4433>
# General setup for the virtual host
DocumentRoot "C:/xampp/htdocs"
ServerName localhost:4433
doesnt let my apache server start.
Appreciate it if I could get any insight regarding this.
REgards
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
I’m having a hard time getting multiple sites working with MAMP using Virtual hosts. Below is what I have set up on my MBA. If I open up my web browser and go to "http:local.login.dev" or "http://dev.login.localhost" (after reconfigure) I get the index page that’s saved in /Users/aaron/localhost. First item listed in my Virtual hosts section Not the index page saved in the Virtual Host I want to get to. Other sites I have setup give me the same result.. "http:next.site.localhost" = displays the index page in /Users/aaron/localhost.
Does anybody have any thoughts? My final goal is to configure MAMP Virtual hosts to work and test with SSL.
Bottom line is it seems like ONLY the first Virtual host entry is read and that's whats used for every host listed. Am I missing some setting somewhere??
Environment:
- MBA with OS X, Yosemite
MAMP 3.0.7.3 using ports 80, and 3306 for http and mysql respectively
httpd.conf File:
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
127.0.0.1 localhost
127.0.0.1 local.login.dev
<VirtualHost *>
DocumentRoot "/Users/aaron/localhost"
ServerName localhost
</VirtualHost>
<VirtualHost *:80> — I tried both with and without :80
DocumentRoot "/Users/aaron/localhost/training/login/public"
ServerName local.login.dev
</VirtualHost>
Also tried configuring my hosts and httpd-vhosts.conf this way - From another post:
127.0.0.1 localhost
127.0.0.1 dev.login.localhost
<VirtualHost *>
DocumentRoot "/Users/aaron/localhost"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/aaron/localhost/training/login/public"
ServerName dev.login.localhost
ServerAlias dev.login.localhost
<Directory "/Users/aaron/localhost/training/login/public">
Allow from All
AllowOverride all
Options -Indexes +FollowSymlinks
</Directory>
</VirtualHost>
Just playing around more I commented out the first "Localhost" in my httpd-vhosts.conf file and looks like I can now navigate to my local sites correctly. Below is what I currently have configed..
httpd-vhosts.conf:
# <VirtualHost *>
# DocumentRoot "/Users/aaron/localhost/"
# ServerName localhost
# </VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/aaron/localhost/training/login/public"
ServerName dev.login.localhost
ServerAlias dev.login.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/aaron/localhost/site1"
ServerName dev.site1.localhost
ServerAlias dev.site1.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/aaron/localhost/site2"
ServerName dev.site2.localhost
ServerAlias dev.site2.localhost
</VirtualHost>
Hosts File:
127.0.0.1 localhost
######Locahost Dev Sites
127.0.0.1 dev.login.localhost dev.site1.localhost dev.site2.localhost
Now to see if I can get SSL working.
If any of this is incorrect, please let me know... but this config is the only way I can get the Virtual hosts working, as of now, using port 80... If I have issues mixing with 443 I'll update
I managed to install ssl on wamp, and it seems to run nicely. However, by default I used url-rewritten apps where I had to set the main server url to
http://127.0.0.1:8080
The problem is I can only run ssl on port 443, here is my httpd listen:
Listen 127.0.0.1:8080
And virtualhost
<VirtualHost _default_:443>
# General setup for the virtual host
DocumentRoot "C:/wamp/www/"
ServerName 127.0.0.1:443
ServerAdmin admin#example.com
ErrorLog "logs/sslerror_log"
TransferLog "logs/sslaccess_log"
I tried adding 8080 here, but no luck
Any idea?