如何在Ubuntu Server 18.04 / 20.04上安装Ghost Blogging平台
本教程将向您展示如何在Ubuntu服务器上安装Ghost博客平台。 Ghost是用Node.js编码的开源博客软件,可让您创建现代,美观的博客。 与WordPress相比,Ghost轻巧且速度更快,因为它是专为博客而构建的,而不是像WordPress这样的全面内容管理系统。
幽灵功能
在撰写本文时,Ghost的最新版本是v3.2.0,于2019年12月23日发布。Ghost的功能如下:
- 基于Markdown的编辑器,可让您快速撰写帖子。
- 简单的内容管理。
- 与您的团队进行协同编辑。
- 预定发布
- 内置分析
- 直接内置正确的SEO,带有语义标记,永久链接,XML站点地图,规范标签和带有手动覆盖的自动元数据。
- 集成的AMP(加速的移动页面)支持
- 完整的RSS提要,电子邮件订阅捕获表单和Slack Webhook集成
- Ghost市场上提供了数百个精美的免费和高级主题
- 具有深色模式支持的外观漂亮的默认主题Capser。
- 适用于Linux,Mac和Windows的跨平台桌面应用程序。
- 官方的Ghost Migrator WordPress插件可让您轻松地从WordPress迁移到Ghost。
Ghost基金会提供托管托管,但是在这里我们将看到如何在Ubuntu服务器上创建自托管Ghost博客。
在Ubuntu服务器上安装Ghost的前提条件
要运行Ghost博客,您需要一台至少具有1GB RAM的服务器。 您可以单击此特殊链接以在DigitalOcean上获得$ 50的免费信用。 (仅适用于新用户)。 如果您已经是DigitalOcean用户,则可以单击此特殊链接以在Vultr上获得$ 50的免费信用(仅适用于新用户)。 在DigitalOcean或Vultr上拥有帐户后,在服务器上安装Ubuntu并按照以下说明进行操作。 为了获得最佳兼容性,请使用Ubuntu的LTS版本,例如Ubuntu 18.04或16.04。
您还需要一个域名。 我从NameCheap注册了我的域名,因为它价格低廉,并且终身免费提供Whois隐私保护。
注意:我在Ubuntu上使用sudo用户安装了Ghost。 为了获得最佳结果,您还应该以sudo用户(而不是root)使用本教程。 要添加sudo用户,只需运行
sudo adduser username sudo adduser username sudo
然后切换到新用户。
su - username
步骤1:更新Ubuntu
如果您的服务器已有一段时间没有更新,请运行以下命令来更新现有软件包。
sudo apt update;sudo apt upgrade
步骤2:在Ubuntu上安装Node.js
Ghost要求您安装Node.js的LTS版本,并且不支持非LTS版本。 Node.js的最新LTS版本是v12.x,但是当前Ghost与Node.js v10.x更加兼容。 使用以下命令添加NodeSource存储库。
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
然后安装Node.js。
sudo apt install nodejs
检查节点版本。
node -v
样本输出:
v10.18.1
检查一下 npm
版:
npm -v
样本输出:
6.13.4
步骤3:安装MariaDB数据库服务器
支持MySQL和MariaDB。 MariaDB是MySQL的直接替代品。 它是由MySQL团队的前成员开发的,他们担心Oracle可能会将MySQL变成开源产品。 因此,让我们安装MariaDB数据库服务器。
输入以下命令以将其安装在Ubuntu 18.04 / 20.04上。
sudo apt install mariadb-server mariadb-client
安装后,MariaDB服务器应自动启动。 使用 系统控制 检查其状态。
systemctl status mariadb
样本输出:
● mariadb.service - MariaDB 10.1.34 database server Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2018-09-08 11:13:27 UTC; 21s ago Docs: man:mysqld(8) https://mariadb.com/kb/en/library/systemd/ Main PID: 3473 (mysqld) Status: "Taking your SQL requests now..." Tasks: 27 (limit: 505) CGroup: /system.slice/mariadb.service └─3473 /usr/sbin/mysqld
如果它没有运行,请使用以下命令启动它:
sudo systemctl start mariadb
要使MariaDB在系统启动时自动启动,请运行
sudo systemctl enable mariadb
现在运行安装后安全脚本。
sudo mysql_secure_installation
当要求您输入MariaDB根密码时,请按Enter键,因为尚未设置根密码。 然后输入 y
设置MariaDB服务器的根密码。
接下来,您可以按Enter回答所有剩余的问题,这将删除匿名用户,禁用远程root登录并删除测试数据库。 此步骤是MariaDB数据库安全性的基本要求。 (注意,信 Y
大写,这是默认答案。)
检查MariaDB服务器版本信息。
mariadb --version
输出:
mariadb Ver 15.1 Distrib 10.1.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
步骤4:为Ghost创建数据库和用户
现在我们需要登录MariaDB控制台并为Ghost创建数据库和用户。 默认情况下,Ubuntu上的MaraiDB软件包使用unix_socket来验证用户登录名,这基本上意味着您可以使用操作系统的用户名和密码登录MariaDB控制台。 因此,您可以运行以下命令来登录,而无需提供MariaDB根密码。
sudo mariadb -u root
使用以下命令为Ghost创建数据库。 我命名了 ghost
,但您可以使用任何喜欢的名称。 (不要忽略分号。)
create database ghost;
然后,输入以下命令为Ghost创建数据库用户,并将该ghost数据库的所有特权授予该用户。
grant all privileges on ghost.* to [email protected] identified by 'ghost_password';
刷新特权表以使更改生效,然后退出MariaDB控制台。
flush privileges; exit;
步骤5:安装Nginx Web服务器
Ghost将使用Nginx Web服务器,因此运行以下命令从默认的Ubuntu存储库安装它。
sudo apt install nginx
如果使用UFW防火墙,则还需要打开端口80和443。
sudo ufw allow 80/tcp sudo ufw allow 443/tcp
步骤6:为您的博客域名创建记录
在安装Ghost之前,建议您为博客域名创建DNS A记录。 A记录将您的域名指向您的Ubuntu服务器的IP地址。
步骤7:安装Ghost
安装Ghost-CLI。
sudo npm install [email protected] -g
然后创建一个目录(/var/www/ghost/
)。
sudo mkdir -p /var/www/ghost/
向您的用户帐户授予权限。 更换 username
使用您的真实用户名。
sudo setfacl -R -m u:username:rwx /var/www/ghost/ sudo chmod 775 /var/www/ghost
现在将工作目录更改为 /var/www/ghost/
并安装Ghost。
cd /var/www/ghost/ ghost install
安装可能需要一段时间。 在安装过程中,将要求您输入博客URL。 输入类似 https://yourdomain.com
。 您将需要输入MariaDB数据库名称,即在步骤4中创建的用户凭据。
? Enter your blog URL: https://yourdomain.com ? Enter your MySQL hostname: localhost ? Enter your MySQL username: ghost ? Enter your MySQL password: ghost_password ? Enter your Ghost database name: ghost
如果您正在使用Ubuntu 20.04,并且看到以下消息,则可以忽略它并继续安装。
System checks failed with message: 'Linux version is not Ubuntu 16 or 18' Some features of Ghost-CLI may not work without additional configuration. For local installs we recommend using `ghost install local` instead.
一种 ghost
系统用户将被自动创建。 建议您接受设置Nginx和SSL,以便通过安全的HTTPS协议访问您的博客。 另外,接受设置Systemd服务,以便您可以轻松启动,停止或重新启动Ghost。
成功安装Ghost后,请转到 https://yourdomain.com/ghost
完成设置。 首先,您需要创建一个帐户。
然后,您可以邀请一些工作人员用户访问您的Ghost博客,也可以稍后进行。
步骤8:编辑Nginx配置文件
默认情况下,Ghost的Nginx配置文件包含一个域名。 如果希望Nginx同时为www域和非www域提供服务,请编辑配置文件。
sudo nano /etc/nginx/sites-enabled/yourdomain.com.conf
找到以下行
server_name yourdomain.com;
添加www域。
server_name yourdomain.com www.yourdomain.com;
保存并关闭文件。 然后删除 /etc/nginx/sites-enabled/yourdomain.com-ssl.conf
文件。
sudo rm /etc/nginx/sites-enabled/yourdomain.com-ssl.conf
然后安装Certbot让我们加密客户端
sudo apt install certbot python3-certbot-nginx
获得www域和非www域的SSL证书。
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d yourdomain.com,www.yourdomain.com
重新启动Nginx,您就完成了。
sudo systemctl restart nginx
步骤9:设置电子邮件通知
为了从您的Ghost博客发送电子邮件(用于密码重置,邀请工作人员用户,会员注册等),您需要配置SMTP设置。 如果您想使用自己的电子邮件服务器,请阅读以下教程以轻松设置自己的电子邮件服务器。
- 如何使用iRedMail在Ubuntu 18.04上轻松设置自己的电子邮件服务器
拥有自己的电子邮件服务器后,请编辑Ghost配置文件。
sudo nano /var/www/ghost/config.production.json
默认情况下,邮件设置如下:
"mail": { "transport": "Direct" },
将其更改为使用SMTP。
"mail": { "transport": "SMTP", "from": "[email protected]", "options": { "service": "yourdomain.com", "host": "mail.yourdomain.com", "port": 465, "secureConnection": true, "auth": { "user": "[email protected]", "pass": "the_email_account_password" } } },
请注意,Ghost不支持SMTP的端口587。 保存并关闭文件。 然后通过systemd服务重新启动Ghost。
sudo systemctl restart ghost_yourdomain-com.service
现在,您的Ghost博客应该可以发送电子邮件了。
包起来
而已! 我希望本教程可以帮助您在Ubuntu服务器上安装Ghost。 与往常一样,如果您发现这篇文章很有用,请订阅我们的免费新闻通讯以获取更多提示和技巧。 保重🙂