https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-with-a-free-signed-ssl-certificate-on-a-vps
Note: You may want to consider using Let's Encrypt instead of the StartSSL.com process below. Let's Encrypt is a new certificate authority that provides a free and easy way of creating SSL/TLS certificates that are trusted in most web browsers. Check out the tutorial to get started: How To Secure Apache with Let's Encrypt on Ubuntu 14.04
Prerequisites
Before we get started, here are the web tools you need for this tutorial:
- Google Chrome browser
- Apache installed on your VPS (cloud server)
- A domain name you own
- Access to an email address at that domain, either:
- postmaster@duable.co
- hostmaster@duable.co
- webmaster@duable.co
StartSSL.com offers completely free verified (your users won't have to see those scary red screens saying "this site isn't trusted" anymore) SSL certificates that you can use on your website. This is a great deal as most companies charge $50-$60 for similar services. The free version is a bit tricky to set up, but it's well worth it.
To get started, browse to StartSSL.com and using the toolbar on the left, navigate to StartSSL Products and then to StartSSL™ Free. Choose the link for Control Panel from the top of the page.
Make sure you are using Google Chrome
- Choose the Express Signup. option
- Enter your personal information, and click continue.
- You'll get an email with a verification code inside it shortly. Copy and paste that email into the form on StartSSL's page.
- They will review your request for a certificate and then send you an email with the new info. This process might take as long as 6 hours though, so be patient.
- Once the email comes, use the link provided and the new authentication code (at the bottom of the email) to continue to the next step.
- They will ask you to Generate a private key and you will be provided with the choice of "High" or "Medium" grade. Go ahead and choose "High".
- Once your key is ready, click Install.
- Chrome will show a popdown that says that the certificate has been succesfully installed to Chrome.
This means your browser is now authenticated with your new certificate and you can log into the StartSSL authentication areas using your new certificate. Now, we need to get a properly formatted certificate set up for use on your VPS. Click on the Control panel link again, and choose the Authenticate option. Chrome will show a popup asking if you want to authenticate and will show the certificate you just installed. Go ahead and authenticate with that certificate to enter the control panel.
You will need to validate your domain name to prove that you own the domain you are setting up a certificate for. Click over to the Validations Wizard in the Control panel and set Type to Domain Name Validation. You'll be prompted to choose from an email at your domain, something like [email]postmaster@yourdomain.com[/email].
Check the email inbox for the email address you selected. You will get yet another verification email at that address, so like before, copy and paste the verification code into the StartSSL website.
Next, go to the Certificates Wizard tab and choose to create a Web Server SSL/TLS Certificate.
Hit continue and then enter in a secure password, leaving the other settings as is.
You will be shown a textbox that contains your private key. Copy and paste the contents into a text editor and save the data into a file called ssl.key.
When you click continue, you will be asked which domain you want to create the certificate for:
Choose your domain and proceed to the next step.
You will be asked what subdomain you want to create a certificate for. In most cases, you want to choose www here, but if you'd like to use a different subdomain with SSL, then enter that here instead:
StartSSL will provide you with your new certificate in a text box, much as it did for the private key:
Again, copy and paste into a text editor, this time saving it as ssl.crt.
You will also need the StartCom Root CA and StartSSL's Class 1 Intermediate Server CA in order to authenticate your website though, so for the final step, go over to the Toolbox pane and choose StartCom CA Certificates:
At this screen, right click and Save As two files:
- StartCom Root CA (PEM Encoded) (save to ca.pem)
- Class 1 Intermediate Server CA (save to sub.class1.server.ca.pem)
For security reasons, StartSSL encrypts your private key (the ssl.key file), but your web server needs the unencrypted version of it to handle your site's encryption. To unencrypt it, copy it onto your server, and use the following command to decrypt it into the file private.key:
openssl rsa -in ssl.key -out private.key
OpenSSL will ask you for your password, so enter it in the password you typed in on StartSSL's website.
At this point you should have five files. If you're missing any, double-check the previous steps and re-download them:
- ca.pem - StartSSL's Root certificate
- private.key - The unencrypted version of your private key (be very careful no one else has access to this file!)
- sub.class1.server.ca.pem - The intermediate certificate for StartSSL
- ssl.key - The encrypted version of your private key (does not need to be copied to server)
- ssl.crt - Your new certificate
You can discard the ssl.key file. If you haven't already copied the others onto your server you upload them there now:
scp {ca.pem,private.key,sub.class1.server.ca.pem,ssl.crt} YOURSERVER:~
0 ^0 B q9 k' t: i
Activating the certificate in Apache
Having a certificate isn't any good if you can't actually use it. This section explains how to configure Apache to use your new SSL certificate. These instructions are for Apache running on recent versions of Ubuntu VPS. For other Linux-based distros or web servers, you'll have to adjust accordingly.
First, create the folders where we'll store the keys. Enable Apache's SSL module, and restart Apache.
sudo a2enmod ssl8 D6 c* `* z6 T+ k& J* b$ r
sudo service apache2 restart
" F4 i% C; u9 Esudo mkdir -p /etc/apache2/ssl0 Q* G6 V' z1 i+ c! D
Copy the files you set up in the previous section into the /etc/apache2/ssl folder on your VPS.
sudo mkdir -p /etc/apache2/ssl
1 h. L( w- k8 ?% S) |3 K2 Wcp ~/{ca.pem,private.key,sub.class1.server.ca.pem,ssl.crt} /etc/apache2/ssl
; W1 h* s8 B' e5 Y
Execute:
ls /etc/apache2/ssl
And it should return:
ca.pem
- j8 l/ C8 \. wssl.crt
" d% n) E$ f, ~+ o6 Gprivate.key
5 G: `: N3 T/ k9 S2 @( Tsub.class1.server.ca.pem
Now, open your apache2 configuration file. Unless you've already modified the default configuration, input:
nano /etc/apache2/sites-enabled/000-default
It should look something like this:
<VirtualHost *:80>
% n$ ~: ?8 p% J- d1 d ServerAdmin webmaster@localhost/ N! P) w: `+ T0 {. {: w$ I2 i
2 W: n2 [1 c8 G+ {+ p4 ?
DocumentRoot /var/www/ a5 L* Q+ [* |3 Y1 B
<Directory />
6 k0 a: K9 X& G1 X( R0 J3 o" {, C Options FollowSymLinks
& S2 Y, }) G' `$ n! { AllowOverride None
8 B+ x+ _: N8 c! X </Directory>
5 i/ O7 B. {) V) o# Y <Directory /var/www/>. R) a$ j1 Z1 W, h6 j
Options Indexes FollowSymLinks MultiViews
- n" u3 ?2 i, M; d* H1 e$ [8 c# r7 n AllowOverride None$ o. k e& M8 |: z' N6 {
Order allow,deny- b. A- a9 {) d4 n& f" L8 x9 _
allow from all1 i. |% y7 T/ ?& B6 a% |+ l+ k
</Directory>; u- r. t" z1 r% G Y. w
, T3 m& d" v7 J/ K ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/* P" ]5 ]3 Q8 T5 |2 E, k+ t
<Directory "/usr/lib/cgi-bin">
. A; V' w' r. G R& q A AllowOverride None, f& [% G% |# g
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch( N2 \' t6 F1 _; T) [8 x
Order allow,deny
' s* c" M+ L2 [1 N2 @ Allow from all
2 a6 _1 P6 J9 c! J1 i8 D </Directory>, z: ^& Y: _' i
/ u2 [" Z+ R$ _0 S
ErrorLog ${APACHE_LOG_DIR}/error.log( i+ a+ n( {- |& ]6 G5 R8 x
) u A) ]7 }+ C+ v' L # Possible values include: debug, info, notice, warn, error, crit,. {! z2 l( r& z$ t. }6 f
# alert, emerg.3 L* s% a. Y: x
LogLevel warn
; `6 h9 o6 b0 _) {
2 Y4 j* l6 G6 N: y CustomLog ${APACHE_LOG_DIR}/access.log combined
+ I4 Q& c' J/ l! s2 K4 y
9 H6 p8 l9 G- I$ n/ _& `# |6 O Alias /doc/ "/usr/share/doc/"
. x4 y& m7 ?0 n' r9 b. T <Directory "/usr/share/doc/">
& ^/ u; b; A4 s: ]; f X5 [9 X Options Indexes MultiViews FollowSymLinks! {1 R3 |8 j( F6 Q2 |0 o
AllowOverride None
. X8 p# D5 H1 b% N) L; x/ u Order deny,allow S/ i" j: w& C$ ` @4 f3 `0 J
Deny from all
( e) z! N# ~" }- @ Allow from 127.0.0.0/255.0.0.0 ::1/128. E4 l+ ^+ H/ B& g; d& M, o6 A
</Directory>0 Y, u G+ d7 h/ k! w" ]
: f& ~+ w; _; G( O# ]! B6 J$ b</VirtualHost>: ^3 Q0 f1 ^/ p' m5 U G* l
Copy the entire script above (from <VirtualHost *:80> to </VirtualHost>), paste it below the existing one, and change the top line from:
<VirtualHost *:80>
to
<VirtualHost *:443>
And add the following lines after the <VirtualHost *:443> line:
SSLEngine on
: Z1 A9 Q3 N1 g9 S# S% {SSLProtocol all -SSLv2 # y) |9 r" d' q
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
1 d2 f2 x: H# r. u, d- A/ H3 b' c; d, Q+ J) G
SSLCertificateFile /etc/apache2/ssl/ssl.crt l% j" h8 T8 V5 l* n
SSLCertificateKeyFile /etc/apache2/ssl/private.key
- t2 A* Z4 d8 e9 v5 LSSLCertificateChainFile /etc/apache2/ssl/sub.class1.server.ca.pem
The end result should look like this:
<VirtualHost *:80>7 D6 Z* k; k. ^* e+ ?
ServerAdmin webmaster@localhost+ r& X# w1 v' G" }+ h+ t
5 ^ l1 B, ]5 L# t: M! ^9 B6 q DocumentRoot /var/www7 X7 Y ?3 p v* [
<Directory />
6 ~+ g3 m9 @5 p Options FollowSymLinks' n4 R& p- W( ^# q. `
AllowOverride None1 G7 T- G% o# D2 W3 L+ K
</Directory>4 c* G! n2 m# g
<Directory /var/www/>8 o4 h o. Y, x- m0 K9 \( R6 W
Options Indexes FollowSymLinks MultiViews
7 l' J- H+ y* w4 i8 I AllowOverride None( R" j7 _* ?" m- c4 a ~
Order allow,deny
{, v" B1 O2 v; n: T allow from all
% o! b1 y, P$ f1 @( j& h4 c) f' z </Directory>% R+ ^3 H9 m) \2 V$ m; v% d# C
: b* Q4 K6 Q" v4 K' I& C
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
; J8 M- P: {6 _/ n <Directory "/usr/lib/cgi-bin">
( x0 M# @. v5 Q' L5 B- [! _ AllowOverride None
4 j% D+ R4 t, |9 p" I1 c' x Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
4 W6 _. b; G7 F: n Order allow,deny
. ~2 i# e( G; l4 p- C0 Q' ~ Allow from all
2 k3 G$ K' G* b$ d4 a </Directory>
/ p( q# E, `1 g4 [* { S. ]0 h1 K3 {3 E
ErrorLog ${APACHE_LOG_DIR}/error.log
* ?8 t! E+ E; w- l) M; ^9 ~! ]- ]7 k
' _9 X [& I8 D, k # Possible values include: debug, info, notice, warn, error, crit,
: n7 m# D4 c. P6 C' _# p! T. @" { # alert, emerg.
3 i- ~8 Z5 S$ | LogLevel warn
% G; h. p7 }" |: e, r; a* w
2 L, m, T% z2 c( U CustomLog ${APACHE_LOG_DIR}/access.log combined3 E; l" v! E" G) U3 H3 d. @+ t
1 u9 x. ?7 F! a" @3 |
Alias /doc/ "/usr/share/doc/"% g9 ~* _' y( a0 C
<Directory "/usr/share/doc/">
* J. b4 A) i6 p Options Indexes MultiViews FollowSymLinks5 [" a* A. s4 Y4 V/ v
AllowOverride None8 Q# n8 f1 \! r; L+ ~
Order deny,allow4 Y# Q7 Z; t6 I2 H- `
Deny from all# X4 |3 J3 e( g8 n1 f
Allow from 127.0.0.0/255.0.0.0 ::1/128
( H' Y. F, a! m9 Y( x1 k u </Directory>
2 W& |! I( O8 _- @
/ J! v' e6 y) B. O: Q- e; E7 e</VirtualHost>9 f4 F; |1 J8 n+ v* H" ^
3 v5 z# d3 T w. W% v1 F
<VirtualHost *:443>+ W, [: M: @* ~. \
SSLEngine on
4 t2 c. n7 p) R* V7 `0 ? SSLProtocol all -SSLv2 * X6 n: y- h2 H4 H4 H5 H
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM , x7 t: u/ y* W9 c
& q" I) C4 C8 w. D. d) x
SSLCertificateFile /etc/apache2/ssl/ssl.crt & ?$ y4 \3 c3 [& O5 u8 V Y, \2 j8 b2 [
SSLCertificateKeyFile /etc/apache2/ssl/private.key 0 L9 T( D! C& U$ N1 e0 ~ p- y' k
SSLCertificateChainFile /etc/apache2/ssl/sub.class1.server.ca.pem - _0 l; l# R. @8 d
ServerAdmin webmaster@localhost
3 j3 H+ |. h. i& r9 r3 U, w. g2 }7 a
DocumentRoot /var/www
/ T0 ^$ j. R) l0 n6 h: @ <Directory />
* I$ s# b2 C/ R Options FollowSymLinks
+ u" k: u- |& p$ S8 v6 y AllowOverride None
' c( {* X6 l% i& ]" V. } </Directory>2 I; |3 K2 t: D, @
<Directory /var/www/>" k! z2 z3 ~- [) U0 g p
Options Indexes FollowSymLinks MultiViews+ Z2 a- I+ g" ]& D' y1 n; X' T. D7 U
AllowOverride None
: H6 g J$ J& I' _0 D Order allow,deny
0 g' X$ j! L9 e4 I9 Y. a2 B2 \ allow from all
6 S5 {: s. J( s! O( t+ K </Directory>. j' |% _7 y' A/ n. u5 r2 g$ a* n
?9 A6 `8 |$ s3 L# n s! T
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
3 w9 t O' z8 H; I+ f1 @0 F <Directory "/usr/lib/cgi-bin">4 |. C6 G/ Z' @2 s+ x; H
AllowOverride None
4 j" D" f7 b: W3 Q+ v7 P0 V. O8 F6 w Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
1 I# U# r6 J* v2 ?. L6 h# x3 s Order allow,deny
+ I( a& X2 Q( Z7 w Allow from all
( @. p0 q" v/ s+ b' [' U, m </Directory>
' L U7 B3 e* `; ]3 ]
6 Y2 `' ^, o- _/ |* ^" h ErrorLog ${APACHE_LOG_DIR}/error.log" V% G( c3 t1 m
; w/ f! \3 ~+ n* s- k# Q # Possible values include: debug, info, notice, warn, error, crit,' `7 f6 V0 s, T! l; x3 V$ G
# alert, emerg.1 A, ]4 s7 |' [
LogLevel warn5 K8 Z+ t# b5 U
! p- }3 L @1 a' |7 B
CustomLog ${APACHE_LOG_DIR}/access.log combined
{. i. N& L# T) W6 T
) r3 a3 v/ V* y( o+ ]$ x: f Alias /doc/ "/usr/share/doc/"
* m5 Q3 m* B+ Z) a: Q% I& z <Directory "/usr/share/doc/">+ g, \9 \9 s! Q" F) ]' p, n: ^
Options Indexes MultiViews FollowSymLinks; H" c* y" i8 ^
AllowOverride None# n: _' c! s% |+ w v
Order deny,allow% R7 B0 b& ~! i
Deny from all
7 j5 I6 M- i2 \4 B* X: [8 ^1 G Allow from 127.0.0.0/255.0.0.0 ::1/128& _4 o0 S' q' B4 |6 ]4 ]7 v
</Directory>' U9 a% O' L3 r; [2 l4 j9 a
$ ]' o, G R) L+ `
</VirtualHost>
Save your files and restart Apache with:
sudo service apache2 restart
You can check Apache's log files to see if there are any show stopping errors with this command:
cat /var/log/apache2/error.log2 m& m" v4 c/ H" J2 l
If everything looks good, try accessing your site in your web browser using an HTTPS URL (e.g. https://www.YOURSITE.com). When your site loads, you should see a little green padlock icon next to the URL. Click on it and you should see the following. The connections tab should show that the site's identity has been verified by StartCom.
Congratulations! You are all set!
Reference Links:
Here are some of the other posts I consulted when putting this together. If you run into any problems they might be a source of inspiration on how to fix them: