Sharing or mostly documenting my experience(pain) hosting a Ghost Blog on a cPanel domain.
As you know, Ghost Blog runs on NodeJS, so you can't host it on a normal hosting service. You need a VPS. So for this, instead of buying a 15$/month VPS from my domain provider, I chose 5$/month from Amazon Web Services.

Requirements

  • Owning a domain or subdomain with cpanel
  • Git basic knowledge
  • Amazon Web Services basic knowledge
  • Linux basic knowledge

Downloading and setting up Ghost Blog Locally

  1. Downalod Ghost Blog here
  2. Unzip and using a Terminal Window, Navigate to the folder.
  3. Inside the folder run these commands:
    • npm install --production
    • npm start
  4. Edit the production part in the config.js file insde the root folder to something similar:

#

config = {
    production: {
        url: 'http://<IP_OF_AWS_SERVER>:2368',
        mail: {},
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            },
            debug: false
        },

        server: {
            host: '0.0.0.0',
            port: '2368'
        }
    }
}

Uploading to GitHub

Create a new repository on GitHub and commit all the files from the Ghost folder (except node_modules of course).

Setting up AWS EC2 Ubuntu Server

  1. Launch an AWS EC2 ubuntu Server instance and ssh into it.
  2. Install NodeJs:
  3. Git clone repository from GitHub
  4. Install and configure nginx to reroute the app to port 80
    • sudo apt-get install nginx
    • cd \etc\nginx\

#

server {
    listen 80;
    server_name <your site ip address>;
      location /
{         proxy_pass http://127.0.0.1:2368;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
}}

6. Install nginx

sudo apt-get install nginx

7. Setup nginx to redirect to port 80

server {
    listen 80;
    server_name <your site ip address>;
      location /
{         proxy_pass http://127.0.0.1:2368;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;

8. Install pm2 on ubuntu server

sudo npm install -g pm2

9. Use PM2 to run at startup

NODE_ENV=production pm2 start index.js --name "ghost"
pm2 startup
pm2 save
pm2 list
pm2 status

10. To make changes while live:

  • git push ...
  • git pull ...
  • pm2 restart

11. Change DNS from your domain to point to aws server ip address (can take 12-24 hours)

The Ghost Logo

back-up notes to update this post:
// 1. register and create droplet on DigitalOcean // 2. install node 6x compatible with ghost // curl -sL https://deb.nodesource.com/setup8.x | sudo -E bash - // sudo apt-get install -y nodejs` // 3. verify // node -v // 4. create /soft/ghost // mkdir soft mkdir ghost // 5. navigate to cd soft/ghost // 6. clone ghost repo // git clone https://github.com/muscaiu/ghost-blog.git // 7. cd ghost-blog // 8. npm i // 9. edit the config file, and modify the external ip // vim config.js // 10. HACK(for some reason need to install) npm install sqlite3 --save // 11. run in production // npm start --production // 12. install nginx to reroute the traffic from 2368 to 80 // apt-get install nginx // 13. Remove the default sites by removing the default file in /etc/nginx // sudo rm sites-enabled/default // 14. create new file in /etc/nginx/sites-available called ghost // sudo touch /etc/nginx/sites-available // sudo vim /etc/nginx/sites-available // 15. modify the servername part to your DO external ip adress: // In my case is: // server { // listen 80; // server_name http://159.65.198.56:2368;

// location / { // proxysetheader X-Forwarded-For $remoteaddr; // proxysetheader Host $httphost; // proxypass "http://127.0.0.1:2368"; // } // } // 16. symlink our configuration in sites-enabled: // sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ghost // 17. restart nginx // sudo service nginx restart // 18. install abd keep ghost running with pm2 // sudo npm install -g pm2 // 19. navigate to /soft/ghost and start
// NODE
ENV=production pm2 start index.js --name "ghost" // 20. add ghost to the pm2 startup list: // pm2 startup // 21. check if it was correctly added // 22. persist it to pm2 (save it) // pm2 save // 23. go to you cpanel zone editor and create a subdomain for you blog for ex: cristian.muscalu.net // 24. click manage and replace the ip for cristian.muscalu.net with the ip from DO // 25. wait up to 48 hours for dns change and check cristian.muscalu.net // 26. referal link : https://m.do.co/c/05441b4ae929