Host static files with Apache on Digital Ocean

April 2016

1. Setup Digital Ocean Server

Login or create an account and spin up a new ubuntu 14.04 droplet at www.digitalocean.com, it is pretty self explanatory. In the options, you should choose login through SSH if you want to follow this article step by step.

Then login to your Server: ssh root@ <yourIp> (e.g. ssh root@46.101.131.21).

2. Install Apache

sudo apt-get update sudo apt-get install apache2 When you type <yourIp> into your browser (e.g. ), y ou should now be able to see the following:

3. Change index.html

Now "hosting static files" can mean two things. Either you want to host something like mycoolfile.txt or you want a classic website.

Option 1: Host files for downloading

  1. Switch directory to cd /var/www/html and remove the index.html file (rm index.html)
  2. Copy the files to your server. Navigate to the directory containing your file in a new terminal window and scp mycoolfile.txt root@<yourIp>:/var/www/html.

You should see the following result when navigating to yourIp in your browser:

Option 2: Host your personal website

  1. Switch directory to cd /var/www/html and remove the index.html file (rm index.html)
  2. Then nano index.html. Then you can write any valid html, for example:
    <!DOCTYPE html>
    <html>
    <body>
    
    <h2>Much Doge! Wow!</h2>
    <img src="https://s-media-cache-ak0.pinimg.com/736x/ee/b7/71/eeb771122eebac79dda2eb99d43e3d82.jpg" alt="Doge" width=300px>
    
    </body>
    </html>
    

    which should yield:

 

Interested in web development?


Learn to Write Clean Code

Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin)