引言
Ghost是一款基于Node.js的开源博客平台,以其简洁的界面和灵活的配置受到许多开发者和博客爱好者的喜爱。本文将基于简书上的实战攻略,详细介绍如何在CentOS系统上安装与配置Ghost博客。
系统准备
在开始安装之前,请确保您的CentOS系统满足以下要求:
- CentOS 7 或更高版本
- Apache服务器
- MariaDB数据库
- PHP
- Node.js和npm
您可以使用以下命令来检查和安装这些依赖项:
# 更新yum源
sudo yum update
# 安装Apache服务器
sudo yum install httpd
# 安装MariaDB数据库
sudo yum install mariadb mariadb-server
# 安装PHP
sudo yum install php php-mysql
# 安装Node.js和npm
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
sudo yum install -y nodejs
安装Ghost
- 创建Ghost目录:
sudo mkdir /var/www/ghost
cd /var/www/ghost
- 初始化Node.js项目:
npm init -y
- 安装Ghost CLI工具:
sudo npm install -g ghost-cli
- 安装Ghost博客:
ghost install
安装过程中,您需要按照提示进行操作,包括设置管理员账户、输入域名等。
配置Apache服务器
- 创建虚拟主机配置文件:
sudo nano /etc/httpd/conf.d/ghost.conf
- 添加以下配置:
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
DocumentRoot /var/www/ghost/content
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
- 重启Apache服务器:
sudo systemctl restart httpd
配置MariaDB数据库
- 连接到MariaDB数据库:
sudo mysql
- 创建Ghost数据库和用户:
CREATE DATABASE ghost;
CREATE USER 'ghostuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON ghost.* TO 'ghostuser'@'localhost';
FLUSH PRIVILEGES;
- 配置Ghost博客以使用MariaDB数据库:
编辑/var/www/ghost/content/config.production.json
文件,修改数据库配置:
{
"server": {
"host": "localhost",
"port": 3306,
"database": "ghost",
"user": "ghostuser",
"password": "password"
}
}
启动Ghost博客
- 启动Ghost博客:
sudo ghost start
- 访问您的Ghost博客:
总结
通过以上步骤,您已经在CentOS系统上成功安装并配置了Ghost博客。接下来,您可以开始创建内容、定制主题和探索Ghost提供的各种功能。希望本文能帮助您在简书上分享您的实战攻略。