Ubuntu 16.04でGhostをインストールおよび構成する方法

このチュートリアルの以前のバージョンはKevin Isaacによって書かれました

前書き

Ghostは、軽量のオープンソースブログプラットフォームです。 Ghostは完全にカスタマイズ可能で、多くのテーマが利用可能です。

このチュートリアルでは、公式のghost-cliインストールウィザードを使用して、Ubuntu16.04で本番環境に対応したGhostインスタンスをセットアップします。 これにより、Ghostがインストールされ、リクエストをGhostにプロキシするようにNginxが構成され、Let’s Encrypt証明書で保護され、システムサービスとしてバックグラウンドで実行されるようにGhostが構成されます。

前提条件

このチュートリアルを完了するには、次のものが必要です。

[[step-1 -—- installing-the-ghost-cli-application]] ==ステップ1— GhostCLIアプリケーションのインストール

公式のghost-cliプログラムを使用してGhostをインストールします。 このプログラムはGhostをインストールし、MySQLユーザーとデータベースを作成し、Nginxをリバースプロキシとして構成し、SSL / TLS暗号化を使用してサイトを保護します。

まず、npmを使用してghost-cliをダウンロードします。

sudo npm i -g ghost-cli

Ghostは、推奨されるインストール場所であるvar/www/ghostディレクトリに配置します。 このディレクトリを作成します。

mkdir /var/www/ghost

次に、ユーザーがこのディレクトリを所有していることを確認します。

sudo chown $USER:$USER /var/www/ghost

/var/www/ghostディレクトリには、ユーザーに対する完全なアクセス許可と、他のすべてのユーザーに対する読み取りおよび実行のアクセス許可が必要です。したがって、次のコマンドを使用してアクセス許可を設定します。

sudo chmod 775 /var/www/ghost

CLIをインストールし、ディレクトリを配置したら、ブログをセットアップできます。

[[step-2 -—- installing-and-configuring-ghost]] ==ステップ2—Ghostのインストールと構成

Ghost CLIアプリには、作業用のGhostブログを設定するためのすべての手順を案内するインストールウィザードがあります。

/var/www/ghost/ディレクトリに切り替えます。

cd /var/www/ghost/

次に、ghostコマンドを使用してGhostをインストールします。 MySQLをデフォルトのデータベースとして使用するようにGhostを構成します。 他のデータベースを使用することもできますが、実稼働セットアップにはMySQLが推奨される選択肢です。

ghost install

インストーラーは、まず必要な前提条件がインストールされていることを確認してから、Ghostをダウンロードしてインストールします。

Output✔ 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 v1.22.2
✔ Finishing install process

インストールプロセスが完了すると、MySQLデータベース情報とともにブログのURLの入力を求められます。 このステップでは、rootのユーザー名とパスワードを入力します。 データベース名には、デフォルトのghost_prodを使用できます。

Output? Enter your blog URL: http://example.com
? Enter your MySQL hostname: localhost
? Enter your MySQL username: root
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: ghost_prod

次に、構成ウィザードはghostシステムユーザーを作成し、ghostMySQLユーザーを作成する必要があるかどうかを尋ねます。これを許可する必要があります。

Output✔ Configuring Ghost
✔ Setting up instance
Running sudo command: useradd --system --user-group ghost
Running sudo command: chown -R ghost:ghost /var/www/ghost/content
✔ Setting up "ghost" system user
? Do you wish to set up "ghost" mysql user? Yes
✔ Setting up "ghost" mysql user

次に、Nginxを設定するかどうかを尋ねられます。 これを確認すると、インストーラーがブログに適切なリバースプロキシサーバーブロックを作成します。

Output? Do you wish to set up Nginx? Yes
✔ Creating nginx config file at /var/www/ghost/system/files/example.con.conf
Running sudo command: ln -sf /var/www/ghost/system/files/example.com.conf /etc/nginx/sites-available/example.com.conf
Running sudo command: ln -sf /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/example.com.conf
Running sudo command: nginx -s reload
✔ Setting up Nginx

次に、SSLサポートを設定するよう求められます。 登録済みの完全修飾ドメイン名を使用していて、サーバーのIPアドレスを指すようにDNS設定を構成している場合は、Yを押して続行します。

