Skip to content

Instantly share code, notes, and snippets.

@esurdam
Last active September 26, 2016 15:37
Show Gist options
  • Save esurdam/2c3f101f33c99a95ec5db444be26e943 to your computer and use it in GitHub Desktop.
Save esurdam/2c3f101f33c99a95ec5db444be26e943 to your computer and use it in GitHub Desktop.
Install Ghost on CentOS/Amazon Linux AMI

Install Ghost on CentOS/Amazon Linux AMI

Thanks to: https://www.rosehosting.com/blog/install-ghost-with-nginx-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.

Prep 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 vim

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

yum install epel-release -y

Now install Node.js and npm:

yum install nodejs npm --enablerepo=epel

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

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

Install Ghost

First, create a directory for your Ghost website:

mkdir /sites/your_site
cd /sites/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 it
rm ghost.zip

Now install the app with the npm installer:

npm install -production

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:

vim 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

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

# vim /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.

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

# nginx -t

# service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment