How to set up an HTTPS / SSL certificate - complete guide
In this tutorial I describe in detail the steps to obtain and deploy a valid certificate on a web server.
When deploying the https protocol on client sites, I often encountered various difficulties that stemmed from a lack of understanding of the issues and too much complexity of the concepts.
In this tutorial I describe in detail the steps to obtain and deploy a valid certificate on a web server.
In each subheading, I always briefly summarize the step for advanced users, and at the bottom I discuss the details for beginners.
Warning: The entire process of deploying a certificate can take over an hour and is often intermittent (the site may be unavailable).
Input requirements
The instructions assume that we have access to a Terminal web server running on Linux that uses Apache.
For Nginx the whole theory applies equally, just the certificate file linking is different.
Connecting to the web server
We connect to the server via SSH.
- On Windows I recommend the program Putty,
- On Mac or Linux, just use the built-in Terminal.
On Mac or Linux, call the command:
ssh user@server
For example, I want to connect to the user root on the baraja.cz website:
ssh root@baraja.cz
Or to the user jan at a specific IP address:
ssh jan@127.0.0.1
After submitting the query, either the connection will be made directly or you will be asked for a password. Nothing is displayed when typing the password, so confirm the password with enter and wait for the connection to be authorized.
Warning: If we do not have rights to an action, we need to assign them. Either switch directly to the
rootuser with thesudo sucommand, or precede the command we want to execute under root with the wordrootat the beginning, for exampleroot rm <name>under root will delete the file<name>. When using thesudocommand, we may periodically be prompted for a password.
Details:
SSH access is set up by the particular hosting where you have leased a server.
- In case of VPS you will always get SSH access.
- In the case of hosting, you may not get SSH at all, and configuration is done differently (usually via the web interface, or contact support).
Switching from HTTP to HTTPS
If you are converting an existing site from http to https, you need to guarantee that all traffic is redirected to the new https protocol.
In the case of Apache, this can easily be achieved by using a redirect in the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule .? https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
This configuration will ensure that all requests to http are redirected with HTTP code 301 to https. This configuration is the default for the Nette framework, but applies to all other cases as well.
Details:
The .htaccess file contains the specific web server configuration that affects each request. It is usually placed in the same directory as index.php, or other files that are accessible from the Internet.
Its setting is only valid for the Apache server and may be disabled or restricted for some hosts. For more detailed information, always contact the hosting where you host your site.