Ghost 手动安装教程
Ghost 是一款专注于博客创作的开源内容管理系统,以其简洁的设计和强大的功能受到许多用户的喜爱。本文将为你提供一个简明的 Ghost 手动安装指南。
首先,确保你的服务器环境满足 Ghost 的运行要求。你需要一台支持 Node.js 和 MySQL/MariaDB 的服务器(如 Ubuntu、CentOS 或其他 Linux 系统)。同时,安装 Git 和 Nginx 或 Apache 作为反向代理工具。
第一步:准备环境
1. 更新系统软件包
在服务器上运行以下命令,确保系统是最新的:
```bash
sudo apt update && sudo apt upgrade -y
```
2. 安装 Node.js 和 npm
Ghost 推荐使用 LTS 版本的 Node.js。你可以通过以下命令安装:
```bash
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install -y nodejs
```
3. 安装 MySQL 或 MariaDB
使用以下命令安装 MySQL:
```bash
sudo apt install mysql-server
```
安装完成后,运行 `mysql_secure_installation` 设置密码并进行安全配置。
4. 安装 Git
Git 是获取 Ghost 源码的必要工具:
```bash
sudo apt install git
```
第二步:下载并安装 Ghost
1. 克隆 Ghost 仓库
使用 Git 克隆最新的 Ghost 源码:
```bash
git clone https://github.com/TryGhost/Ghost.git
cd Ghost
```
2. 初始化数据库
登录 MySQL 并创建 Ghost 数据库:
```bash
mysql -u root -p
CREATE DATABASE ghost;
GRANT ALL PRIVILEGES ON ghost. TO 'ghost_user'@'localhost' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;
EXIT;
```
3. 安装依赖
进入项目目录后,安装所需的 Node.js 模块:
```bash
npm install --production
```
第三步:配置与启动
1. 复制配置文件
复制默认配置文件并编辑:
```bash
cp config.example.json config.production.json
nano config.production.json
```
修改数据库连接信息和其他设置。
2. 启动 Ghost
使用以下命令启动 Ghost:
```bash
npm start --production
```
3. 设置为开机自启
你可以将 Ghost 配置为服务,以便在系统重启时自动运行。使用 PM2 工具管理服务:
```bash
sudo npm install -g pm2
pm2 start index.js --name ghost -- --production
pm2 save
```
第四步:配置域名与反向代理
1. 配置 Nginx
编辑 Nginx 配置文件,添加反向代理规则:
```bash
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:2368;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
```
2. 重启 Nginx
```bash
sudo nginx -t
sudo systemctl restart nginx
```
完成以上步骤后,打开浏览器访问你的域名,即可进入 Ghost 的安装页面,完成博客的初始配置。
通过上述方法,你便成功搭建了一个属于自己的 Ghost 博客平台!