37

My question may be stupid, But honestly I searched a lot and got success but not complete.

I use xampp with windows 8.

My host file looks as follows.

    127.0.0.1   localhost
    127.0.0.1   www.mysite.com

My httpd-vhosts.config looks as follows.

    NameVirtualHost 127.0.0.1
    <VirtualHost 127.0.0.1>
        DocumentRoot "C:/xampp/htdocs"
        ServerName localhost
    </VirtualHost>
    <VirtualHost 127.0.0.1>
        ServerName www.mysite.com
        ServerAlias mysite.com
        DocumentRoot "C:/xampp/htdocs/mysite"
    </VirtualHost>

This works perfect for http. But I have enabled ssl.

When I type http://localhost or https://localhost, Both work fine.

When I type http://mysite.com it works,

when I type https://mysite.com it is redirected as https://mysite.com/xampp/ and shows me default welcome page of xampp.

I tried following things.

1) instead of using 127.0.0.1, I tried using *:80 in httpd-vhosts.conf But result was same.

2) instead of using 127.0.0.1, I tried using *:443 in httpd-vhosts.conf But at the time of restarting apache fails to start again.

Please let me know how can I access my site through domain name instead of localhost with https or http.

swapnesh
  • 26,318
  • 22
  • 94
  • 126
Jeet Chaudhari
  • 760
  • 1
  • 8
  • 14
  • 1
    try to uncomment extension=php_openssl.dll in php.ini and restart apache – Rakesh Sharma Apr 26 '13 at 05:10
  • the line you have mentioned is already uncommented, that's why I can use my other sites in https by https:/ /localhost/othersite/ Should I comment restart, and later again uncomment and restart? – Jeet Chaudhari Apr 26 '13 at 05:17
  • possibly need apache support too, uncomment #LoadModule ssl_module modules/mod_ssl.so in xampp/apache/conf/httpd.conf – shapeshifter Apr 26 '13 at 05:17
  • @shapeshifter the file you mentioned is already uncommented. – Jeet Chaudhari Apr 26 '13 at 05:20
  • @JeetChaudhari Have you added exception in Windows Firewall for port – swapnesh Apr 26 '13 at 05:30
  • @JeetChaudhari Also you can check these two links http://wiki.apache.org/httpd/DebuggingSSLProblems#Debugging_SSL_Problems & http://rubayathasan.com/tutorial/apache-ssl-on-windows/ & http://www.digicert.com/ssl-support/apache-fix-common-ssl-errors.htm – swapnesh Apr 26 '13 at 05:31
  • @JeetChaudhari let me know what you tried out of this..so that I can assist you further – swapnesh Apr 26 '13 at 05:34
  • check this http://sawmac.com/xampp/virtualhosts/ – RavatSinh Sisodiya Apr 26 '13 at 05:43
  • @swapnesh I checked the links, it shows how to create certificate, but honestly I have done nothing like that, I don't remember now where I saw post about enabling the https, but it wasn't having any instructions about how to create certificate and sign, I just uncommented LoadModule ssl_module modules/mod-sso.so in httpd.conf So I can browse the https on my localhost but it shows that certificate error, means red colored address bar. Does this creating problem? also will it be ok if I follow steps provided in link given by you now? – Jeet Chaudhari Apr 26 '13 at 05:45
  • @JeetChaudhari have you checked error logs..at times they are really beneficial..let me know..one thing more to check SSL error google provide a developer tool(but i haven't used it yet) ? – swapnesh Apr 26 '13 at 05:48
  • @swapnesh I have found this error in apache logs [ssl:warn] [pid 9664:tid 320] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache] How can we configure SSLSessionCache – Jeet Chaudhari Apr 26 '13 at 06:05
  • Hey @swapnesh I found the answer, it was simply I acted stupidly. I just need to post answer here so that noone else will spend this much time on this. though I have solved my issue, still I have some more questions in my mind. should I edit my question or simply click on answer my own question? sorry but I am newto this site, this was my 1st question. – Jeet Chaudhari Apr 26 '13 at 06:11
  • @JeetChaudhari what was that ..let me know – swapnesh Apr 26 '13 at 06:13
  • I edited the comment, please once again check my previous comment. – Jeet Chaudhari Apr 26 '13 at 06:14
  • @JeetChaudhari For this particular question create an answer..then post another question with you doubts – swapnesh Apr 26 '13 at 06:15
  • There is no such thing as stupid question. – Traveling Salesman Nov 05 '13 at 17:23

