From nothing to Ghost in 5h. Only !

As my friend Pierre decided to start a blog I thought why not creating mine too ?

That's how I started my evening yesterday.

Hosting

I had a vps sleeping for almost a year somewhere in the OVH infrastructure. It was time to wake it up !

I reinstalled a brand new Ubuntu 16.10 on it, and spent almost 20min trying to create and add my ssh key on it (few errors like typo in file path help the process taking longer).

Generate a new key:

touch ~/.ssh/my_key  
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"  

Now you should change rights on both mykey and mykey.pub :

sudo chmod 600 ~/.ssh/my_key  
sudo chmod 600 ~/.ssh/my_key.pub  

To send the key to the server, there is a very useful command (thanks @Pierre):

ssh-copy-id -i ~/.ssh/my_key.pub [your_login]@[your_server_address]  

Now you should be able to ssh your server without typing your password :)

Node

Every single time I want to install node.js I end up on the source page. I don't want the sources U_u. I just want the tiny line of code that will install node in a simple copy & paste... but the Grail is hidden.
See ?? I had to put the browser in full screen to actually see the link without scrolling :(

So here it is:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -  
sudo apt-get install -y nodejs  

Ghost

Nice ! The server is now up and running, let's install Ghost ! Easy stuff. On the Ghost github, we are redirected to the LTS branch where the following instructions are given:

  • Download the latest release of Ghost
  • Unzip in the location you want to install
  • Fire up a terminal
  • npm install --production
  • Start Ghost!

Let's try out !!

...

...

French

Meh.

F5 ?
No...
Nmap ?
Nothing on port 2368...

[insert a 2h gap]

Well well. I save you from my hazardous research but the result is to change the ghost/config.js file and replace the loopback address by your public address:

[...]
production: {  
        [...]
        server: {
            host: '51.255.171.158',
            port: '2368'
        }
[...]

Yeah ! :D

Systemd

Now I want to automatically start my node server when the server boots and restart it if it crashes. To do so I created the following ghost-blog.service file in /etc/systemd/system/:

[Unit]
Description=My Ghost blog :)

[Service]
Type=simple  
ExecStart=/usr/bin/node index --production  
WorkingDirectory=/home/henri/ghost  
Environment=NODE_ENV=production  
Restart=always

[Install]
WantedBy=multi-user.target  

Then type the following command to get it running:

systemctl enable ghost-blog.service  
systemctl start ghost-blog.service  

You can stop or restart the server with systemctl stop/restart ghost-blog.service.

There you go ! Just create your account by going to any route except the index / of your site and you will be redirected to the setup page ;)

In conclusion, a very simple task "setting up a ghost blog from scratch" took me almost 3/4 hours with all the little troubleshooting here and there. I hope this article will save you (certainly my future me when I'll have to do it again) some time !

The End.