Skip to content

Instantly share code, notes, and snippets.

@LeonSkrilec
Last active December 30, 2022 11:20
Show Gist options
  • Save LeonSkrilec/28f6d8d6e020ac8fe4140e018c967e7f to your computer and use it in GitHub Desktop.
Save LeonSkrilec/28f6d8d6e020ac8fe4140e018c967e7f to your computer and use it in GitHub Desktop.
How to create working SSL certificate for XAMPP virtual hosts on Windows

How to create working self signed certificate for custom virtual hosts on Windows

Step by step tutorial how to create working self signed SSL certificate for XAMPP apache server on Windows (Even working in chrome version > 58)

Prerequisites

You have to have OpenSSL installed and in your system PATH for this to be working.

You can download OpenSSL binary here. Just extract contents in some directory - I put mine in C:/OpenSSL Than add OpenSSL executable in your PATH. How to add folders to PATH in windows?

Enable mod_ssl

Make sure that there is following line and that is not commented (# in front) in {your_xampp_installation_path}/XAMPP/apache/conf/httpd.conf: LoadModule ssl_module modules/mod_ssl.so

Created certificate will be working for local domain example.test. Make sure to change values to your own virtual host name.

Step 1

Add your virtual host config in {your_xampp_installation_path}/XAMPP/apache/conf/extra/httpd-vhosts.conf. Make sure to restart your apache server afterwards.

<VirtualHost *:443>
    DocumentRoot "{your_xampp_installation_path}/XAMPP/htdocs/{your_host_root}"
    ServerName www.example.test
    ServerAlias example.test
    SSLEngine On
    SSLCertificateFile "{your_xampp_installation_path}/XAMPP/apache/conf/ssl.crt/example.crt"
    SSLCertificateKeyFile "{your_xampp_installation_path}/XAMPP/apache/conf/ssl.key/example.key"  
    <Directory "{your_xampp_installation_path}/XAMPP/htdocs/{your_host_root}">
        Options All
        AllowOverride All
        order allow,deny
        allow from all
    </Directory>
</VirtualHost>

Step 2

Create new .bat script in folder {your_xampp_installation_path}/XAMPP/apache/conf with this code. Then run this script by duble clicking on it.

@echo off
REM IN YOUR SSL FOLDER, SAVE THIS FILE AS: makeCERT.bat
REM AT COMMAND LINE IN YOUR SSL FOLDER, RUN: makecert
REM IT WILL CREATE THESE FILES: example.cnf, example.crt, example.key
REM IMPORT THE .crt FILE INTO CHROME Trusted Root Certification Authorities
REM REMEMBER TO RESTART APACHE OR NGINX AFTER YOU CONFIGURE FOR THESE FILES
REM PLEASE UPDATE THE FOLLOWING VARIABLES FOR YOUR NEEDS.
SET HOSTNAME=example
SET DOT=test
SET COUNTRY=SI
SET STATE=Slovenia
SET CITY=Ljubljana
SET ORGANIZATION=IT
SET ORGANIZATION_UNIT=IT Department
SET EMAIL=webmaster@%HOSTNAME%.%DOT%

(
echo [req]
echo default_bits = 2048
echo prompt = no
echo default_md = sha256
echo x509_extensions = v3_req
echo distinguished_name = dn
echo:
echo [dn]
echo C = %COUNTRY%
echo ST = %STATE%
echo L = %CITY%
echo O = %ORGANIZATION%
echo OU = %ORGANIZATION_UNIT%
echo emailAddress = %EMAIL%
echo CN = %HOSTNAME%.%DOT%
echo:
echo [v3_req]
echo subjectAltName = @alt_names
echo:
echo [alt_names]
echo DNS.1 = *.%HOSTNAME%.%DOT%
echo DNS.2 = %HOSTNAME%.%DOT%
)>%HOSTNAME%.cnf
openssl req -new -x509 -newkey rsa:2048 -sha256 -nodes -keyout %HOSTNAME%.key -days 3560 -out %HOSTNAME%.crt -config %HOSTNAME%.cnf

Step 3

Add certificate to chrome trusted authorities. Go to Settings -> Manage Certificates -> Import Than select generated certificate in previous step. Should be located in {your_xampp_installation_path}/XAMPP/apache/conf/example.crt In the field "Place all certificates in the following store:" select "Trusted root certification authorities".

Step 4

Visit https://example.test and celebrate the green lock in browser's address bar :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment