$ sudo apt-get update
$ sudo apt-get upgrade
1) Installing Apache
To install apache 2 type the command:
$ sudo apt-get install apache2
When finished you should be able to connect with the browser at http://localhost and see the message “It works!”. Or you may verify that at the command line installing and using curl:
$ sudo apt-get install curl
$ curl http://localhost
<h1>It works!</h1>
$ gedit /etc/apache2/ports.conf
2) Configuring Apache with SSL
Now we want to configure apache to run HTTPs.
Following command will enable ssl Apache2 module with a2enmod (cryptic name for “Apache2 enable module”
$ sudo a2enmod ssl
The previous command will suggest you to restart apache to let it to reload the configuration; ignore that message for now.
We need to enable the HTTPS port (443). Edit /etc/apache2/ports.conf and ensure that port 443 is defined as follows:
$ gedit /etc/apache2/ports.conf
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz
NameVirtualHost *:80
Listen 80
# SSL name based virtual hosts are not yet supported, therefore no
# NameVirtualHost statement here
NameVirtualHost *:443
Listen 443
I added the clause NameVirtualHost *:443 in the for SSL; this is not strictly necessary but it will be useful later if you want to have a VirtualHost for trac and other development services.
Now we need to configure the SSL site. Fortunately we have already the configuration file for that, we just need to enable it with a2ensite (cryptic name for “apache2 enable site”)
$ sudo a2ensite default-ssl
$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2 apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
… waiting apache2: Could not reliably determine the server’s fully
If everything went fine you should see the above warning. You can ignore it, unless you want to configure the ServerName for your server. But this is out of scope, so do a search on Google, or consult an Apache expert.
So, if everything went fine, now we should be able to connect to our server through SSL.
You can use firefox or curl, as before, but this time the URL will be https://localhost
$ curl -k https://localhost
<html><body><h1>It works!</h1></body></html>
the -k option is to ignore certification validation. Also firefox will complain that our certificate is invalid, but you can add it to exceptions and it will nomore bug you with those messages.
If everything went fine, now we should have Apache2, HTTP and HTTPs ready.
Reference:
Install Tutorial: Ubuntu 9.04, Apache with SSL, Subversion over HTTP / HTTPs, and Trac
Kleber Rodrigo de Carvalho