Digital Ocean

Host Your Own Email ServerDigital Ocean is an inexpensive, simple, super fast  cloud-based hosting company. In addition to having a simple web user interface for creating, managing and backing up your servers, they also use solid state digital (SSD) drives. This means that all your sites run faster than servers using traditional magnetic media hard drives.

I’ve recently moved my WordPress sites to Digital Ocean away from Amazon AWS. Amazon’s lowest cost instances which I’d featured in my earlier tutorials, simply have too much latency, whereas Digital Ocean’s SSD-based $5/mo. instances are quite responsive. Digital Ocean’s web interface is also a lot simpler than AWS’. AWS does offer SSD-based instances, but they are more expensive.

Digital Ocean has recently begun offering IPv6 networking support as well. While this isn’t very important right now, it shows that they are staying on the front edge of hosting services.

Related Links

Generic Ubuntu Installation Guide for Digital Ocean

This guide walks you through installing a generic Ubuntu 14.04 instance at cloud hosting provider Digital Ocean ($5 per month); it should work similarly for you in other LAMP environments. You’ll want to have a domain name or sub-domains registered for the app, e.g. http://yourdomain.com. If you don’t have a registrar or need more information, I recommend NameCheap.

Creating Your Server Instance on Digital Ocean

Sign up at Digital Ocean now, the process is simple and only requires your email and password:

signup-do

Digital Ocean’s cloud instances are called Droplets. Once you sign up, you can create your first Droplet using the selections below. You’ll want to have a hostname (domain or sub-domain name) chosen for your readers in mind. You can also select any region closest to you or your typical reader e.g. San Francisco or New York. Under Select Image, choose Applications: LAMP on Ubuntu 14.04 LTS.

Creating a droplet only takes a minute. Digital Ocean will email you your IP address and root password.

Once you have your IP address, you can begin the process of mapping your domains and subdomains e.g. yourdomain.com to your IP address. Visit your domain registrar’s DNS settings and change the A record for yourdomain.com to the new IP address e.g. 54.234.124.117.

Wait until your DNS changes propagate (sometimes up to 24 hours or more – check them here), try to connect via SSH using your domain and the password provided in the Digital Ocean email.

ssh root@yourhostname.com

You can also use your IP address until your domain name is active:

ssh root@xx.xx.xx.xx

Change your password when prompted, or use:

passwd

There are a few things you’ll want to do to get your droplet ready for installing your app.

sudo apt-get install zip php5-curl
sudo apt-get update
sudo apt-get upgrade
sudo a2enmod rewrite

It’s also best to run through the script for securing your MySQL server installation:

mysql_secure_installation

You might also wish to install PHPMyAdmin as I’ve described in Installing and Using PHPMyAdmin for Web Development.

Installing an Application from Github

Installing an application is relatively straightforward. Sign in to your Droplet via SSH as shown above. Download the code:

cd /var/www/
wget https://github.com/newscloud/yourapp/archive/master.zip
unzip master.zip
mv yourapp-master yourapp

Set the file privileges and permissions for yourapp’s directories:

chown -R www-data:www-data yourapp
sudo find /var/www/yourapp/ -type d -exec chmod 755 {} \;
sudo find /var/www/yourapp/ -type f -exec chmod 644 {} \;
chmod -vR 0777 /var/www/yourapp/app/assets/
chmod -vR 0777 /var/www/yourapp/app/protected/runtime
chmod -vR 0777 /var/www/yourapp/app/protected/uploads
chmod 755 /var/www/yourapp/app/protected/yiic
chmod 755 /var/www/yourapp/app/protected/yiic.bat
chmod 755 /var/www/yourapp/app/protected/yiic.php

Login to MySQL. The password for your MySQL Server is usually shown when you login to your Droplet.

mysql -u root -p

Create a database for your application and grant permissions:

create database yourapp;
grant all privileges on yourapp.* TO "root"@"localhost" identified by "your-password";
flush privileges;
exit;

You’ll have to provide these database settings in your application .ini file. Copy the /app/docs/sample-config.ini to a secure directory on your server. e.g.

mkdir /var/secure
cp /var/www/yourapp/app/docs/sample-config.ini /var/secure/yourapp.ini
nano /var/secure/yourapp.ini

Then, change the database settings for your MySQL server:

mysql_host="localhost"
mysql_un="root"
mysql_db="basedb"
mysql_pwd="sql-user-pwd"

Next, we’ll create an Apache configuration file for your website:

nano /etc/apache2/sites-available/yourapp.conf

Paste in the following – replace your sub-domain or domain name:

<VirtualHost *:80>
 ServerName yourdomain.com
 DocumentRoot /var/www/yourapp/app
 DirectoryIndex index.php
 <Directory /var/www/yourapp/app/>
 AllowOverride All
 Order Deny,Allow
 Allow from all
 </Directory>
</VirtualHost>

Activate the site and reload Apache:

a2ensite yourapp.conf
a2dissite 000-default.conf 
service apache2 reload

Visit your website e.g. http://yourdomain.com and you should be able to login using your username and password from the migration.

Congratulations!