We are all about efficiency as developers. Why hammer commands line after line into the terminal when you can write code to do it for you? As I setup this Ghost-powered blog, I set out to document down this process as repeatable code.
Ansible is a really good tool to add to your arsenal if you haven't. It lets you use code to run a set of tasks on your VPS/EC2. Instead of staying put in front of the screen issuing out commands, you run your Ansible script and go for a jog instead.
- EC2 instance or VPS
- Ansible installed on your local machine
- A domain name
- SSL certificate
- Clone my Ansible Ghost blog script into your local machine
- Edit hosts file and replace
[YOUR_DOMAIN_NAME](lines 10, 11, 16,)
- Copy your SSL Certificate and key to
- Run this Ansible playbook on your local machine:
- SSH into your remote server and finish setting up MySQL by following the prompts:
sudo apt-get install mysql-server
- During the MySQL install, select no when asked if you want to enable the validate password plugin. It causes some problems with MySQL 5.7 apparently.
- Set up ghost by going to
- During the ghost install script, when prompted whether you want to set up Nginx and SSL, answer 'N'.
What's Going On
Let's look at what's going on in the Ansible playbook script when it's run.
- import_tasks: swap.yml
This runs the commands defined in swap.yml, which sets up a 1gb swap (I'm using a 512mb droplet). Disable if you don't want swap.
- name: 'Upload nginx site config'
template: src=nginx.conf.j2 dest=/etc/nginx/sites-enabled/ghost
We copy our own nginx.conf in the templates folder to our server. This is why we don't want ghost to set up the Nginx scripts for us.
- name: 'Upload SSL certificate'
- name: 'Upload SSL certificate key'
Copies our SSL cert and private key to our server.
- name: Install mysql-server
apt: name=mysql-server state=present
- name: Install nodejs
shell: curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -; sudo apt-get install -y nodejs
- name: Install ghost-cli
command: npm i -g ghost-cli
- name: Create ghost directory
command: mkdir -p
Installs MySQL, NodeJS, ghost-cli and creates the directory for your ghost installation.
After ghost-cli finishes the setup process, your blog is now viewable. Head to your blog URL and see if it's showing up fine.
With that, go to
yourblog.com/ghost where you'll be guided to finish up setting the first admin account. This is also the URL for your ghost admin panel.