HTTPS in Ubuntu PC localhost with OpenSSL is more easier to set up than on Windows PC with WAMP. All you want is to install Apache2 and some knowledge on SSL. If you are looking for HTTPS in WAMP Server on Windows PC, then read this guide instead. For setup of HTTPS in Ubuntu PC localhost with OpenSSL, you need basic LAMP set up.
HTTPS in Ubuntu PC localhost with OpenSSL : Basic Setup
Only follow these steps for the set up of HTTPS in Ubuntu PC localhost with OpenSSL if you have not installed Apache. A simple command will install Apache2 :
1 | sudo apt-get install apache2 |
Open your browser and point to either localhost or your fixed static IP :
---
1 | http://localhost/ |
You will see the default Apache2 message – It Works!
If you need full LAMP server setup, run this command instead :
1 | sudo apt-get install lamp-server^ |
HTTPS in Ubuntu PC localhost with OpenSSL : The Steps for SSL
OpenSSL comes as default package with Apache2 in case of Ubuntu. You need not to install it separately. First enable SSL :
1 | sudo a2enmod ssl |
Then force restart Apache2 :
1 | sudo /etc/init.d/apache2 force-reload |
And create server key (note two commands are separate) :
1 2 3 | cd /etc/apache2 sudo openssl genrsa -des3 -out server.key 1024 |
If above last command gives error later, try this command :
1 | sudo openssl genrsa -out server.key 1024 |
Run this command for certificate request :
1 | sudo openssl req -new -key server.key -out server.csr |

Create a self signed certificate :
1 | sudo openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt |
Install them (note there are two separate commands) :
sudo cp server.crt /etc/ssl/certs/
sudo cp server.key /etc/ssl/private/
Go to :
1 | cd /etc/apache2/sites-available |
And open the needed file in graphical Gedit :
gksudo gedit default-ssl
Find and comment out three lines :
SSLEngine on
SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
Enable SSL, go to root to run this command :
1 | sudo a2ensite default-ssl |
Actually if you restart Apache2, it should work, but this adds a bit error in the auto config of httpd. So you might need to edit :
1 | gksudo gedit httpd.conf |
This step should normally enable https on your localhost.
Tagged With ssl for localhost ubuntu , openssl ubuntu 18 SSL_CTX_use_certificate , sudo cp server crt /etc/ssl/certs sudo cp server key /etc/ssl/private , ubuntu https at localhost?