6 Answers6

28

I tried many things, But I think I missed basic edit.

Now all working fine.

Now host file is still the same as mentioned in question. I did not make any changes to it.

I changed port in httpd-vhosts.config as shows below.

NameVirtualHost *
    <VirtualHost *>
        DocumentRoot "C:/xampp/htdocs"
        ServerName localhost
    </VirtualHost>
    <VirtualHost *>
        ServerName www.mysite.com
        ServerAlias mysite.com
        DocumentRoot "C:/xampp/htdocs/mysite"
    </VirtualHost>

Also the step I missed, was editing httpd-ssl.config file in same folder that of httpd-vhosts.config.

I just added following lines before last line of http-ssl.config file i.e. < /IfModule>

<VirtualHost _default_:443> 
    DocumentRoot "C:/xampp/htdocs/mysite" 
    ServerName www.mysite.com:443 
    ServerAlias mysite.com:443  
    SSLEngine on 
    SSLCertificateFile "conf/ssl.crt/server.crt" 
    SSLCertificateKeyFile "conf/ssl.key/server.key" 
</VirtualHost> 

Thank You all friends for helping me lot on this, Without your links I would never ever be able to find out that I need to edit one more file.

Jeet Chaudhari
  • 760
  • 1
  • 8
  • 14
17

Let me explain step by step for other guys too.

1. Map your custom domain name to localhost in HOSTS file.

Where to usually find the hosts file:

  • Unix (Linux,Mac): /etc/hosts.
  • Windows: C:\Windows\System32\drivers\etc\hosts

Open hosts file and add below line.

127.0.0.1 www.example.com

2. Tell XAMPP about your custom domain.

Add below content to httpd-vhosts.conf

<VirtualHost *>
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot "C:/xampp/htdocs/example"
</VirtualHost>

If you have port for your localhost, then add it as <VirtualHost *:80>

Restart apache,Now you can access http://example.com in your browser.


3. If you want to access https://example.com

Add below line to httpd-vhosts.conf

<VirtualHost *:443>
    DocumentRoot "C:/xampp/htdocs/example"
    ServerName www.example.com
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
    <Directory "C:/xampp/htdocs/example">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Anurag Prashant
  • 995
  • 10
  • 31
1

I have been googling for hours trying to figure out why the newest XAMPP release puts 1200MS on page generation times... I thought it was maybe my code working with some pretty complex class systems yet.. this thread pointed out the whole localhost <> 127.0.0.1

I'm on Windows 7 and I didn't think to use CMD to "ping localhost"

the result was "::1:" not 127.0.0.1

After a quick windows/system32/drivers/etc/host file edit to uncomment out the line

127.0.0.0 localhost

My page times went back to normal. Might be someone else is having this problem recently and seeing as this thread ranks top in Google then good luck!

FaTe
  • 155
  • 3
  • 11
1

I started with multiple custom domains. See new code below:

Note: WordPress strips backslashes, so below I’ve replaced them with forward slashes. I believe it with work regardless either way.

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/Users/Austin Passy/Documents/InMotion Hosting/frostywebdev.com/html"
    ServerName frostyweb.dev
    <Directory "C:/Users/Austin Passy/Documents/InMotion Hosting/frostywebdev.com/html">
    Options Indexes FollowSymLinks ExecCGI Includes
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/eateryengine"
    ServerName eateryengine.dev
    <Directory "C:/xampp/htdocs/eateryengine">
    Options Indexes FollowSymLinks ExecCGI Includes
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
Xman Classical
  • 5,179
  • 1
  • 26
  • 26
