W3docs

Setting up SSL on a local xampp/apache server

To set up SSL on a local XAMPP/Apache server, you will need to generate a self-signed certificate, configure the Apache server to use the certificate, and then access the server using https.

To set up SSL on a local XAMPP/Apache server, you will need to generate a self-signed certificate, configure the Apache server to use the certificate, and then access the server using https. Here are the general steps:

  1. Generate a self-signed certificate: You can use the OpenSSL tool to generate a self-signed certificate. Run the following command in Git Bash (included with XAMPP) or a compatible shell:

Example of using the OpenSSL tool to generate a self-signed certificate

openssl req -x509 -out localhost.crt -keyout localhost.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj '/CN=localhost'

(Note: Adding Subject Alternative Names requires a separate configuration file.)

  1. Configure the Apache server to use the certificate: In the Apache configuration file (httpd.conf), ensure the SSL module is enabled by uncommenting LoadModule ssl_module modules/mod_ssl.so. You can also include XAMPP's pre-configured httpd-ssl.conf file located in apache/conf/extra/ instead of manually adding the VirtualHost block. If configuring manually, add the following lines:

Example of configuring the Apache server to use a self-signed certificate

Listen 443

<VirtualHost _default_:443>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
    SSLEngine on
    SSLCertificateFile "C:/xampp/ssl/localhost.crt"
    SSLCertificateKeyFile "C:/xampp/ssl/localhost.key"
</VirtualHost>
  1. Restart the Apache server and access the server using https:

Example of restarting the Apache server and accessing the server using HTTPS

httpd.exe -k restart

Now you should be able to access your local server using https.

Note: This is just a simple example, for production, you will want to use a CA-signed certificate and configure Apache accordingly.

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>