Enable SSL for apache server in 5 minutes

This post describe how to quickly enable SSL for apache web server under linux. This has been done on a clouded virtual machine, the Linux distribution is Ubuntu 12.04 LTS Server, the one provided by Amazon Aws or Microsoft Azure. This procedure may not work or may differ on older or different distribution.

What need to be in place ?

You need to already have apache server running on http port 80 (or whatever) and when you try to go to your website for example http://demo.hallard.me you should have the well know page

It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

Once this is ok, just go to your server with ssh

What do to ?

Ok let’s start where we will put the certificates (in /etc/apache2/ssl)

now we generate the certicates, for 3 years (1095 days) under the folder we created above.

that will show the following, and ask you some questions.

The most important, is the Common Name, it should match the internet name FQDN (here demo.hallard.me)

Now we install the SSL mod for apache, this instruction pre configure the file /etc/apache2/ports.conf with some line and the important one that say Listen 443

We put the default-ssl site available creating a symbolic link

Now we edit the file default-ssl (or default-ssl.conf for new version) we have just enabled

Edit October 2014 : on new apache2 version, configuration files need to have .conf extension, so in this case the two previous commands are now :

End of Edit

and we change the two lines relative to SSLCertificate as follow :

Now restart apache server

now you can go with your favorite browser, in my example https://demo.hallard.me, the browser will warn you because it is a self signed certificate, but if you accept it you will now have the same famous “It works!” but with encryption. To avoid warning by browser, you can add the certificate to Trusted Root Certificate Authority of your computer. The procedure to to this depends on browser and operating system, so google is your friend.

Now it is safe that you force SSL encryption on each page that require authentication.

For example, for WordPress, add the following two lines (just after the other existing define lines in the file wp-config.php (located in wordpress installation dir)

This will force each login to use SSL and all admin site to use SSL

You can do the same for phpmyadmin adding to the file /etc/phpmyadmin/config.inc.php





  1. Excellent blog, thanks it worked with me. Just one thing, I
    have a password protected folder in my apache2 server. When I point
    my browser to that folder using the https it opens the folder
    without authentication, but when I access it with http only, it
    asks me for username and password. So do you have any idea why this
    basic authentication doesn’t work with https? Thanks

    • Hi Zari,

      If you followed this tutorial, I think you need to enable authentication into the file
      sudo nano /etc/apache2/sites-enabled/000-default-ssl
      has you have done into
      sudo nano /etc/apache2/sites-enabled/000-default
      because SSL sites use another config file. If can be different dependings on the config file you used, but this tip should do the trick.


    • John,
      May be you can use a FQDN (ie mycomputer.com) and generate the certificate for it then in the host file add mycomputer.com
      Did not tried but could work
      Also trying certificate generation for localhost might work.
      Good to test, let me Know

  2. I’m afraid it didn’t work for me. http:// is fine but https:// brings “This webpage is not available”.
    It may have had something to do with the edited Oct 2014 symbolic links as I wasn’t sure what Apache2 was loaded on my RPi. I ended up doing both and when it didn’t work I deleted the .conf. This seemed to work but I got a message about FQDN. I solved that by creating a local.conf in conf.d with servername localhost.
    Any help would be mightily appreciated

  3. Thanks a lot, Charles Henri, it works for me, fine. BUT : something I do not understand, I can access to my site with http:// and with https:// ! is it normal ? I redirect 443 external to 443 internal on my Live box, and I cannot redirect 80 external to 443 internal.

    Thanks for your help.


  4. If I check on your demo, it is the same, http: works and https: also. It is a normal behaviour ? how does the visitor knows he should use https: ?


    • Sebastien,

      Yes for the demo it’s normal, both are working but of course you can just remove simple http but it’s not the best solution. Instead, do a redirect, this mean that every http requests will be redirected to https by the web server. sometimes applications can also do this like wordpress or phpadmin.
      I don’t know live box redirection but may be for 80 -> 443 it’s more under port mapping than redirection. Anyway just close 80 on your livebox and just let 443, then from external you just have https and from your internal network you can use http and https.


  5. Thanks CH for your answer. I am going to study all this. Your page about https is the best one of google’s ! you cannot imagine ! with yours ? 5 minutes ! thanks again.

  6. Hello Charles.

    Now, I dont know what to do ! I went on http://cacert.com in order to have a free certificat.
    I have them : file.cer, file.crt and an ascii very long file supposed to be loaded in my browser !

    You say this :

    pico /etc/apache2/sites-enabled/000-default-ssl
    SSLCertificateKeyFile /etc/apache2/ssl/server.crt
    SSLCertificateKeyFile /etc/apache2/ssl/server.key

    But I do not have that .key file ? what do I have to do with the files Cacert gave me ?

    Thanks again.

    • Sebastien,
      Depending on how you requested your certificate to cacert. did you done it using CSR ? if so your private key certificate should be on the computer from which you generated your CSR file to provide to cacert. What does CACERT procedure says about that ?

0 Comments on this topic in community Forums.

Comments are now managed by the new generation Forums. They will appears both at the end of this article and in the associated thread on the community.