Install a certificate for a website under Apache on Linux

From tech
Revision as of 11:02, 3 March 2023 by Lucazeo (talk | contribs)
Jump to navigation Jump to search

In this article, I will show you how to create and install a free SSL certificate for your domain. I will demonstrate how we did it for this very site. The example applies to a site installed on Apache, on a server where you have SSH access and root user privileges. In the example, we use the Debian 11 operating system.

Also we have multiple domain under the same host, managed with VirtualHost. link to official documentation.

  1. Connect to your server via SSH. For example:
    ssh myhostaddress.com
    
  2. Become root. Alternatively, you can use the sudo command before the commands we are going to use:
    sudo su -
    
  3. Install snapd:
    apt install snapd
    
  4. And do the basic configuration. For this example we are not going to deep explain every step, so just:
    snap install core
    snap refresh core
    
  5. In case you have a result like this:
    snap "core" has no updates available
    
    It is ok, go on.
  6. Clean eventually previous installations of certbot. Warning: do this only if you are sure nobody else needs it, or it can break previous scripts and so on:
    apt-get remove certbot
    
  7. Install certbot:
    snap install --classic certbot
    
  8. Create a link to make certbot usable from users:
    ln -s /snap/bin/certbot /usr/bin/certbot
    
  9. Start certbot for apache:
    certbot --apache
    
  10. This will start an interactive script where we need to interact. Let's start with first question. You will see:
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    Enter email address (used for urgent renewal and security notices)
     (Enter 'c' to cancel):
    
    In this case you will just enter your email. Please also not the first line: it indicates you where is the log you will need if something goes wrong.
  11. Second step, the Terms of Service. In order to proceed you need to accept:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Please read the Terms of Service at
    https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
    agree in order to register with the ACME server. Do you agree?
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    (Y)es/(N)o: y