/ how-to

Setting Up My Blog With Ghost

First I went with siteground shared hosting which was a bad idea from the start but after a few days they took away Ghost from Softaculous in the cPanel, ended up getting a refund and decided to try [vultr](http://www.vultr.com/?ref=7149731" target="_blank) for a change since I have heard good things about them in the past.

I signed up for vultr and within minutes i had deployed a server which has a very simple setup interface where you get to pick the location of the server, the OS which i used Ubuntu 17.04 for this server, server size which i picked the $5 plan, for some reason it the $2.50 plan was temporary sold out and also setup my ssh key for the server, it takes a few mins for the server to set it's self up.

After the server is setup, you can click on the server under the servers page which will bring you to a overview page and it will have your username and password, ip address that is needed to login to Putty to access the server.

After we logged in using putty we firstly updated the server:

sudo apt-get update
sudo apt-get upgrade -y

Next i Install Let's Encrypt so we can enable secure HTTPS connections:

apt install -y letsencrypt

Now i had to get a cert for this site:

letsencrypt certonly -d mydomain.com -d www.mydomain.com --email youremail@mail.com --agree-tos --standalone

Next i installed nodeJS which is needed for Ghost, Node v4 argon LTS is the recommend version for ghost and also install npm.

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
apt install -y nodejs
npm install --production

Next we will setup our web server for ghost, we will use nginx which i find easier to setup than Apache.

sudo apt-get install nginx
service nginx start

To make ghost available on 80 and 443 for https we use nginx reverse proxy to do this.we create the file below to do this.

nano /etc/nginx/conf.d/ghost.conf

and within this file paste the below:

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name yourdomain.com www.yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourdmain.com/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://127.0.0.1:2368;
    }
}

restart nginx for this to take effect:

service nginx restart

Now we will install ghost its self. Firstly we will create a new user on the server called ghost(or whatever you want) and switch to that user.

adduser ghost
su - ghost

We create the default folder where ghost will be downloaded and installed to, after we delete the zip that we used to install ghost as its not needed anymore.

sudo mkdir -p /var/www/
cd /var/www/
sudo wget https://ghost.org/zip/ghost-latest.zip
sudo unzip -d ghost ghost-latest.zip
cd ghost/
sudo npm install --production
rm ghost-latest.zip

Now we can config ghost:

sudo cp config.example.js config.js
sudo nano config.js

inside this file i needed to change the url under production to my domain blog domain name.

config = {
// ### Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
    url: 'https://example.com',
    ...
}

after saving this we can start ghost with the following command

npm start --production

Now we need to make ghost run 24/7 because at the moment if you close the current session your blog will stop working. To keep ghost always running we can use forever.The below installs and then starts ghost.

npm install -g forever
NODE_ENV=production forever start index.js

My last step was to point my domain from namecheap to vultr name servers.

ns1.vultr.com
ns2.vultr.com

after doing this i needed to go to vultr and after logging in i went to DNS tab where i added my domain name.

Now my Ghost blog is all setup and ready to go :)