Skip to content

Instantly share code, notes, and snippets.

@obviousdisaster
Last active February 17, 2023 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obviousdisaster/1e549ab3001ea5a4460f4394de5bbdbf to your computer and use it in GitHub Desktop.
Save obviousdisaster/1e549ab3001ea5a4460f4394de5bbdbf to your computer and use it in GitHub Desktop.
Set up SSL certs for local development. Only method that's worked for me. Tested on Ubuntu v20.x
#
# my default apache ssl conf, playground.test is the local site
#
Define servername playground.test
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
ServerName ${servername}
DocumentRoot /var/www/html/${servername}
<Directory "/var/www/html/${servername}">
Order allow,deny
Allow from all
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/${servername}-ssl-error.log
CustomLog ${APACHE_LOG_DIR}/${servername}-ssl-access.log combined
SSLEngine on
SSLCertificateFile /home/markhall/ssl-certs/${servername}.pem
SSLCertificateKeyFile /home/markhall/ssl-certs/${servername}-key.pem
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>
#
# my default apache non-ssl conf, playground.test is the local site
#
Define servername playground.test
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName ${servername}
DocumentRoot /var/www/html/${servername}
ErrorLog ${APACHE_LOG_DIR}/${servername}-error.log
CustomLog ${APACHE_LOG_DIR}/${servername}-access.log combined
<Directory /var/www/html/${servername}>
DirectoryIndex index.php index.html
</Directory>
</VirtualHost>
# store all ssl's in home
mkdir $HOME/ssl-certs
cd ~/ssl-certs
mkcert -install
# playground.test is our test site
mkcert playground.test
# apache conf files
cd /etc/apache2/sites-available/
# create playground.test.conf
# create playground.test.ssl.conf
# edit hosts file with new local site
sudo /etc/hosts
# add line
127.0.0.1 playground.test
# enable the site in apache
sudo a2ensite playground.test.*
# reboot apache
sudo systemctl reload apache2
@obviousdisaster
Copy link
Author

Updated mkcert as it's part of PopOS install, no need from brew install.

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