Digital Ocean API Console

ocean-app

Digital Ocean API Console Installation

If you don’t yet have a Digital Ocean account, sign up here. The tutorial for this console will be posted in early June at Tuts+ or browse my Tuts+ page for Jeff Reifman.

This guide walks you through the basics of installing my console application in an Ubuntu 14.04 instance. You can run the console itself in a localhost development environment but require CRON capability for some tasks.

Note: If you appreciate this site, please check out some of our affiliates:

  • Agile Bits 1Password – no need to remember your passwords ever again, except one
  • Digital Ocean – fast SSD hosting from the second largest hosting company in the world
  • FastMail – a great GMail alternative
  • CodeGuard – backup your website automatically with this great service
  • WPEngine – professional, scalable WordPress hosting
CodeGuard

Getting Started

You may want to have a domain name or sub-domains registered for the app, e.g. http://console.yourdomain.com. If you don’t have a registrar or need more information, I recommend NameCheap.

Creating Your Server Instance

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 your ocean.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 the Ocean console.

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 the Console Application

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

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

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

chown -R www-data:www-data ocean
sudo find /var/www/ocean/ -type d -exec chmod 755 {} \;
sudo find /var/www/ocean/ -type f -exec chmod 644 {} \;
chmod -vR 0777 /var/www/ocean/app/assets/
chmod -vR 0777 /var/www/ocean/app/protected/runtime
chmod -vR 0777 /var/www/ocean/app/protected/uploads
chmod 755 /var/www/ocean/app/protected/yiic
chmod 755 /var/www/ocean/app/protected/yiic.bat
chmod 755 /var/www/ocean/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 Ocean and grant permissions:

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

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

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

Then, change the database settings for your MySQL server and add your Digital Ocean API access key:

mysql_host="localhost"
mysql_un="root"
mysql_db="basedev"
mysql_pwd="sql-user"
do_access = "your-digital-ocean-api-access-token"

To build the MySQL database, we’ll run Yii ActiveRecord migrations:

cd /var/www/ocean
./app/protected/yiic migrate --migrationPath=user.migrations
./app/protected/yiic migrate up

You’ll be prompted to create your web user login credentials; you’ll use these to log in to the website – important, use admin for the username:

Admin login [admin]: admin
Admin email [webmaster@example.com]: admin@yourdomain.com
Admin password [admin]: supereasy99

Yii will then go ahead and build the database for you.

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

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

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

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

Activate the site and reload Apache:

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

We’ll use cron to configure a background task to regularly run the background actions:

crontab -e

Paste in the following line – replace your domain (this will update your timeline every five minutes):

*/5 * * * * wget -O /dev/null http://ocean.yourdomain.com/daemon/index

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