Setting up SSL on a local xampp/apache server
Apache part - enabling you to open https://localhost/xyz
There is the config file xampp/apache/conf/extra/httpd-ssl.conf which contains all the ssl specific configuration. It's fairly well documented, so have a read of the comments and take look at http://httpd.apache.org/docs/2.2/ssl/.
The files starts with <IfModule ssl_module>
, so it only has an effect if the apache has been started with its mod_ssl module.
Open the file xampp/apache/conf/httpd.conf in an editor and search for the line
#LoadModule ssl_module modules/mod_ssl.so
remove the hashmark, save the file and re-start the apache. The webserver should now start with xampp's basic/default ssl confguration; good enough for testing but you might want to read up a bit more about mod_ssl in the apache documentation.
PHP part - enabling adldap to use ldap over ssl
adldap needs php's openssl extension to use "ldap over ssl" connections. The openssl extension ships as a dll with xampp. You must "tell" php to load this dll, e.g. by having an extension=nameofmodule.dll
in your php.ini
Run
echo 'ini: ', get_cfg_var('cfg_file_path');
It should show you which ini file your php installation uses (may differ between the php-apache-module and the php-cli version).
Open this file in an editor and search for
;extension=php_openssl.dll
remove the semicolon, save the file and re-start the apache.
see also: http://docs.php.net/install.windows.extensions
How to Create Valid SSL in localhost for XAMPP
In my XAMPP install I basically have a clone to all the site that I managed. And All of them (of course) use SSL/HTTPS.
Here’s the step by step guide:
In this step we are going to crate SSL
and setup “site.test” website.
1. Navigate to Apache directory in XAMPP.
In regular install it’s in C:\xampp\apache.
2. Create a folder in that page.
This is where we will store our cert. In this example I will create “crt” folder. So we will have C:\xampp\apache\crt
3. Add this files.
cert.conf
make-cert.bat
4. Edit cert.conf and Run make-cert.bat
Change {{DOMAIN}} text using the domain we want to use, in this case site.test and save.
Double click the make-cert.bat and input the domain site.test when prompted. And just do enter in other question since we already set the default from cert.conf.
Note: I don’t know how to do text replace in .bat script, if you do, let me know in the comment how to do it and I will update make-cert.bat to automatically replace the {{DOMAIN}} with the domain input.
5. Install the cert in windows.
After that, you will see site.test folder created. In that folder we will have server.crt and server.key. This is our SSL certificate.
Double click on the server.crt to install it on Windows so Windows can trust it.
And then select Local Machine as Store Location.
And then Select “Place all certificate in the following store” and click browse and select Trusted Root Certification Authorities.
Click Next and Finish.
And now this cert is installed and trusted in Windows. Next is how how to use this cert in XAMPP.
6. Add the site in Windows hosts
- Open notepad as administrator.
- Edit
C:\Windows\System32\drivers\etc\hosts
(the file have no ext) - Add this in a new line:
127.0.0.1 site.test
This will tell windows to load XAMPP when we visit http://site.test
You can try and it will show XAMPP dashboard page.
7. Add the site in XAMPP conf.
We need to enable SSL for this domain and let XAMPP know where we store the SSL Cert. So we need to edit C:\xampp\apache\conf\extra\httpd-xampp.conf
And add this code at the bottom:
## site.test
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName site.test
ServerAlias *.site.test
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "C:/xampp/htdocs"
ServerName site.test
ServerAlias *.site.test
SSLEngine on
SSLCertificateFile "crt/site.test/server.crt"
SSLCertificateKeyFile "crt/site.test/server.key"
</VirtualHost>
After that, you will need to restart Apache in XAMPP. It’s very simple, simply open XAMPP Control Panel and Stop and re-Start Apache Module.
Tips: In XAMPP conf, as you can see you can change the domain root directory if needed. Eg. as sub-dir in htdocs.
8. Restart your browser and Done!
This is required to load the certificate. And visit the domain on your browser, and you will see green lock!
I hope this tutorial is useful!
Source: https://shellcreeper.com/how-to-create-valid-ssl-in-localhost-for-xampp/
Enabling SSL with XAMPP
Found the answer. In the file xampp\apache\conf\extra\httpd-ssl.conf
, under the comment SSL Virtual Host Context
pages on port 443 meaning https is looked up under different document root.
Simply change the document root to the same one and problem is fixed.
How do I use https (SSL) in XAMPP while using virtual hosts
SSL, of the HTTPS://url.here/
variety, is entirely handled by Apache and has nothing to do with PHP, or any of PHP's extensions/modules, or any php.ini settings.
A typical SSL Enabled VirtualHost looks like this and contains at least these parts...
<VirtualHost *:443>
DocumentRoot "C:/WampDeveloper/Websites/www.example.com/webroot"
ServerName www.example.com
ServerAlias example.com
SSLEngine On
SSLCertificateFile "C:/WampDeveloper/Websites/www.example.com/certs/public.crt"
SSLCertificateKeyFile "C:/WampDeveloper/Websites/www.example.com/certs/private.key"
<Directory "C:/WampDeveloper/Websites/www.example.com/webroot">
Options All
AllowOverride All
order allow,deny
allow from all
</Directory>
</VirtualHost>
(The paths above are from my WampDeveloper Pro set up, Xampp's will be slightly different)
Your <VirtualHost *>
line is faulty. It needs a port number, which is always 443 for an HTTPS:// URL, in combination with either an IP address or a star before it. And if using a star, also a NameVirtualHost *:443
line...
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "C:\Users\user_name\Documents\project_one"
ServerName project_one.localhost
SSLEngine on
SSLCertificateFile "conf/ssl.crt/server.crt"
SSLCertificateKeyFile "conf/ssl.key/server.key"
<Directory "C:\Users\user_name\Documents\project_one">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\user_name\Documents\project_two"
ServerName project_two.localhost
<Directory "C:\Users\user_name\Documents\project_two">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
SSL on Xampp Localhost using VirtualHost on Windows redirects to Xampp default info/localhost page
SOLVED:
Seems like the configuration above was correct, but I didn't realize one thing, and I had to include some further configuration to make it work. Explained below:
Typing "q.localhost" in URL window failed, and redirected to the Xampp default page. Had to include https:// before the url, so typing in "https://q.localhost" brought up the correct page. However, clicking on the various other links on the website also failed, as it required, but did not have the "https://..." in front of the link.
To correct the above problem, I referred to this article. which suggested adding redirects to configuration file: \xampp\apache\conf\extra\httpd-xampp.conf. I added what he suggested to enable automatic redirects without having to always type in "https://..."
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect /xampp folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} xampp
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /phpMyAdmin folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} phpmyadmin
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /security folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} security
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /webalizer folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} webalizer
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /folder_name folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} folder_name
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]</IfModule>
Related Topics
Finding the Minimum Value's Key in an Associative Array
Delete First 3 Characters and Last 3 Characters from String PHP
PHP Printed Boolean Value Is Empty, Why
How to Create a Subquery Using Laravel Eloquent
PHP Date() in Foreign Languages - E.G. Mar 25 Aoû 09
Difference Between PHP Echo and Return in Terms of a Jquery Ajax Call
Differencebetween {{ }} and {!! !!} in Laravel Blade Files
MySQL Performance - "In" Clause VS. Equals (=) for a Single Value
Highlight the Word in the String, If It Contains the Keyword
Setting Up Ssl on a Local Xampp/Apache Server
Passing Multiple PHP Variables to Shell_Exec()
Best Method for Sum Two Arrays
How to Use Array_Push on a Session Array in PHP
Php: Best Way to Check If Input Is a Valid Number
C#'s Null Coalescing Operator () in PHP
Type-Juggling and (Strict) Greater/Lesser-Than Comparisons in PHP