Chris Mallinson Chris Mallinson at night
Chris Mallinson

Koken on DigitalOcean

Posted on November 24, 2016

Koken is “Content management and web site publishing for photographers”. It’s free and a great platform for photo publishing and other simple content. It even integrates with Adobe Lightroom.

When I build a site for a client or friend, I’m suggesting WordPress or Squarespace about 90% of the time. For photographers, many are best served by Squarespace, or by using premium accounts with Flickr, 500px, or another of the photo-centric sites. This tutorial is for those who want to host your site on your own, for whatever reason you want. It’s not as expensive as you might think. You can get going for under $10 per month.

Prerequisites

Buy a domain if you don’t have one. You should always use Hover when you buy a domain. Hover is the best registrar out there. They make everything easy, and give you full access to DNS settings. Once you’ve got your domain, or chosen an existing one, move on to the next step.

Create an account at DigitalOcean. Use my referral link and we each get free money – you get $10 credit. When you’ve got your account created, it’s time to build your server. This is so easy it makes me sad about the time it used to take a few days to set up hosting for clients. Go to the droplets pages, and click “create a droplet”.

There are many droplet options. DigitalOcean allows you to build a droplet based on one of several operating system, but they also have pre-built server images with pre-installed software. These are called “one click apps”. For Koken, I use LAMP on 14.04. This is an Ubuntu version 14.04 Linux image with Apache, PHP, and MySQL installed and ready to go. There is a LAMP 16.04 image as well, but it includes PHP7, which is supposed to be compatible with Koken, but I’ve had trouble getting it to work. Stick with 14.04 for now.

Once you chose your LAMP droplet, you can pick the size. I usually chose the smallest server, which is $5 per month. It’s probably all you need, but you can upgrade it later. It’s harder to downgrade, so start with the small one. You also need to pick a datacenter. They will all work just fine, but pick the one closest to you.

DigitalOcean now offers block storage, which allows you to add disk space to existing servers. That way you can add more disk space without paying for a more powerful server. Block storage currently only works in select datacenters, so chose one of those if you think you’ll need more storage in the future.

The only other option you should be worried about is backups. DigitalOcean will create weekly backups of your server and store the last 4 for a 20% surcharge. Do this. Always do this. Now give your server a name (I usually just use my domain name), and hit create. Sit back for at most one minute, and your server will be created and ready to go. That’s it. You now have your own server with its own IP address. Magic.

Now go back to Hover (or your terrible domain registrar if you didn’t use Hover). You need to take the IP address for your new server, and enter it as an A Record in your DNS settings. On Hover, this is easy. Just go to the DNS tab for your domain. Click add new. Enter “@” for host name (This means the root domain will point to your new server. If you want to use a subdomain, enter the subdomain here). Enter “A” for the record type. Enter your DigitalOcean server IP for the IP Address. You’re done. Your domain should now (or soon) point to your new server. You should see a defult Apache welcome page if you put it in a browser.

The Dirty Work

Ready for some terminal fun? Hopefully you’ve used the terminal before. If not, don’t worry, you’ll be fine.

For my example, I’ll use the domain http://koken.rocks so, I will use that domain in the rest of the examples. Use yours in its place – obviously.

Log in to your fancy new server. From your terminal enter this:

ssh root@koken.rocks

Set up MySQL. DigitalOcean put the default MySQL admin password in a text file in your server home directory. We need to get it. This command will open the file with the password

nano ~/.digitalocean_password

Copy the password in the file, and close the file (CTRL-X). With the password copied to your clipboard, or a text file, run this command to set up MySQL. This will give you options to lock down your database installation, and help protect your server from attacks.

sudo mysql_secure_installation

Once that is done, we log into MySQL to create the database for Koken. You’ll be prompted for your MySQL password.

mysql -u root -p

Create the database (this can be called whatever you want)

CREATE DATABASE koken;

Create a user. You’re currently using the root user, but this is a user that only has access to the Koken database. The username and password can be anything you like. But copy them down somewhere. You’ll need them again.

GRANT ALL PRIVILEGES ON koken.* TO 'k_user'@'localhost' IDENTIFIED BY 'KOKEN_PASSWORD';

FLUSH PRIVILEGES;

That it for MySQL. If everything goes well, you’ll never need to touch this database again.

Now for some changes to our PHP settings. PHP is already installed on your server, but there are a few package additions and updates you need to make in order for Koken to work. Run these commands:

sudo apt-get update

sudo apt-get -y install zip unzip php5-fpm php5-cli php5-imagick php5-mysqlnd php5-curl php5-mcrypt

sudo php5enmod mcrypt

Apache. Now we create a website. We need to set up a new web root for Koken, and create a VirtualHost to link your domain to your site. Remember to replace the bold text with your site’s domain.

sudo mkdir -p /var/www/koken.rocks/public_html

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/koken.rocks.conf

Next, we need to edit the config file for your site. Run the next command to open the file in a text editor.

sudo nano /etc/apache2/sites-available/koken.rocks.conf

Copy the following into the file. You can delete what’s already in the file.


ServerAdmin webmaster@localhost
DocumentRoot /var/www/koken.rocks/public_html/
ServerName koken.go
  koken.rocks/public_html/>
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
  DirectoryIndex index.php
  
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Hit CTRL-X to exit the text edit. Hit “Y” to save your changes and enter the following command to enable the new site.

sudo a2ensite koken.rocks.conf

Let’s encrypt this site, shall we? Encryption used to be just for sites that offered financial transactions of some sort. Now it’s a good idea for every site. This step is certainly optional, but I recommend it. SSL certificates used to be a pain, and cost money. Now they’re easy and free, thanks to Let’s Encrypt. Google is starting to give better ranking to sites that use https over http, so that’s reason enough to use encryption. Also, if you ever want to start selling your photographs, SSL encryption is required by almost all credit card transaction plugins. These steps will get your site’s SSL certificate installed. Remember, once again, to replace the bold text with your domain. The last command will trigger some prompts that you need to answer. I recommend directing all traffic to your https site. It’s best to have one URL for search engine rankings.

cd /usr/local/sbin

sudo wget https://dl.eff.org/certbot-auto

sudo chmod a+x /usr/local/sbin/certbot-auto

certbot-auto --apache -d koken.rocks

Your certificate is now installed, but these free certificates expire every three months. Thankfully, there’s a way to renew them automatically! open your crontab (where your server keeps a list of scheduled jobs) with this command. It will ask you to choose a text editor (I use nano).

sudo crontab -e

Paste the following line to the end of the file.

ADD —> 30 2 * * 1 /usr/local/sbin/certbot-auto renew >> /var/log/le-renew.log

That’s it. You’re practically a hacker now.

Now we get and install Koken. The next few commands will download the Koken installer, unzip it, and update the directory permissions to allow the self-installer to run.

cd /var/www/koken.rocks/public_html/

wget -P . https://s3.amazonaws.com/install.koken.me/releases/Koken_Installer.zip

unzip Koken_Installer.zip -d .;cp Koken_Installer/koken/* .;rm Koken_Installer -r;rm Koken_Installer.zip;chmod 777 -R ../public_html/

All done on the server side. Time to load the site, where you can finish the configuration in your browser. Just visit your site and you will be walked through the basics. The first thing you’ll need is the database username and password you set up earlier. After setup, many more settings are available in the admin section of your site.

Koken offers several built-in themes to choose from, and enough flexibility to create a great showcase for your photos.

Extra DigitalOcean Tip

Use SSH keys to access your droplet. You can just use a username/password to log into your DigitalOcean server, but it’s easy and safer to use SSH keys. To set up SSH keys, follow these guides for macOS or Windows.