In this tutorial we will show how to create your very own self signed ssl certificate or How to create a self signed ssl certificate and install it which you can install on your apache web server using Ubuntu Linux. The first step is to make sure you have openssl so that you can generate the certificate. We will be generating two files, one which is the .crt which basically is the certificate file and a .key file which governs the trust of the certificate. First lets make sure you have openssl installed.
How to install open ssl
In order to install openssl you will need to run the command : sudo apt-get install openssl
On the command line. Once installed you will need to run the command :
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout keyname.key -out certname.crt
This should create a certificate which is valid for 365 days. You should now be prompted with a few questions.
You can simply fill this in to your best knowledge. Once done you should now have two files: keyname.key and certname.crt.
Let’s setup our apache server to be able to handle ssl
First we need to make sure that apache has ssl enabled in order to enable run the following command on the command line:
sudo a2enmod ssl
Once enabled we should be ok to now do the configuration. For this tutorial we will assume your website is already in the var/www folder.
Apache virtual hosts for your self signed certificate
Since ssl is generally setup on port 443 which is the default port for https we will setup the virtual host for this scenario.
Let’s first get into our apache folder. Run:
cd /etc/apache2/sites-enabled
create the config file:
touch mysite.conf
nano mysite.conf (Alternatively use your text editor of choice).
Add the following virtual host entry in the config file:
<VirtualHost *:443>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite
ErrorLog ${APACHE_LOG_DIR}/error-mysitelog
CustomLog ${APACHE_LOG_DIR}/access-mysite.log combined
<Directory “/var/www/mysite”>
AllowOverride All
</Directory>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/certname.crt
SSLCertificateKeyFile /etc/apache2/ssl/keyname.key
</VirtualHost>
Save the file and then make sure to have copied the files from openssl into the folder /etc/apache2/ssl.
Restarting apache
Now you can restart apache for the config to take effect. Run:
sudo service apache2 restart
If no errors you should be good to go.
Testing the self signed certificate
Open a web browser and browse to https://mysite.com if the page opens and loads your certificate is working.
Report