XAMPP virtual host to HTTPS | SSL cert on XAMPP | HTTPS on localhost

0

Localhost (HTTPS) certificate on your Webserver XAMPP Working 100%

1. Create important files

Go to apache folder then create a folder name what ever you want but to easy to notice you should create it name "cert"
 
Then go inside the cert folder and create two files below:

makecert.bat (put this content and save)

@echo off
set /p domain="Enter Domain: "
set OPENSSL_CONF=../conf/openssl.cnf

if not exist .\%domain% mkdir .\%domain%

..\bin\openssl req -config cert.conf -new -sha256 
-newkey rsa:2048 -nodes -keyout %domain%\server.key -x509 
-days 365 -out %domain%\server.crt

echo.
echo -----
echo The certificate was provided.
echo.
pause

cert.conf (put this content and change laravelpro.local to your domain name and save)

[ req ]

default_bits        = 2048
default_keyfile     = server-key.pem
distinguished_name  = subject
req_extensions      = req_ext
x509_extensions     = x509_ext
string_mask         = utf8only

[ subject ]

countryName                 = Country Name (2 letter code)
countryName_default         = US

stateOrProvinceName         = State or Province Name (full name)
stateOrProvinceName_default = NY

localityName                = Locality Name (eg, city)
localityName_default        = New York

organizationName            = Organization Name (eg, company)
organizationName_default    = Example, LLC

commonName                  = Common Name (e.g. server FQDN or YOUR name)
commonName_default          = laravelpro.local

emailAddress                = Email Address
emailAddress_default        = test@example.com

[ x509_ext ]

subjectKeyIdentifier   = hash
authorityKeyIdentifier = keyid,issuer

basicConstraints       = CA:FALSE
keyUsage               = digitalSignature, keyEncipherment
subjectAltName         = @alternate_names
nsComment              = "OpenSSL Generated Certificate"

[ req_ext ]

subjectKeyIdentifier = hash

basicConstraints     = CA:FALSE
keyUsage             = digitalSignature, keyEncipherment
subjectAltName       = @alternate_names
nsComment            = "OpenSSL Generated Certificate"

[ alternate_names ]

DNS.1       = laravelpro.local

2. Generate cert

Double click to run makecert.bat and fill your domain info (Enter your domain name on Common Name)

After done this you will have a cert folder that its name is your domain name
And inside this folder you can see two files has been generated (server.crt, server.key)

3. Install server.crt 

Double click on it then click on install certificate

4. Create and config virtual host

Edit file httpd-vhosts.conf from folder (apache\conf\extra) and input following text and replace ServerName, DocumentRoot, Directory to your domain

Example:

<VirtualHost *:80>
    DocumentRoot "S:\Laravels\Projects\laravelPro\public"
    ServerName laravelPro.local
    <Directory "S:\Laravels\Projects\laravelPro\public">
       Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order Deny,Allow
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:443>
    DocumentRoot "S:\Laravels\Projects\laravelPro\public"
    ServerName laravelPro.local
    SSLEngine On
    SSLCertificateFile "D:\XAMPP\apache\cert\laravelpro.local\server.crt"
    SSLCertificateKeyFile "D:\XAMPP\apache\cert\laravelpro.local\server.key"
    <Directory "S:\Laravels\Projects\laravelPro\public">
       Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order Deny,Allow
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>  



Add your server name to hosts. Go to (C:\Windows\System32\drivers\etc) then you can see file hosts. Edit and add your server/domain name. 
Example 

Notice: to save hosts file you need to save it as Administrator 
 

Now everything are done please restart your apache and try https

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)

Random Posts