如何在Ubuntu 18.04上安装Ghost CMS

时间:2020-02-23 14:32:58  来源:igfitidea点击:

本教程将演示如何在Ubuntu 18.04(仿生海狸)Linux发行版上安装Ghost CMS。
Ghost是一个开源出版平台,设计精美,易于使用,为每个人提供免费。
它已完全支持Markdown,并提供易于使用的Web界面以用于管理目的。

设置要求

对于此设置,基本要求是:

  • Ubuntu 18.04 / Ubuntu 16.04 Server
  • Nginx Web Server
  • FQDN
  • Node.js
  • MySQL / MariaDB Database Server
  • ghost user – Non-root user to manage it

让我们在Ubuntu 18.04 LTS上开始安装Ghost。

步骤1:安装和配置MySQL/MariaDB数据库服务器

为Ghost CMS安装数据库服务器。
这可以是MySQL或者MariaDB数据库服务器。
我们有用于设置MySQL或者MariaDB数据库服务器的教程。

如何在Ubuntu 18.04/16.04上安装MySQL 8.0

如何在Ubuntu 18.04/Ubuntu 16.04上安装MariaDB 10.4

完成后,为Ghost Blog创建数据库,我们计划添加:

$mysql -u root -p
CREATE USER Hyman@theitroad IDENTIFIED BY "StrongPassword";
CREATE DATABASE  ghost; 
GRANT ALL ON ghost.* TO Hyman@theitroad;
FLUSH PRIVILEGES;
QUIT

第2步:安装nginx web服务器

接下来是安装nginx

sudo apt update
sudo apt -y install nginx

第3步:添加用户获取幽灵管理

添加用户调用 ghostadmin

sudo adduser ghostadmin
sudo usermod -aG sudo ghostadmin

第4步:安装node.js

自支持以来,安装Node.js 10 LT。

在Ubuntu 18.04/16.04/debian 9上安装node.js 10 lts

确认节点版本

$node -v
v10.15.0

第5步:在Ubuntu 18.04上安装ghost-cli

我们现在需要安装包ghost-cli,它提供ghost命令。

$sudo npm i -g ghost-cli
 npm WARN deprecated Hyman@theitroad: cross-spawn no longer requires a build toolchain, use it instead
 /usr/bin/ghost -> /usr/lib/node_modules/ghost-cli/bin/ghost
 Hyman@theitroad
 added 377 packages from 182 contributors in 29.281s

步骤6:为Ghost数据创建一个新文件夹

请注意:在/根文件夹中安装Ghost无法正常工作,并导致破坏的设置!在/home/{user}文件夹中安装ghost无法正常工作并导致破坏的设置!请仅使用/var/www/{folder}因为它具有正确的权限。

所以让我们创建这个目录:

sudo mkdir -p /var/www/ghost
sudo chown ghostadmin:ghostadmin /var/www/ghost
sudo chmod 775 /var/www/ghost

第7步:在Ubuntu 18.04上安装Ghost(仿生海狸)

创建Ghost CMS目录。

su - ghostadmin
cd /var/www/ghost
mkdir blog.example.com
cd blog.example.com

运行以下命令以安装ghost:

$ghost install
 ✔ Checking system Node.js version
 ✔ Checking logged in user
 ✔ Checking current folder permissions
 ✔ Checking operating system compatibility
 ✔ Checking for a MySQL installation
 ✔ Checking memory availability
 ✔ Checking for latest Ghost version
 ✔ Setting up install directory
 ✔ Downloading and installing Ghost v2.9.1
 ✔ Finishing install process
 ? Enter your blog URL: http://blog.example.com
 ? Enter your MySQL hostname: localhost
 ? Enter your MySQL username: ghost
 ? Enter your MySQL password: [hidden] <ENTER PASSWORD>
 ? Enter your Ghost database name: ghost
 ✔ Configuring Ghost
 ✔ Setting up instance
 sudo useradd --system --user-group ghost
 sudo chown -R ghost:ghost /var/www/ghost/blog.example.com/content
 ✔ Setting up "ghost" system user
 ? Do you wish to set up "ghost" mysql user? Yes
 MySQL user is not "root", skipping additional user setup
 ℹ Setting up "ghost" mysql user [skipped]
 ? Do you wish to set up Nginx? Yes
 ✔ Creating nginx config file at /var/www/ghost/blog.example.com/system/files/blog.example.com.conf
 sudo ln -sf /var/www/ghost/blog.example.com/system/files/blog.example.com.conf /etc/nginx/sites-available/blog.example.com.conf
 sudo ln -sf /etc/nginx/sites-available/blog.example.com.conf /etc/nginx/sites-enabled/blog.example.com.conf
 sudo nginx -s reload
 ✔ Setting up Nginx
 ? Do you wish to set up SSL? No
 ℹ Setting up SSL [skipped]
 ? Do you wish to set up Systemd? Yes
 ✔ Creating systemd service file at /var/www/ghost/blog.example.com/system/files/ghost_blog-example-com.service
 sudo ln -sf /var/www/ghost/blog.example.com/system/files/ghost_blog-example-com.service /lib/systemd/system/ghost_blog-example-com.service
 sudo systemctl daemon-reload
 ✔ Setting up Systemd
 ? Do you want to start Ghost? Yes
 sudo systemctl is-active ghost_blog-example-com
 ✔ Ensuring user is not logged in as ghost user
 ✔ Checking if logged in user is directory owner
 ✔ Checking current folder permissions
 sudo systemctl is-active ghost_blog-example-com
 ✔ Validating config
 ✔ Checking folder permissions
 ✔ Checking file permissions
 ✔ Checking content folder ownership
 ✔ Checking memory availability
 sudo systemctl start ghost_blog-example-com
 ✔ Starting Ghost
 sudo systemctl is-enabled ghost_blog-example-com
 sudo systemctl enable ghost_blog-example-com --quiet
 ✔ Enabling Ghost instance startup on server boot 
 Ghost uses direct mail by default. To set up an alternative email method read our docs at https://ghost.org/mail
 
 Ghost was installed successfully! To complete setup of your publication, visit: 
 http://blog.example.com/ghost/

使用MySQL作为默认数据库,这将在生产模式中安装并启动博客。
你可以同意 setup Let's Encrypt SSL
如果服务器有有效的域名和公共IP地址。

nginx配置文件将放置在:/etc/nginx /支持站点下/

检查服务状态:

$systemctl status ghost_blog-example-com
 ● ghost_blog-example-com.service - Ghost systemd service for blog: blog-example-com
    Loaded: loaded (/var/www/ghost/blog.example.com/system/files/ghost_blog-example-com.service; enabled; vendor preset: enabled)
    Active: active (running) since Sun 2016-12-30 17:06:48 EAT; 34min ago
      Docs: https://docs.ghost.org
  Main PID: 19723 (ghost run)
     Tasks: 18 (limit: 4915)
    CGroup: /system.slice/ghost_blog-example-com.service
            ├─19723 ghost run
            └─19734 /usr/bin/node current/index.js

ghost 命令:

日志目录:/content/Logs/
$ghost start:启动ghost
$ghost restart:重启ghost
$ghost run:测试ghost是否可以成功启动
$ghost uninstall:重新安装ghost
$ghost update:升级ghost
$ghost update-force:如果出现错误,则强制升级
$ghost update–rollback:如果升级失败,则还原到早期版本
$sudo npm i-g xxx:升级Ghost CLI
$ghost ssl renew:续订ssl证书
$ls./system/files/*.conf:系统配置文件
$ghost setup nginx:手动设置nginx
$ghost setup nginx ssl:使用ssl设置nginx

访问Ubuntu 18.04上的Ghost Admin接口

设置现已准备就绪,访问Ghost Web管理界面,我们可以其中上传主题,使用Markdown语法更改设置和写入内容。

要完成出版物,请访问:

创建第一个Ghost Administrator/Publisher帐户。

我们已在Ubuntu 18.04上成功安装Ghost CMS。