0

I'm not too familiar with apache but perhaps not specifying a port defaults to :80 and adding this would magically fix everything?

<VirtualHost 127.0.0.1:443>
    ServerName www.mysite.com
    ServerAlias mysite.com
    DocumentRoot "C:/xampp/htdocs/mysite"
</VirtualHost>
Insensus
  • 66
  • 5
  • This made apache server fail to start. error log shows. [Fri Apr 26 10:06:38.323550 2013] [ssl:warn] [pid 7892:tid 324] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache] – Jeet Chaudhari Apr 26 '13 at 05:24
-1

I use my own domains (ended with .lc) for development web application on localhost. I will describe simple solution for dynamic .lc domains and development enviroment that works without dependency on internet connection.

I wrote about it on my blog too: http://www.michalseidler.com/development/localhost-development-enviromet-for-php/

For this example i try describe configuration of local dynamic domains *.lc with Wamp Server. I have my projects stored in C:\wamp\www\projects\projectname\ and i use dynamic maping projectname.lc. This means that i can access every project directory with domain [project direktory name].lc

Step 1 – configuration of local WAMP server

First of all you need place configuration of *.lc domain into httpd.conf:

<VirtualHost 127.0.0.1>
ServerName lc
ServerAlias *.lc
DocumentRoot "C:\wamp\www\projects"
</VirtualHost>;

You need insert .htaccess file into projects direktory (in my example into: C:\wamp\www\projects) this configuration maps *.ls domains to project direktories. Ex.: If you have sources in direktory ‚myapp‘ you can use www.myapp.lc to open it in browser.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^\.]*)\.([^\.]*)$
RewriteRule (.*) http://www.%1.%2/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.([^.]+)\.([^\.]*)$ [NC]
RewriteRule ^(.*)$ http://%1.%2.%3/$1 [L,R=301]

RewriteCond %{REQUEST_URI} !^projects/
RewriteCond %{REQUEST_URI} !^/projects/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteRule (.*) %3/$1 [DPI] 

After this changes restart Wamp Server

Step 2 – configuration of local DNS server

Because we can’t use *.lc in Windows host file we need instal local DNS server. I choose Acrylic DNS Server because it is very simple for configuration.

After instalation find AcrylicHosts file (C:\Program Files (x86)\Acrylic DNS Proxy) and insert new line:

127.0.0.1 *.lc

This is only DNS configuration we need so restart Acrylic DNS service.

Step 3 – configuration of network adapter

Final step is install new fake network adapter and assign DNS server: 1.Click the Start menu. 2.Search for “cmd“. 3.Right-click on “cmd” and select “Run as Administrator” 4.Enter “hdwwiz.exe” 5.In the „Welcome to the Add Hardware Wizard“, click Next. 6.Select „Install the hardware that I manually select from a list (Advanced)“ and click Next. 7.Scroll down and select „Network adapters“ and click Next. 8.Select under Manufacturer „Microsoft“ and then under Network Adapter „Microsoft Loopback Adapter“ and click Next.

In next step you must change TCP/IP settings of new created adapter: 1.Log on to the computer by using the Administrator account. 2.Click Start, point to Control Panel, and click Network Connections. 3.Right-click the Loopback connection and then click Properties. 4.In the This connection uses the following items box, click Internet Protocol (TCP/IP), and then click Properties. The Internet Protocol (TCP/IP) Properties dialog box appears.

IP addess: 192.168.1.1
Subnet mask: 255.255.255.0
Default Gateway: empty

Prefered DNS server: 127.0.0.1

Now close all dialogs and its done! You can try open [your project name].lc