Hosting a Ghost Blog on Laravel Forge

I was looking for a way to deploy my blog and noticed there was no much documentation anywhere about deploying a Ghost blog on Laravel Forge.
So I thought I will have a walkthrough of deploying a new blog.

For this article I assume you know the basic setup of a server on the forge, and familiar with the command line tools.

1. Create a new Server

I prefer Digitalocean, but you can choose a provider you're familiar with.
Once the server is set up, you should have received the Sudo password of the server and Database server. Keep this for later use.

While your server is provisioning, you can take your newly assigned IP address and point your domain to the server.

Once the server is provisioned, we can move ahead with the blog.

2. Nginx and SSL

We will install Ghost blog using ghost-cli but we will do it later.
Let's make sure the site is live by going to the domain on a browser.

If the site is up and running we can continue setting up SSL for the site.

Screenshot-2020-08-14-at-20.08.05

Click SSL tab in the forge site panel, then click Let's Encrypt, and click Obtain Certificate to get a SSL certificate.

When the certificate is generated, activate and visit the site via https.
If you can reach successfully, we. Can go ahead with the next step.

Screenshot-2020-08-14-at-20.08.51

At the bottom of each page under your site there is an Edit Files button, click that then Edit Nginx Configuration.

This Is the config. For the. Server we are setting:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com;
    root /home/forge/example.com/ghost/current;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/example.com/228707/server.crt;
    ssl_certificate_key /etc/nginx/ssl/example.com/228707/server.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-FCM-SHA128:ECDHE-ECDSA';
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/example.com-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Make the 4 following changes

Find and update the index line to this

index index.js index.html index.htm index.php;

Remove location block

location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

Update error page

error_page 404 /index.js;

Replace php block with node server block

location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
 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;
    }

Save the config file and reload the nginx service.

3. Database

Log in to the server with your database tool, and create a. Database with
using utf8mb4 and utf8mb4_unicode_ci,

CREATE DATABASE ghostblog CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;

4. Connect to the server

Now connect to the server via ssh and setup th ghost service.

$ ssh [email protected]_ADDRESS

5. Installing Node.js Using NVM

Install Node.js using a tool called nvm, which stands for “Node.js Version Manager”. Rather than working at the operating system level, nvm works at the level of an independent directory within your home directory. This means that you can install multiple self-contained versions of Node.js without affecting the entire system.

To download the nvm installation script from the project’s GitHub page, you can use curl:

$ curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh -o install_nvm.sh

$ bash install_nvm.sh

$ source ~/.profile

$ nvm ls-remote

Install the lts version of Node.js to be used

$ nvm install 12.18.3

$ nvm use 12.18.3

$ node -v

6. Installing Ghost

Follow the steps below to install the ghost-cli and install the blog:

$ sudo npm i -g ghost-cli
install ghost-cli
$ cd example.com

$ ls -a

$ sudo rm -rf ghost
navigate into the blog directory and remove existing folder
$ mkdir ghost && cd ghost

$ ghost install

During the installation you will be prompted for the following (I've written the answers as well for this install)

Enter your blog URL: http://example.com
Enter your MySQL hostname: 127.0.0.1
Enter your MySQL username: forge
Enter your MySQL password: [Forge created Database password]
Enter your Ghost database name: ghostblog

# DO NOT SET UP NGINX
# Answering no will skip the SSL set up as well
Do you wish to set up Nginx? n

# DO NOT SET UP GHOST MYSQL USER
Do you wish to set up "ghost" mysql user? n 

# SAY YES TO SYSTEMD
Do you wish to set up Systemd? Y

Do you want to start Ghost? Y

Now the site will be live.

Show Comments