VPS Cloud Hosting With Digital Ocean

It's 2015. Stop using shared hosting. Let's move to cloud, shall we? Digital Ocean is the cheapest kind of cloud VPS hosting I can find till now. $5/m for some decent entry level server hardware? Who wouldn't want that.

If you are setting up a personal website or if you are just beginning to learn how servers work, then this plan is good for you. I wouldn't recommend this plan to those who are setting up a production server, as one of my friend, who is a backend engineer said using AWS is much more reliable for that task.

Creating account at DigitalOcean

  1. Go to http://www.digitalocean.com
  2. Create an account (It's a referral link)
    • Verify account in email
    • Once verified, give your credit card information. Giving your credit card information won't deduct any money as of yet, if you registered with my link above, you'll get $10 free, which means you have two months free DO service.
  3. Create a droplet. A droplet is like a server instance in DigitalOcean.
    • Name your droplet. Eg. tears
    • Select size. I chose the cheapest one, $5/m. Comes with 512MB Memory, 1 Core Processor, 20GB SSD & 1TB Transfer.
    • Select region. Choose the closest to your country.
    • Select image: Ubuntu 14.04 x64
    • Select application: Lamp on 14.04 (This will install apache, mysql, php)
    • Create Droplet to finish
  4. Your droplet DROPLET_IP_ADDRESS is given in the dashboard.

Accessing to droplet

Access to droplet using SSH.

  1. Windows user, please use Putty
  2. Linux and Mac user, use SSH command:
  3. For the first timer, you'll need to reset your password after logged in.

Setting up the server

  1. Enable a2enmod, an apache component for virtual hosted directory.
    sudo a2enmod rewrite
  2. Enable mysqlnd, mysql native driver for PHP. Used to connect PHP to mysql.
sudo apt-get update
sudo apt-get install php5-mysqlnd
sudo service apache2 restart
  1. Install phpmyadmin, stuff for your database.
    sudo apt-get install phpmyadmin apache2-utils
    • Follow the instructions, specify password if asked and select yes, mostly.
  2. You can now access phpmyadmin by this URL: DROPLET_IP_ADDRESS/phpmyadmin
  3. Enable AllowOverride to access public directory
    sudo nano /etc/apache2/apache2.conf
    • Change AllowOverride to All and Require all granted under <Directory var/www/html/>. Eg.
<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride All
	Require all granted

Create a public webpage

  1. Go to /var/www/html. This will serve as your public website directory. Everything that you see on browser, came from here, in directory form.
  2. In this example, create a new directory called example.domain.com:
    sudo mkdir -p example.domain.com
  3. Give the directory an ownership to non-root user: sudo chown -R $USER:$USER /var/www/html/example.domain.com
  4. Give it a read and execute only permission by sudo chmod -R 755 /var/www/html
  5. Let's create a simple webpage here.
    sudo nano /var/www/html/example.domain.com/index.html
  6. Write a simple webpage text like 'hello world'
		<p>Hello world! I'm in the ocean if my grammar is correct...</p>
  1. Save and close it by pressing ctrl+x

By now, you can see your webpage via DROPLET_IP_ADDRESS/example.domain.com in your browser.

You don't need to specify the webpage file name (index.html) as we have allowed all access in apache settings previously. However, we don't want the DROPLET_IP_ADDRESS in our url, we just want example.domain.com. To do this, we need to create a virtual host to serve our public directory and point it to a domain name.

In this example, I'm going to demonstrate on how to create a sub-domain pointing to a public directory that we have created before. You can create a domain (eg. www.domain.com), the process is similar.

Virtual host

Create a virtual host. Useful if you have many subdomains inside public directory, eg. example.domain.com, example2.domain.com, etc.

Apache comes with a default virtual host file. We are going to copy that file and use it for our webpage config.

  1. Duplicate Apache virtual host file:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.domain.com.conf
  1. Edit it
sudo nano /etc/apache2/sites-available/example.domain.com.conf

This is how it looks like - originally - without comments, for clarity.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Some changes need to ammend:

<VirtualHost *:80>
    ServerAdmin your_email@domain.com
    ServerName example.domain.com
    ServerAlias example.domain.com
    DocumentRoot /var/www/html/example.domain.com
    ErrorLog ${APACHE_LOG_DIR}/example.error.log
    CustomLog ${APACHE_LOG_DIR}/example.access.log combined
  1. Save (ctrl+x) and close.
  2. Enable the virtual host: sudo a2ensite /etc/apache2/sites-available/example.domain.com.conf
  3. Restart apache service: sudo service apache2 restart
  4. Setup a local host. Pointing our virtual host to an IP address: sudo nano /etc/hosts
    • Add your DROPLET_IP_ADDRESS pointing to ServerName in virtual host file
    .   localhost
	DROPLET_IP_ADDRESS	example.domain.com

Create a domain

Buy yourself a domain, if you haven't already. eg. domain.com (we've been using this the whole guide!) I don't know about choosing the right registrar. But you can Google for the best one.

1. Digital Ocean settings

Go to your DigitalOcean account

Select Networking and add domain as follows:

Name: example.domain.com
Select droplet: your droplet name

Press Create Domain

2. Domain registrar settings

Add Digital Ocean nameservers. Read here for more details.
> ns1.digitalocean.com
> ns2.digitalocean.com
> ns3.digitalocean.com

Go to manage DNS or wherever it says DNS management and add A records to it.

Hostname: example.domain.com
Destination IPv4 Address: DROPLET_IP_ADDRESS

That's all. Go to example.domain.com in your browser, you'll see your webpage is live and ready to be SEO'd!


Show Comments

Get the latest posts delivered right to your inbox.