Ghost on Alpine Linux

別の記事「Nextcloud on Alpine Linux」に引き続き、Ghost を Alpine Linux にインストールします。作業手順は既にここに記載されていましたが、パッケージ shadow をインストールしたくなかったので、少し変更しました。

前提

別の記事「Nextcloud on Alpine Linux」記載の次の作業完了が前提です。

  • サーバ証明書
  • MariaDB のインストール
    システムテーブル生成
    セキュリティ初期設定
  • NGINX のインストール

Install Node.js & npm

Node.js とパッケージマネージャ npm をインストールします。

root@www:~# apk add nodejs npm
fetch http://alpine.cs.nctu.edu.tw/v3.14/main/x86_64/APKINDEX.tar.gz
fetch http://alpine.cs.nctu.edu.tw/v3.14/community/x86_64/APKINDEX.tar.gz
(1/3) Installing c-ares (1.17.1-r1)
(2/3) Installing nodejs (14.17.3-r0)
(3/3) Installing npm (7.17.0-r0)
Executing busybox-1.33.1-r3.trigger
OK: 584 MiB in 209 packages
root@www:~#

Install Ghost-CLI

Ghost 管理用のコマンドラインツール Ghost-CLI をインストールします。

root@www:~# npm install ghost-cli@latest -g

added 419 packages, and audited 420 packages in 24s

30 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
root@www:~#

Create Database & User

mariadb に Ghost 用のデータベースとユーザを作成します。

root@www:~# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3469
Server version: 10.5.11-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database ghost4;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> grant all on ghost4.* to 'ghost4'@'localhost' identified by 'ghost4';
Query OK, 0 rows affected (0.004 sec)

MariaDB [(none)]> exit
Bye
root@www:~#

Create a new user

Ghost 管理用のユーザとグループを作成します。

root@www:~# adduser -h /var/www/ghost -G gst gst
Changing password for gst
New password:
Retype password:
passwd: password for gst changed by root
root@www:~# mkdir -p /var/www/ghost
root@www:~# chown gst:gst /var/www/ghost
root@www:~#

Install Ghost

作成した Ghost 管理用のユーザで Ghost をインストールします。途中 sudo のためのパスワードの入力を求められますが、sudo の設定はしていないのでエラーになります。エラーにはなるものの Ghost は稼働できる状態となります。

root@www:~# sudo -u gst ash
gst@www:/root$ cd
gst@www:~$ ghost install
✔ Checking system Node.js version - found v14.17.3
✔ Checking logged in user
✔ Checking current folder permissions
System checks failed with message: 'Linux version is not Ubuntu 16, 18, or 20'
Some features of Ghost-CLI may not work without additional configuration.
For local installs we recommend using `ghost install local` instead.
? Continue anyway? Yes
System stack check skipped
ℹ Checking system compatibility [skipped]
Local MySQL install was not found or is stopped. You can ignore this if you are using a remote MySQL host.
Alternatively you could:
a) install/start MySQL locally
b) run `ghost install --db=sqlite3` to use sqlite
c) run `ghost install local` to get a development install using sqlite3.
? Continue anyway? Yes
MySQL check skipped
ℹ Checking for a MySQL installation [skipped]
✔ Checking memory availability
✔ Checking free space
✔ Checking for latest Ghost version
✔ Setting up install directory
✔ Downloading and installing Ghost v4.10.2
✔ Finishing install process
? Enter your blog URL: https://www.example.com/gst/
? Enter your MySQL hostname: localhost
? Enter your MySQL username: ghost4
? Enter your MySQL password: ghost4
? Enter your Ghost database name: ghost4
✔ Configuring Ghost
✔ Setting up instance
+ sudo useradd --system --user-group ghost
? Sudo Password [hidden]xxx
? Sudo Password [hidden]xxx
? Sudo Password [hidden]xxx
✖ Setting up "ghost" system user
ℹ Setting up "ghost" mysql user [skipped]
Nginx is not installed. Skipping Nginx setup.
ℹ Setting up Nginx [skipped]
Nginx setup task was skipped, skipping SSL setup
ℹ Setting up SSL [skipped]
? Do you wish to set up Systemd? No
Systemd setup skipped, reverting to local process manager
ℹ Setting up Systemd [skipped]
? Do you want to start Ghost? No
ℹ Starting Ghost [skipped]
One or more errors occurred.

1) undefined

Error: Command failed: /bin/sh -c sudo -S -p '#node-sudo-passwd#'  useradd --system --user-group ghost

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

#node-sudo-passwd#Sorry, try again.
#node-sudo-passwd#Sorry, try again.
#node-sudo-passwd#sudo: 3 incorrect password attempts


Debug Information:
    OS: Alpine Linux, v3.14.0
    Node Version: v14.17.3
    Ghost Version: 4.10.2
    Ghost-CLI Version: 1.17.3
    Environment: production
    Command: 'ghost install'

Try running ghost doctor to check your system for known issues.

You can always refer to https://ghost.org/docs/ghost-cli/ for troubleshooting.

config.production.json

UNIXドメインソケットで MariaDB に接続するよう変更しました。

gst@www:~$ cp -p config.production.json config.production.json.original
gst@www:~$ vi config.production.json
gst@www:~$ diff config.production.json.original config.production.json
--- config.production.json.original
+++ config.production.json
@@ -8,6 +8,7 @@
     "client": "mysql",
     "connection": {
       "host": "localhost",
+      "port": "/run/mysqld/mysqld.sock",
       "user": "ghost4",
       "password": "ghost4",
       "database": "ghost4"

Start Ghost

gst@www:~$ ghost start
✔ Checking system Node.js version - found v14.17.3
ℹ Ensuring user is not logged in as ghost user [skipped]
ℹ Checking if logged in user is directory owner [skipped]
✔ Checking current folder permissions
✔ Validating config
✔ Checking memory availability
✔ Checking binary dependencies
✔ Starting Ghost: www-example-com

------------------------------------------------------------------------------

Your admin interface is located at:

    https://www.excample.com/gst/ghost/

gst@www:~$

NGINX Reverse Proxy

nginx に次のようなリバースプロクシの設定をして作業完了です。

    location /gst {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://127.0,0.1:2368;
        proxy_redirect off;
    }

Ghost

ブラウザで、次の URL にアクセスし、最後のステップを完了します。

https://www.example.com/gst/ghost/