Official Power Up Hosting Blog

Everything about Linux, Windows, and hosting ;)

Selvakumar
Author

I am an Online Marketer and technology lover. I like to learn new things and share that with people.

Share


Our Newsletter


Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Tags


Twitter


Official Power Up Hosting Blog

(Learn) How to Install Ghost Blogging CMS on Ubuntu 16.04

SelvakumarSelvakumar

Ghost is one of the best open source CMS available. Ghost is mostly used for the blogging platform and it is very simple to use.

There are a lot of themes available for the ghost so that customizing the ghost will be very easy for you.

Ghost is very fast in loading. If you have many images to post on the site, Ghost will give you minimal loading speed at the user end. It is almost 110% faster than WordPress.

Here, let us see how to install ghost on Ubuntu 16.04 server. Before that let us see the required things to install the Ghost.

If you want to know how to install Ghost CMS on CentOS refer here

We will be using install Ghost Ubuntu command lines for this purpose.

Prerequisites:

  • Ubuntu 16.04 server with sudo non root user and configured with the initial server setup guide.
  • The server should have node.js installed.
  • The server also should have nginx installed.

Step 1: Installing Ghost CMS

Now:

We are going to install the Ghost at /var/www/ghost directory. This is the recommended location to install ghost.

First, download the ghost package from the Github's official repository using wget command.

wget https://ghost.org/zip/ghost-latest.zip

We have to unzip the compressed package so that we have to install the unzip program in Ubuntu. Let us install the unzip program first.

$ sudo apt-get install unzip

Here after just unzip the downloaded ghost packages using the utility.

$ sudo unzip -d /var/www/ghost ghost-latest.zip

The unzipped file will be stored at the /var/www/ghost directory.

Now move to the /var/www/ghost directory to install the ghost dependencies.

$ cd /var/www/ghost/

Only install the dependencies which is required for the production. This will skip installing other dependencies which are used by the ghost developers.

$ sudo npm install --production

That's all.

Now:

The ghost is installed on your site. The next step is to setup the ghost before starting it.

Step 2 - Configuring Ghost

There is a configuration file for ghost to use located at /var/www/ghost/config.js. The installation of Ghost also includes config.example.js.

The first step is to copy the example configuration file to the /var/www/ghost/config.js

We just have to copy the example.js file to /ghost.config.js file. Just avoid moving the file. Because, if you want to revert the changes in the configuration file, you can just the copy the original configuration file to the folder.

Here is the command to copy the file

$ sudo cp config.example.js config.js

Now, open the file to edit it(Since we need to make some changes in the configuration file)

$ sudo nano config.js

Ghost is using its own URL. We have to change that first. Otherwise, the link in the ghost blog will redirect to my-ghost-blog.com.

In that file, check the URL and replace it with your domain URL or use your IP address (If you don't want to use the domain).

The file will look like the one in below

              /var/www/ghost/config.js

...

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

Be careful while replacing the URL. Put http://yourdomain.tld or http://ipaddress. If the format is not right, Ghost wont start.

In the above code, the TLD can be (.com, in, .us, .sg, etc).

Ghost can work without the email settings. But if you need it for the ghost users to recover the password, you should configure it.)

Here is the more detail about customizing ghost in their official site.

Save the file and exit the editor.

Now, you have to start the ghost using the following command.

$ sudo npm start --production

The output will look like this.

Output

> ghost@0.11.7 start /var/www/ghost
> node index

WARNING: Ghost is attempting to use a direct method to send email.
It is recommended that you explicitly configure an email service.
Help and documentation can be found at http://support.ghost.org/mail.

Migrations: Creating tables...
...

Ghost is running in production...
Your blog is now available on http://your_domain_or_ip_address
Ctrl+C to shut down

Ghost listens to the port 2368. If you enabled the UFW firewall, The ghost won't work.

Here our next task is to configure Nginx for ghost.

Step 3- Configuring Nginx

Here, you have to setup Nginx in front of ghost redirect the request from port 80 to the port to which the ghost is listening to.

So, people don't need to add :2368 at the end of URL to access the ghost. It helps you in redirecting to the user to your blog when it is growing large.

if the ghost is running on your machine, Press CTRL+C to shut down the ghost instance.

Let us configure the Nginx now.

go to /etc/nginx directory. Then remove the default ninginx configuration file /etc/nginx/sites-enabled.

$ cd /etc/nginx/
$ sudo rm sites-enabled/default

Create a new file:

$ sudo nano /etc/nginx/sites-available/ghost

Add the following code in the configuration file.

Replace domain name with your domain name or IP address of your server.

/etc/nginx/sites-available/ghost
server {
listen 80;
server_name your_domain_or_ip_address;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass         http://127.0.0.1:2368;
}
}

This configuration sends all visitors to your ghost blog running on Port Number 2368. They also set correct http headers so that you can see the visitors IP address at Ghost log.

Now:

Save and exit the file. To enable the configuration create a sim link at /etc/nginx/sites-enabled.

$ sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ghost

After that, test the configuration.

$ sudo nginx -t

You will get the following output

Output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If there is any errors, just fix the issue and check it again.

If there is no error, then start the Nginx using the following command.

$ sudo service nginx restart

Before starting the ghost, let us create user and the ghost.

Step 4 Running the Ghost

To enhance the security of ghost, we are going to run the ghost under the separate user name.

The user will only have access to /var/www/ghost and its home directory.

So, the user is restricted to a certain limit. This will avoid heavy damage to the server.

Now, create a new ghost user, using the below command.

$ sudo adduser --shell /bin/bash --gecos 'Ghost application' ghost

After that, make this new user as the owner of /var/www/ghost/

$ sudo chown -R ghost:ghost /var/www/ghost/

Now we have to make this user able to run the ghost. Login as a ghost.

 $ su - ghost

Start the ghost to run under the user and make sure it runs.

$ cd /var/www/ghost
$ npm start --production

Now, you should be able to access your ghost blog through http://your_ip_address.

It should work now. Though we have to ensure that the ghost will run after this.

Step 5- Running Ghost as a system Service

The ghost is running in our terminal. but once you exit the terminal the blog won't work.

To make the ghost automatically starts running after every restart of the system, you have to create a systemd unit which specifies how systemd should manage ghost.

Create a new file which will hold the systemed unit.

$ nano /etc/systemd/system/ghost.service

Add the below codes to the configuration file.

These codes define the service's name, the group and user, the service for the user and the instruction about how the ghost should start.

/etc/systemd/system/ghost.service
[Unit]
Description=Ghost
After=network.target

[Service]
Type=simple

WorkingDirectory=/var/www/ghost
User=ghost
Group=ghost

ExecStart=/usr/bin/npm start --production
ExecStop=/usr/bin/npm stop --production
Restart=always
SyslogIdentifier=Ghost

[Install]
WantedBy=multi-user.target

Now, just save the file and exit. After that make sure enable the service and start it.

$ systemctl enable ghost.service
$ systemctl start ghost.service

Check your blog again by visiting http://your_ip_address. Now you should see your blog.

Conclusion:

In this tutorial you have learned

  • How to install Ghost
  • How to configure ghost Nginx to send the request to ghost
  • Make sure that the ghost is running as a system service

Ghost is a fast loading CMS at the user end. It is very simple to use. So, Now start use the ghost. For ghost mailgun is the preferred mailing software.

Ghost blog install process is made easy now. Whenever you upgrade ghost, just remember to restart ghost.

If you have any doubt regarding configuration of ghost, please let us know in the comment.

Selvakumar
Author

Selvakumar

I am an Online Marketer and technology lover. I like to learn new things and share that with people.

Comments