Ghost 0.3.3 をArch Linuxへインストール
Ghost 0.3.3をArch Linuxへインストールしてみたので手順のメモ。
SourceをDownloadし、コンテンツ用Directoryへ配置
cd /usr/local/src
wget https://ghost.org/zip/ghost-0.3.3.zip
cd /srv/http
unzip /usr/local/src/ghost-0.3.3.zip -d ghost
chown -R http ghost
DBを作成
MarinaDBが自動で起動するよう設定
systemctl enable mysqld.service
systemctl start mysqld.service
以下2つのDBを作成
- ghost
- ghost_dev
MarinaDBへログイン
mysql -u root -p
password: ******
MariaDB [(none)]> CREATE DATABASE ghost CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> CREATE DATABASE ghost_dev CHARACTER SET utf8;
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ghost |
| ghost_dev |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
MariaDB [(none)]> GRANT ALL ON ghost.* to ghost@localhost;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON ghost_dev.* to ghost_dev@localhost;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SET PASSWORD FOR ghost@localhost=password('YOUR PASSWORD');
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SET PASSWORD FOR ghost_dev@localhost=password('YOUR PASSWORD');
Query OK, 0 rows affected (0.01 sec)
config.jsを編集
cd /srv/http/ghost
vi config.js
config.jsではDB Client部分をsqlite3からmarinadb(mysql)へ変更します。
config.js
// ### Production
(snip)
client: 'mysql',
connection: {
host: 'localhost',
user: 'ghost',
password: 'YOUR PASSWORD',
database: 'ghost',
charset: 'utf8'
},
(snip)
// ### Development **(default)**
(snip)
database: {
client: 'mysql',
connection: {
host: 'localhost',
user: 'ghost_dev',
password: 'YOUR PASSWORD',
database: 'ghost_dev',
charset: 'utf8'
},
(snip)
npm install
cd /srv/http/ghost
npm install --production
defaultの起動モードをproductionに設定
vi index.js
index.js
process.env.NODE_ENV = 'production';
Apacheの設定
httpd-vhosts.confを読み込むように設定
cd /etc/httpd/conf
vi httpd.conf
httpd.conf
- #Include conf/extra/httpd-vhosts.conf
+ Include conf/extra/httpd-vhosts.conf
VirtualHostを設定する
cd /etc/httpd/conf/extra/
vi httpd-vhosts.conf
httpd-vhosts.conf
#### ghost
<VirtualHost *:80>
ServerAdmin wwwadmin@example.com
DocumentRoot "/srv/http/ghost/"
ServerName example.com
ServerAlias www.example.com
AddDefaultCharset Off
ErrorLog "/var/log/httpd/www.example.com/error_log"
CustomLog "/var/log/httpd/www.example.com/access_log" common
<Proxy *>
order deny,allow
allow from 127.0.0.1
</Proxy>
<IfModule mod_proxy.c>
ProxyPass / http://localhost:2368/
ProxyPassReverse / http://localhost:2368/
ProxyPreserveHost On
</IfModule>
</VirtualHost>
Apacheが自動で起動するよう設定
systemctl enable httpd.service
systemctl start httpd.service
Apacheを起動する。
systemctl start httpd.service
pm2でindex.jsをdaemon化する
pm2をインストールする。
cd /srv/http/ghost
npm install pm2
一応起動させる。
pm2 start /srv/http/ghost/index.js -i max
pm2 list
サーバ起動時にindex.jsが自動で起動するよう設定する
/usr/lib/systemd/systemへ移動し、ghost.serviceを作成
cd /usr/lib/systemd/system/
vi ghost.service
ghost.service
[Unit]
Description=Ghost service
# Make sure we have functional network and logging available
After=syslog.target
After=network.target
[Service]
# Optional, assign custom user and group for this service
User=root
Group=root
# Allow process forking
ExecStart=/usr/bin/pm2 start /srv/http/ghost/index.js -i max
#ExecStop=/usr/bin/pm2 stop all
#ExecReload=/usr/bin/pm2 restart all
Type=forking
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=10
[Install]
WantedBy=multi-user.target