Learn how to set up a local SSL certificate on Apache with this comprehensive step-by-step guide. Secure your local development environment with HTTPS.
/etc/apache2/
on Linux or C:\Apache24\
on Windows).
openssl genrsa -out localhost.key 2048
openssl req -new -key localhost.key -out localhost.csr
Enter your details when prompted. For "Common Name," use localhost
.
openssl x509 -req -days 365 -in localhost.csr -signkey localhost.key -out localhost.crt
httpd.conf
or apache2.conf
, depending on your installation.
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf
httpd-ssl.conf
file (found in conf/extra/
or a similar directory).
<VirtualHost _default_:443>
DocumentRoot "your/document/root"
ServerName localhost:443
SSLEngine on
SSLCertificateFile "path/to/localhost.crt"
SSLCertificateKeyFile "path/to/localhost.key"
<Directory "your/document/root">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Replace "your/document/root"
with the path to your web root directory and "path/to/localhost.crt"
and "path/to/localhost.key"
with the actual paths to your generated certificate and key files.
C:\Windows\System32\drivers\etc\hosts
/etc/hosts
127.0.0.1 localhost
httpd -k restart
sudo systemctl restart apache2
https://localhost
.By following these steps, you have successfully set up a local SSL certificate on Apache, providing a secure development environment for your local projects. This setup is essential for developing and testing applications that require secure connections.
Published By: Krishanu Jadiya
Updated at: 2024-07-17 18:05:11