Skip to content

Instantly share code, notes, and snippets.

@chrisdchristo
Created December 28, 2013 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdchristo/8159746 to your computer and use it in GitHub Desktop.
Save chrisdchristo/8159746 to your computer and use it in GitHub Desktop.
101: Apache

101: Apache

sudo apt-get install apache2

Setup the default site (/var/www)

To host your own custom website, you will want to use the /var/www folder for your files.

First let's disabled the default websites Apache sets up for us:

sudo a2dissite default
sudo a2dissite default-ssl
sudo a2dissite 000-default

Then remove the default-ssl file:

sudo rm /etc/apache2/sites-available/default-ssl

We are only going to need the default file in the sites-available folder. Lets change the default file to accept SSL and also point all non-ssl requests to the SSL website.

Open it with nano:

sudo nano /etc/apache2/sites-available/default

and alter it to look like this:

<VirtualHost *:80>
        Redirect permanent / https://mydomain.com/
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        SSLEngine on
        SSLCACertificateFile /etc/ssl/custom/certs/official-www-mydomain-com-ad-inter.crt
        SSLCertificateFile    /etc/ssl/custom/certs/official-www-mydomain-com.crt
        SSLCertificateKeyFile /etc/ssl/custom/keys/official-www-mydomain-com.key        
</VirtualHost>
</IfModule>

Now re-enable the default site:

sudo a2ensite default

Finally we want to reload & restart the web server:

sudo /etc/init.d/apache2 reload
sudo /etc/init.d/apache2 restart

Now you can just add any web files straight to the /var/www folder without having to restart the apache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment