Install Ghost on Plesk server
Installation CMS Ghost

Install Ghost on Plesk server

Mishel Shaji
Mishel Shaji

Introduction

Ghost is an Open Source publishing platform built on modern technology stack NodeJS. This makes the Installation of Ghost a little complicated. On the other hand, CMS like WordPress and Joomla is built using PHP which makes its installation much easier. You will also find many web hosting providers offering One-click installation for such CMS.

In this post, we'll see how to install Ghost 2x manually with Plesk Onyx. I assume that you have SSH access to your server.

Prerequisites

  • A server running on Ubuntu 16. 04 or newer.
  • SSH access.
  • An account with root privileges.
  • At least 1 GB of memory.

Setting up server

If you are using Plesk, you can skip these steps because Plesk automatically installs MySQL and Nginx on your system.

Creating a new user

To create a new user, login using SSH and run the following command. You can use PuTTY or SmarTTY ( I'm using this ) as your SSH client app.

adduser <username>

Replace <user> with a username. Eg: adduser ghostuser

Never choose ghost as the username.

Now you will be asked to enter a password for the user. Remember to choose a strong password.

Next, we're adding our new user to superuser group to unlock admin privileges.

usermod -aG sudo <username>

Now, login as the new user.

su - username

Install Nginx, NodeJS and MySQL

Ghost needs MySQL and Nginx and NodeJS to work. But we need not install Nginx and MySQL because Plesk might have already installed them.

Run this command to install NodeJS on your machine.

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

Verify the installation by running:

node --version
# and 
npm --version

Install Ghost CLI

Ghost CLI is a command-line application that helps you to install and manage your Ghost installation.

sudo npm install ghost-cli@latest -g

Now we've set up our server to install our Ghost blog.

Installing Ghost

By default, Ghost uses SQLite as the database. However, MySQL is faster and reliable than SQLite. So, it is good to use MySQL instead of SQLite.

If you have hosted other websites on your server, It is good to create a new user and database for the Ghost blog.

Step 1 : Setting up Domain and Database

We can create a new MySQL user from the terminal. But if you create it with Plesk, it will be easy for you to manage and backup your database from Plesk dashboard. So,

  • Login to your Plesk control panel.
  • Go to Websites and Domains and click ➕ Add Domain to add a domain and web space. Make sure that you have selected Secure the domain with Let's Encrypt. If you have already had a domain, you can skip this step.
  • Then, go to Databases and create one for your blog.

Step 2 : Install and configure Ghost

If you have created the database and set up your domain, follow the steps below to install Ghost.

  • Login to your server using SSH.
  • Login as the new user using su - username command.
  • Create a directory for installing Ghost.
sudo mkdir /var/www/ghost
  • Set the new user as the owner of the directory.
sudo chown username:username /var/www/ghost
  • And set appropriate permission for it.
sudo chmod 775 /var/www/ghost
  • Navigate to the directory.
cd /var/www/ghost
  • Now, install Ghost using the following command.
ghost install

The setup will ask you a couple of questions. Answer them and hit enter.

  1. Blog URL - Provide the URL of your blog here. Eg: https://www.myghostblog.com
  2. MySQL hostname - Host name of your database. In most cases, it will be localhost. If the host name is localhost ( set by default ), simply hit Enter.
  3. MySQL username - Username of the database user. (Use the same one you created in the Plesk admin panel).
  4. MySQL password - Password to connect with the database. (Use the same one you created in the Plesk admin panel).
  5. Database name - Database name of your Ghost blog. (Use the same one you provided in the Plesk admin panel).
  6. Set up NGINX? (Recommended) - Type n and hit Enter.
  7. Set up SSL? (Recommended) - Skipped
  8. Set up systemd? (Recommended) - Type y and hit Enter.
  9. Start Ghost? - Type y and hit Enter. This will start your Ghost site.
The site is not yet ready. If you try to access the blog, you will get an Nginx Bad Gateway page.

Step 3 : Set up a reverse proxy

By default, Ghost listens on port 2368. So we need to forward the requests from Nginx to Ghost.

Note: This step includes making modifications to your Nginx configuration file. I advise you to take a copy of the configuration file before modifying it.
  • Login using SSH as the root user or the default user.
  • Navigate to the folder where configuration files are stored.
cd /var/www/vhosts/system/yourdomain.com/conf

Replace yourdomain.com with your domain name. For example, if the domain name is www.myghostblog.com, type cd /var/www/vhosts/system/myghostblog.com/conf

  • Open nginx.conf.
nano nginx.conf

You can use any editor of your choice. If you are using SmarTTY, simply double-click on nginx.conf in the list on the left side of the window to edit the file and use Ctrl + S to save the file  after making changes.

The configuration file will look similar to the one shown below.

#ATTENTION!
#
#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.

server {
	listen ***.***.***.***:*** ssl http2;

	server_name yourdomain.com;
	server_name www.yourdomain.com;
	server_name ipv4.yourdomain.com;

	ssl_certificate             [some location generated by plesk];
	ssl_certificate_key         [some location generated by plesk];
	ssl_client_certificate      [some location generated by plesk];

	client_max_body_size 128m;

	root "/var/www/vhosts/yourdomain.com/httpdocs";
    
	# Code removed for brevity

	#extension letsencrypt begin
	location ^~ /.well-known/acme-challenge/ {
		# Code removed for brevity
	}
	#extension letsencrypt end

	location / {
		proxy_pass http://127.0.0.1:****;
		proxy_set_header Host             $host;
		proxy_set_header X-Real-IP        $remote_addr;
		proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_set_header X-Accel-Internal /internal-nginx-static-location;
		access_log off;
	}

	location /internal-nginx-static-location/ {
		# Code removed for brevity
	}

	location ~ ^/(plesk-stat|awstats-icon|webstat|webstat-ssl|ftpstat|anon_ftpstat) {
		proxy_pass http://127.0.0.1:****;
		proxy_set_header Host             $host;
		proxy_set_header X-Real-IP        $remote_addr;
		proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_set_header X-Accel-Internal /internal-nginx-static-location;
		access_log off;

	}

	add_header X-Powered-By PleskLin;

}

server {
	# Code removed for brevity
}
nginx.conf
  • Now we're going to make changes to this file to make Nginx forward the requests to Ghost.
  • Modify all the occurrence of the line proxy_pass http://127.0.0.1:****; as proxy_pass http://127.0.0.1:2368;
  • Add the following line to location / { block.
proxy_set_header X-Forwarded-Proto https;

It is important to add this line. If not set, you will get a redirection error from the browser.

Complete code:

#ATTENTION!
#
#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.

server {
	listen ***.***.***.***:*** ssl http2;

	server_name yourdomain.com;
	server_name www.yourdomain.com;
	server_name ipv4.yourdomain.com;

	ssl_certificate             [some location generated by plesk];
	ssl_certificate_key         [some location generated by plesk];
	ssl_client_certificate      [some location generated by plesk];

	client_max_body_size 128m;

	root "/var/www/vhosts/yourdomain.com/httpdocs";
    
	# Code removed for brevity

	#extension letsencrypt begin
	location ^~ /.well-known/acme-challenge/ {
		# Code removed for brevity
	}
	#extension letsencrypt end

	location / {
		proxy_pass http://127.0.0.1:2368;
		proxy_set_header Host             $host;
		proxy_set_header X-Real-IP        $remote_addr;
		proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
		proxy_set_header X-Accel-Internal /internal-nginx-static-location;
		access_log off;
	}

	# Code removed for brevity

}

server {
	# Code removed for brevity
}
  • Save the file and restart Nginx.
service nginx restart
  • Visit https://www.yoursite.com/ghostto create an admin account and finish the installation.

via GIPHY