Setting up SSL with Apache2 (Debian/Crunchbang) 09-27-2014, 07:32 AM
#1
Oh it's that time again. You know what time it is. Time for Equinox post a tutorial that is probably 100% incorrect and look like a dumbass. Wait... it's not that time? Oh well, here goes nothing.
I for one hated this process, annoying as fuck, but still useful. If you've ran a website, especially one with SSL, you know the deal. This tutorial is how to setup SSL for Crunchbang specifically.
If you haven't already installed Apache2, or OpenSSL, you may take the time to do so now, as I will not be teaching you either of these in this tutorial (rather how to set them up).
Good, now that you've got them installed, let's have some fun.
Basic commands you will need to know for this tutorial;
Also note that I was not able to figure all of this out on my own; Some research did factor in, and I do not take full credit for this tutorial, however, I am sharing this because no matter the query typed into Google, there isn't any Crunchbang specific tutorials (or rather Debian, however, Crunchbang is a bit different from even what it is based off of).
Here we go. The first step to installing SSL onto your Apache2 server is to make sure Apache2 works in the first place. When you finish installing it, go to http://127.0.0.1/ in your browser. If set up correctly, it should bring you to index.html, or rather a page that looks like this;
![[Image: uCZjih6.png]](http://i.imgur.com/uCZjih6.png)
If you haven't set it up correctly, you may want to trace back your steps. Though all you really need to do is run the sudo apt-get command, so I haven't the foggiest how you fucked up if you did.
Go back to terminal, and prepare your anus, we're about to do some bash commands. First we will produce keys for our site and then generate our certificate using the openssl command. Go ahead and clear your terminal if you don't like it to be cluttered; I'm a neat freak when it comes to terminal, so I clear mine like ever 5 seconds.
If you haven't already logged into root, it is in your best interest to do so now. These files (the key and certificate) we just generated will be stored in /home/*user*/ if you weren't logged into root, otherwise they will be located in /root/.
Now we will make a folder to hold our SSL-related files. Use the mkdir command to do so, or just type what follows;
Move the files we made earlier (the key and cert) to the /etc/apache2/*ssl_folder_name*/ directory. I put "*ssl_folder_name*" in place of your ssl directory in /etc/apache2/. Maybe you might not have named the directory "ssl". Open up your apache2 directory, shit's going to get wild.
You should be logged into root when doing this. DO NOT TOUCH ANYTHING UNLESS INSTRUCTED. Seriously, you could fuck up your entire system if you're not careful; though not with Apache2, you'd just screw your webserver. Just don't wander off, kids.
Now then, we have 2 of the 3 needed files. We will copy the "ssl.crt" file, and paste it in the same folder, and rename this new copy to "ssl.pem". This is our pem key, conveniently enough, it has the same structure as the .crt file, so no need to edit or worry about this file at all.
Go one directory up (/etc/apache2/ssl/ -> /etc/apache2) and then to the sites-available directory (/etc/apache2/sites-available). Modify your default-ssl file with your preferred text editor. It will look something like this (actually exactly like this unless you've modified it);
![[Image: aCdHesL.png]](http://i.imgur.com/aCdHesL.png)
We're looking for two specific lines. It's these ones;
![[Image: Ux6cfi8.png]](http://i.imgur.com/Ux6cfi8.png)
Now, if you've been following this tutorial strictly, your directories should be the same. If they aren't, that's okay. Just change the two lines to the .pem and .key location.
![[Image: u9wuPrF.png]](http://i.imgur.com/u9wuPrF.png)
We're almost done, now we have to disable port 80 (optional), and change the 000-default file. If you want to disable port 80, open /etc/apache2/ports.conf in a text editor. Find the lines that say the following;
(Lines 8 & 9)
Just put a hashtag in front of them, and they will be commented out.
Save your file, and move onto /etc/apache2/sites-enabled/000-default and open it in your preferred text editor.
Change the first line ( <VirtualHost *:80> ) to <VirtualHost *:443>. Lastly, put these 3 lines between "</Directory>" and "ErrorLog ${APACHE_LOG_DIR}/error.log";
Save your file. If you have done everything correctly, go back to terminal, exit xdg, and type this;
This will restart your apache2 webserver. If you did everything correctly, it will restart without any failure or errors. Then just go to a browser and type "https://127.0.0.1" (or "https://localhost"). If everything goes well, this will be your ending page;
![[Image: B9IWGTy.png]](http://i.imgur.com/B9IWGTy.png)
kbye
I for one hated this process, annoying as fuck, but still useful. If you've ran a website, especially one with SSL, you know the deal. This tutorial is how to setup SSL for Crunchbang specifically.
If you haven't already installed Apache2, or OpenSSL, you may take the time to do so now, as I will not be teaching you either of these in this tutorial (rather how to set them up).
Good, now that you've got them installed, let's have some fun.
Basic commands you will need to know for this tutorial;
Code:
xdg-open ...
sudo ...
openssl ...
mkdir ...
mv ...Also note that I was not able to figure all of this out on my own; Some research did factor in, and I do not take full credit for this tutorial, however, I am sharing this because no matter the query typed into Google, there isn't any Crunchbang specific tutorials (or rather Debian, however, Crunchbang is a bit different from even what it is based off of).
Here we go. The first step to installing SSL onto your Apache2 server is to make sure Apache2 works in the first place. When you finish installing it, go to http://127.0.0.1/ in your browser. If set up correctly, it should bring you to index.html, or rather a page that looks like this;
![[Image: uCZjih6.png]](http://i.imgur.com/uCZjih6.png)
If you haven't set it up correctly, you may want to trace back your steps. Though all you really need to do is run the sudo apt-get command, so I haven't the foggiest how you fucked up if you did.
Go back to terminal, and prepare your anus, we're about to do some bash commands. First we will produce keys for our site and then generate our certificate using the openssl command. Go ahead and clear your terminal if you don't like it to be cluttered; I'm a neat freak when it comes to terminal, so I clear mine like ever 5 seconds.
Code:
$ openssl genrsa -out ssl.key 1024
$ openssl req -new -key ssl.key -x509 -out ssl.crtIf you haven't already logged into root, it is in your best interest to do so now. These files (the key and certificate) we just generated will be stored in /home/*user*/ if you weren't logged into root, otherwise they will be located in /root/.
Now we will make a folder to hold our SSL-related files. Use the mkdir command to do so, or just type what follows;
Code:
$ mkdir /etc/apache2/ssl/Move the files we made earlier (the key and cert) to the /etc/apache2/*ssl_folder_name*/ directory. I put "*ssl_folder_name*" in place of your ssl directory in /etc/apache2/. Maybe you might not have named the directory "ssl". Open up your apache2 directory, shit's going to get wild.
Code:
$ xdg-open /etc/apache2/ssl/You should be logged into root when doing this. DO NOT TOUCH ANYTHING UNLESS INSTRUCTED. Seriously, you could fuck up your entire system if you're not careful; though not with Apache2, you'd just screw your webserver. Just don't wander off, kids.
Now then, we have 2 of the 3 needed files. We will copy the "ssl.crt" file, and paste it in the same folder, and rename this new copy to "ssl.pem". This is our pem key, conveniently enough, it has the same structure as the .crt file, so no need to edit or worry about this file at all.
Go one directory up (/etc/apache2/ssl/ -> /etc/apache2) and then to the sites-available directory (/etc/apache2/sites-available). Modify your default-ssl file with your preferred text editor. It will look something like this (actually exactly like this unless you've modified it);
![[Image: aCdHesL.png]](http://i.imgur.com/aCdHesL.png)
We're looking for two specific lines. It's these ones;
![[Image: Ux6cfi8.png]](http://i.imgur.com/Ux6cfi8.png)
Now, if you've been following this tutorial strictly, your directories should be the same. If they aren't, that's okay. Just change the two lines to the .pem and .key location.
![[Image: u9wuPrF.png]](http://i.imgur.com/u9wuPrF.png)
We're almost done, now we have to disable port 80 (optional), and change the 000-default file. If you want to disable port 80, open /etc/apache2/ports.conf in a text editor. Find the lines that say the following;
Code:
NameVirtualHost *:80
Listen 80(Lines 8 & 9)
Just put a hashtag in front of them, and they will be commented out.
Code:
#NameVirtualHost *:80
#Listen 80Save your file, and move onto /etc/apache2/sites-enabled/000-default and open it in your preferred text editor.
Change the first line ( <VirtualHost *:80> ) to <VirtualHost *:443>. Lastly, put these 3 lines between "</Directory>" and "ErrorLog ${APACHE_LOG_DIR}/error.log";
Code:
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/ssl.pem
SSLCertificateKeyFile /etc/apache2/ssl/ssl.keySave your file. If you have done everything correctly, go back to terminal, exit xdg, and type this;
Code:
sudo /etc/init.d/apache2 restartThis will restart your apache2 webserver. If you did everything correctly, it will restart without any failure or errors. Then just go to a browser and type "https://127.0.0.1" (or "https://localhost"). If everything goes well, this will be your ending page;
![[Image: B9IWGTy.png]](http://i.imgur.com/B9IWGTy.png)
kbye
![[Image: BXqGARG.png]](https://i.imgur.com/BXqGARG.png)








![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)