Summary
ghost is an open source blog platform based on nodejs
There are many articles about ghost blog deployment, including ghost Chinese network. There are many ways to deploy ghost blog. But I think the most convenient way is to deploy ghost with ghost_cli. ghost-cli is a new tool after version 1.0. Simply put, it can help us install, start, upgrade and manage our ghost-blog more easily.
Here's how this deployment works
system requirements
Here are the official requirements for the system and system environment
- Ubuntu 16.04
- MySQL
- NGINX (minimum of 1.9.5 for SSL)
- Systemd
- Node v6 installed via NodeSource
- At least 1GB memory (swap can be used)
- A non-root user for running ghost commands
Installation and deployment
Because the official recommendation of using Ubuntu 16.04, so my system is also Ubuntu 16.04, you'd better be the same as me.
User settings
For security reasons, it is recommended to use non-root users to manage ghost blogs, so it is recommended to create a new account specifically for ghost management.
sudo adduser ghost
Add this user to the sudo user group to give it permission to use sudo
sudo usermod -aG sudo ghost
Log in as ghost user
su - ghost
Update the system
sudo apt update && sudo apt upgrade
Install nginx
sudo apt-get install nginx
Open HTTP/HTTPS firewall
Check if ufw is activated?
ghost@bboysoul:/etc/init.d$ sudo service ufw status ● ufw.service - Uncomplicated firewall Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor preset: enabled) Active: active (exited) since Sat 2017-09-16 15:24:12 CST; 29min ago Main PID: 337 (code=exited, status=0/SUCCESS) CGroup: /system.slice/ufw.service Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
If activated, make sure that the firewall allows http/https connections
ghost@bboysoul:/etc/init.d$ sudo ufw allow 'Nginx Full' Rules updated Rules updated (v6)
Install mysql
sudo apt-get install mysql-server
Install nodejs
Because ghost blog is written in nodejs, install nodejs
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash
sudo apt-get install -y nodejs
Install Ghost-CLI
Because I am in China, I have to switch the source of nodejs, otherwise the download will be very slow.
npm config set registry https://registry.npm.taobao.org
Then install ghost-cli
sudo npm i -g ghost-cli
ghost@bboysoul:/etc/init.d$ sudo npm i -g ghost-cli [sudo] password for ghost: npm WARN deprecated node-uuid@1.4.8: Use uuid module instead /usr/bin/ghost -> /usr/lib/node_modules/ghost-cli/bin/ghost /usr/lib └── ghost-cli@1.1.1
Install ghost
First create a new site folder
sudo mkdir -p /var/www/ghost
Change the owner of this folder to ghost
sudo chown ghost:ghost /var/www/ghost/
Switch to this folder
cd /var/www/ghost/
Install ghost
ghost install
ghost@bboysoul:/var/www/ghost$ ghost install ✔ Checking system Node.js version ✔ Checking current folder permissions ✔ Checking operating system ✔ Checking MySQL is installed ✔ Checking for latest Ghost version ✔ Setting up install directory ✔ Downloading and installing Ghost v1.8.6 ✔ Finishing install process ? Enter your blog URL: http://localhost:2368 ? Enter your MySQL hostname: localhost ? Enter your MySQL username: root ? Enter your MySQL password: [hidden] ? Enter your Ghost database name: ghost ✔ Configuring Ghost ✔ Setting up instance Running sudo command: chown -R ghost:ghost /var/www/ghost/content [sudo] password for ghost: ✔ Setting up "ghost" system user ? Do you wish to set up Nginx? No ℹ Setting up Nginx [skipped] Task ssl depends on the 'nginx' stage, which was skipped. ℹ Setting up SSL [skipped] ? Do you wish to set up "ghost" mysql user? No ℹ Setting up "ghost" mysql user [skipped] ? Do you wish to set up Systemd? Yes ✔ Creating systemd service file at /var/www/ghost/system/files/ghost_localhost.service Running sudo command: ln -sf /var/www/ghost/system/files/ghost_localhost.service /lib/systemd/system/ghost_localhost.service Running sudo command: systemctl daemon-reload ✔ Setting up Systemd ✔ Running database migrations ? Do you want to start Ghost? Yes ✔ Validating config Running sudo command: systemctl start ghost_localhost ✔ Starting Ghost You can access your blog at http://localhost:2368/ Ghost uses direct mail by default To set up an alternative email method read our docs at https://docs.ghost.org/docs/mail-config
In this way, you can open your own ghost website in your local browser. If you can't access it, please wait patiently, because the program may start slowly, if you want to visit your blog on another machine. Modify its configuration file, as follows
vim config.production.json
{ "url": "http://192.168.1.102:2368/", "server": { "port": 2368, "host": "192.168.1.102" }, "database": { "client": "mysql", "connection": { "host": "localhost", "user": "root", "password": "woyaoxuehuilinux", "database": "ghost" } }, "mail": { "transport": "Direct" }, "logging": { "transports": [ "file", "stdout" ] }, "process": "systemd", "paths": { "contentPath": "/var/www/ghost/content" } }
Note that the url and host have to be changed to the actual ip of their machine instead of 127.0.0.1
Of course, I didn't configure nginx. If you configure nginx, you just need to modify the configuration file in nginx.
Have Fun
Welcome to Bboysoul's personal blog www.bboysoul.com