Output? Do you wish to set up SSL? Yes

メールアドレスの入力を求められ、証明書がインストールされます。

Output? Enter your email (used for Let's Encrypt notifications) [email protected]
Running sudo command: mkdir -p /etc/letsencrypt
Running sudo command: ./acme.sh --install --home /etc/letsencrypt
Running sudo command: /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt --domain example.com --webroot /var/www/ghost/system/nginx-root --reloadcmd "nginx -s reload" --accountemail [email protected]
Running sudo command: openssl dhparam -out /etc/nginx/snippets/dhparam.pem 2048
Running sudo command: openssl dhparam -out /etc/nginx/snippets/dhparam.pem 2048
Running sudo command: mv /tmp/ssl-params.conf /etc/nginx/snippets/ssl-params.conf
✔ Creating ssl config file at /var/www/ghost/system/files/example.com-ssl.conf
Running sudo command: ln -sf /var/www/ghost/system/files/example.com-ssl.conf /etc/nginx/sites-available/example.com-ssl.conf
Running sudo command: ln -sf /etc/nginx/sites-available/example.com-ssl.conf /etc/nginx/sites-enabled/example.com-ssl.conf
Running sudo command: nginx -s reload
✔ Setting up SSL

次に、構成ウィザードはsystemdサービスをセットアップするように求めます。 Yを押して続行すると、ウィザードはghost_example-comという新しいsystemdサービスを作成し、起動時に開始できるようにします。

Output? Do you wish to set up Systemd? Yes
✔ Creating systemd service file at /var/www/ghost/system/files/ghost_example-com.service
Running sudo command: ln -sf /var/www/ghost/system/files/ghost_example-com.service /lib/systemd/system/ghost_example-com.service
Running sudo command: systemctl daemon-reload
✔ Setting up Systemd

最後に、ウィザードはデータベースを構成し、Ghostを起動するかどうかを尋ねます。これは、Yを押して許可する必要があります。

OutputRunning sudo command: /var/www/ghost/current/node_modules/.bin/knex-migrator-migrate --init --mgpath /var/www/ghost/current
✔ Running database migrations
? Do you want to start Ghost? Yes
Running sudo command: systemctl is-active ghost_example-com
✔ Ensuring user is not logged in as ghost user
✔ Checking if logged in user is directory owner
✔ Checking current folder permissions
Running sudo command: systemctl is-active ghost_example-com
✔ Validating config
✔ Checking folder permissions
✔ Checking file permissions
✔ Checking content folder ownership
✔ Checking memory availability
Running sudo command: systemctl start ghost_example-com
✔ Starting Ghost
Running sudo command: systemctl is-enabled ghost_example-com
Running sudo command: systemctl enable ghost_example-com --quiet
✔ Starting Ghost

これで、Ghostブログがインストールされ、使用できる状態になりました。 http://example.comでブログにアクセスできます。 最初の投稿を作成できるように、アカウントを作成しましょう。

[[step-3 -—- creating-an-account-and-configuring-your-blog]] ==ステップ3—アカウントの作成とブログの構成

ログインしてブログを構成するには、http://example.com/loginにアクセスしてください。 次の画面が表示されます。

Welcome screen

開始するには、Create your accountボタンを押します。

Create your account画面が表示され、ブログのタイトル、名前、メールアドレス、パスワードの入力を求められます。

Create account screen

詳細を入力し、Last step: Invite your teamボタンを押します。

ウィザードでは、他の共同編集者のメールアドレスを入力するように求められますが、画面の下部にあるリンクI’ll do this laterを選択できます。

次に、Ghostがストーリーと呼ぶ投稿のリストが表示されます。

List of stories

左側のメニューでは、新しいストーリーを作成したり、ブログの他の設定を管理したりできます。 詳細については、official documentationを参照してください。

結論

このチュートリアルでは、Ghostをインストールし、リクエストをGhostにプロキシするようにNginxを設定し、Ghostがシステムサービスとして実行されるようにしました。 ただし、Ghostでできることは他にもたくさんあります。 新しいブログの使用方法の詳細については、これらのチュートリアルをご覧ください。

Related