Install Ghost on CentOS 7

How to Install ghost on CentOS 7

We’ll show you, how to install ghost on CentOS 7. Ghost is a free and open source blogging platform written in JavaScript and built on Node.js, designed to simplify the process of online publishing for individual bloggers as well as online publications.

The Ghost user interface is very simple and straightforward making it great for beginners as well as advanced users.

Requirements

In this article we will install Ghost with Nginx on a CentOS 7 VPS. We will use our SSD 1 Linux VPS hosting plan with a clean CentOS environment which means that there is no PHP, Nginx and MySQL installed. We will only need PHP-FPM and Nginx for this tutorial, but you can also check out how to install a full LEMP stack on CentOS 7.

1. Update the System

As always, make sure your server is fully up-to-date. Also install unzip and a text editor of your choice. We will use nano:

# yum update && yum install unzip nano

2. Install EPEL Repository

Install the EPEL repository after which you will be able to install Node.js and npm:

# yum install epel-release -y

3. Install Node.js and npm

Now install Node.js and npm:

# yum install nodejs npm --enablerepo=epel

4. Install a Process Manager

Next, install a process manager so you can control your Node.js applications. This process manager will allow you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks. Enter the following command:

# npm install pm2 -g

5. Install Nginx and PHP-FPM

Your next step is to install Nginx and PHP-FPM along with some much needed dependencies:

# yum install nginx php php-fpm php-cli php-mysql php-curl php-gd

Start Nginx and enable it to start on boot:

# systemctl start nginx
# systemctl enable nginx

6. Install Ghost on CentOS 7

First, create a directory for your Ghost website:

# mkdir /var/www/html/your_site

Enter the newly created dir:

# cd /var/www/html/your_site

Download the latest Ghost version:

# curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip

Unzip the archive:

# unzip ghost.zip

Delete the archive:

# rm ghost.zip

Now install the app with the npm installer:

# npm install -production

7. Configure Ghost CMS

After the installation is completed, configure Ghost and update the URL in the config file with your domain. Copy the example config into a new file:

# cp config.example.js config.js

Open the file:

# nano config.js

Find the ‘Production’ section and update the URL with your domain. After modifying it should look like this:

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

Save and close the file.

Now you can use the process manager that we installed earlier to configure Ghost to run forever. Execute the below command:

# NODE_ENV=production pm2 start index.js --name "Ghost"

To start/stop/restart Ghost you can use:

# pm2 start Ghost

# pm2 stop Ghost

# pm2 restart Ghost

8.  Configure Nginx to Act as a Reverse Proxy

Your next step is to configure Nginx to act as a reverse proxy for your Ghost application. Open a config file:

# nano /etc/nginx/conf.d/your_domain.conf

Paste the following:

upstream ghost {
    server 127.0.0.1:2368;
}

server {
    listen      80;
    server_name your_domain;

    access_log  /var/log/nginx/ghost.access.log;
    error_log   /var/log/nginx/ghost.error.log;

    proxy_buffers 16 64k;
    proxy_buffer_size 128k;

location / {
        proxy_pass  http://ghost;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;

        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;
    }

}

Don’t forget to replace your_domain with your actual domain. Save and close the file.

9. Test and Restart Nginx Server

Test the Nginx configuration and restart Nginx so the changes can take effect:

# nginx -t

# service nginx restart

Congratulations, you have successfully installed Ghost on your CentOS 7 VPS. Now open your favorite web browser and navigate to http://your_domain/ghost and create an admin user.

For more information about how manage your Ghost blog, please refer to the their website.

Of course you don’t have to install Ghost with Nginx on CentOS 7, if you use one of our Optimized CentOS 7 Hosting services, in which case you can simply ask our expert Linux admins to install Ghost with Nginx on CentOS 7 for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post in how to install Ghost with Nginx on CentOS 7, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

3 thoughts on “Install Ghost on CentOS 7”

  1. Why am i getting a 502 error when i try to access my blog?
    here is my conf file:

    upstream ghost {
    server 127.0.0.1:2368;
    }

    server {
    listen 80;
    server_name blahblah.com;

    access_log /var/log/nginx/ghost.access.log;
    error_log /var/log/nginx/ghost.error.log;

    proxy_buffers 16 64k;
    proxy_buffer_size 128k;

    location / {
    proxy_pass http://ghost;
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
    proxy_redirect off;

    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;
    }

    }

    Reply
    • This is pretty common error, most likely generated by the PHP or FastCGI buffer and timeout settings.

      You may check the /var/log/nginx/ghost.error.log error log for details.

      Reply

Leave a Comment