Search Our Database
Installing an SSL Certificate via Terminal (Apache)
Introduction
Securing websites with SSL certificates is essential for maintaining trust and safeguarding sensitive data between users and web servers. Apache, being one of the most widely-used web servers globally, offers flexible options to configure SSL through its terminal-based configuration. This approach is ideal for administrators who prefer managing servers over SSH or require a manual deployment for custom environments.
This guide provides step-by-step instructions to install and configure an SSL certificate on Apache using the command line. The process includes generating a Certificate Signing Request (CSR), installing the issued SSL certificate, and modifying Apache’s virtual host configuration to enable HTTPS.
The instructions are suited for system administrators, DevOps engineers, or web hosting professionals managing Linux servers with Apache installed.
Prerequisites
- A Linux-based server with Apache installed (Ubuntu 20.04+, CentOS 7+, AlmaLinux 8+, etc.).
- Root or sudo user access.
- An issued SSL certificate (including .crt and .ca-bundle files) from a Certificate Authority (CA).
- The server’s private key and CSR generated previously (or generate a new one if required).
- SSH access to the server.
Step-by-step Guide
Step 1: Upload SSL Certificate Files to the Server
Using SCP or SFTP, upload the SSL files to a directory on your server, such as /etc/ssl/certs/.
scp yourdomain.crt yourdomain.ca-bundle user@yourserver_ip:/etc/ssl/certs/
Ensure that the private key is securely placed in /etc/ssl/private/.
Step 2: Configure Apache Virtual Host File
Open your Apache configuration file for the domain:
vi /etc/httpd/conf.d/yourdomain.conf # CentOS/RHEL/AlmaLinux vi /etc/apache2/sites-available/yourdomain.conf # Ubuntu/Debian
Configure the Virtual Host as follows:
<VirtualHost *:443> ServerName yourdomain.com ServerAlias www.yourdomain.com DocumentRoot /var/www/yourdomain.com/public_html SSLEngine on SSLCertificateFile /etc/ssl/certs/yourdomain.crt SSLCertificateKeyFile /etc/ssl/private/yourdomain.key SSLCertificateChainFile /etc/ssl/certs/yourdomain.ca-bundle <Directory /var/www/yourdomain.com/public_html> Options -Indexes +FollowSymLinks AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined </VirtualHost>
Step 3: Enable SSL Module (Ubuntu/Debian only)
Use below commands to enable SSL module:
sudo a2enmod ssl sudo systemctl restart apache2
Step 4: Restart Apache Service
For CentOS/AlmaLinux:
sudo systemctl restart httpd
For Ubuntu/Debian:
sudo systemctl restart apache2
Step 5: Verify SSL Installation
Test your website:
https://yourdomain.com
Or use external tools such as:
Conclusion
You have successfully installed and configured an SSL certificate on Apache using the terminal. This ensures secure communication over HTTPS and helps improve your site’s credibility and SEO ranking.
Should you have any inquiries about the guidelines, please feel free to open a ticket through your portal account or contact us at support@ipserverone.com. We’ll be happy to assist you further.