Install Ghost with Nginx and MySQL

The steps I installed Ghost blog on Linode with Debian 7.5

Prepare

1
2
3
apt-get update
apt-get upgrade
apt-get install -y build-essential

Installing Nginx

1
apt-get install nginx

Install Node.js

Based on here

Setup with Debian (as root):

1
curl -sL https://deb.nodesource.com/setup | sudo bash -

Then install with Debian (as root):

1
apt-get install -y nodejs nodejs-legacy

Install MySQL

1
apt-get install mysql-client mysql-server

Secure MySQL

1
mysql_secure_installation

Restart MySQL

1
/etc/init.d/mysql restart

or

1
service mysql restart

Using MySQL mysql -u root -p to setup database:

1
2
3
4
5
6
7
CREATE DATABASE YOUR_DATABASE;

CREATE USER 'YOUR_USERNAME' IDENTIFIED BY 'YOUR_PASSWORD';

GRANT ALL PRIVILEGES ON YOUR_DATABASE.* TO 'YOUR_USERNAME';

exit

Install Ghost

Based on here

created /var/www/ghost as ghost folder

1
2
3
4
5
mkdir -p /var/www/
cd /var/www/
curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip
unzip -uo ghost.zip -d ghost
cd /var/www/ghost

Then setup ghost environment

1
2
3
npm install --production
npm install mysql
npm install forever -g

Setup Ghost

Copy over the example config file and then edit it

1
2
3
cp config.example.js config.js

vim /var/www/ghost/config.js

Change production default url to your domain and setup MySQL database

1
url: 'http://YOUR_DOMAIN',
1
2
3
4
5
6
7
8
9
10
database: {
client: 'mysql',
connection: {
host: 'localhost',
user: 'YOUR_USERNAME',
password: 'YOUR_PASSWORD',
database: 'YOUR_DATABASE',
charset: 'utf8'
}
},

Run Ghost as background process

Fix all permission

1
chown -R www-data:www-data /var/www/ghost

Then run ghost as background process by forever (you can find other deply methods in here)

1
NODE_ENV=production forever start index.js

Setup Nginx

1
vim /etc/nginx/sites-available/ghost
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
server {
listen 80;

server_name example.com www.example.com;

location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;

proxy_pass http://127.0.0.1:2368;
}
}

Enable this site

1
ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ghost

Restart nginx

1
/etc/init.d/nginx restart

Open Ghost

Now you can check http://YOUR_DOMAIN to see ghost in there.

Login http://YOUR_DOMAIN/ghost to setup your account.