Ghost

From Newroco Tech Docs
Revision as of 08:37, 8 December 2022 by Lucian.pricop (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Installation

First install mysql

apt-get install mysql-server

Open mysql and set a password for root

mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

And put the password in /root/.my.cnf

Install postfix

apt-get install mailutils

Install Node.js

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash
apt-get install -y nodejs

Install Ghost-CLI

npm install ghost-cli@latest -g

Install Ghost

mkdir -p /var/www/sitename
chown <user>:<user> /var/www/sitename
chmod 775 /var/www/sitename
cd /var/www/sitename
ghost install

Instalation questions:

  • Blog URL: http://blog.oxfordarchaeology.com   (NOTE: I've used http because the encryption is done one the proxy, otherwise it will end up in a redirect loop)
  • MySQL hostname: localhost
  • MySQL username / password: root and password   (NOTE: it will use the root only to create a DB and a user with rights for that DB)
  • Ghost database name: blog
  • Set up a ghost MySQL user?: yes
  • Set up NGINX?: no   (NOTE: nginx will be used to proxy pass to the ghost port, but since we already have a proxy no need to use nginx)
  • Set up SSL?: no   (SSL is handled on the proxy)
  • Set up systemd?: yes
  • Start Ghost?: yes

The installer will give you a link to visit so you can finish the installation, but hold on that just a bit.

Edit /var/www/blog/config.production.json to make it listen on the VM's IP instead of just local

  "server": {
    "port": 2368,
    "host": "0.0.0.0"
  },

Edit the same file and configure ghost to use the local SMTP server to send emails

  
"mail": {
    "transport": "SMTP",
    "options": {
       "hosts": "127.0.0.1",
       "port": 25,
       "tls": {
           "rejectUnauthorized": false
       }
    }
  },

Restart the ghost service

systemctl restart ghost_blog-oxfordarchaeology-com.service

On the proxy point the domain to port 2368 instead of the default 80/443. The proxy vhost should look like this:

<VirtualHost *:443>
        ServerName blog.oxfordarchaeology.com

        ProxyPreserveHost On

        RequestHeader set X-Forwarded-Proto "https"
        <Location />
            SSLRequireSSL
        </Location>

        ProxyPass / http://192.168.98.85:2368/
        ProxyPassReverse / http://192.168.98.85:2368/

        CustomLog /var/log/apache2/blog.oxfordarchaeology.access.log combined
        ErrorLog /var/log/apache2/blog.oxfordarchaeology.error.log

SSLCertificateFile /etc/letsencrypt/live/blog.oxfordarchaeology.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/blog.oxfordarchaeology.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

Now you can go to the link provided by the ghost installer at the end and finish the installation on the web interface

Migration

In case we need to move ghost to a different server, for example if updating fails, it may be easier and optimal to simply migrate it to a fresh install. Here are the steps (taken from here):

  • Make sure the new server is updated and has ghost installed to the latest version
  • Run
    ghost backup
    on the source server.
  • Run
    ghost doctor
    to make sure everything checks out before you start to migrate data.
  • Navigate to the Labs view, and click Export to download the content archive
  • Staying on the Labs page, click Download current redirects
  • Download current routes.yaml
  • Navigate to Members, click on the cog at top right and select Export all members, save the file somewhere.
  • Navigate to the Design view, open the Advanced tab to see all themes and click the Download button next to the Active label. This will export your current theme.
  • To download your images, you’ll need shell access to your server.
cd /var/www/ghost/content
zip -r images.zip images/*

Ensure your images folder only contains images. Any other file types may cause import errors.

  • Now go to the new server and do the steps in the same order:
  • Navigate to the Labs view. Next to the Import content header, select your content .json file and click Import
  • Staying on the Labs view, click Upload redirects JSON, then select your redirects.json file to upload it.
  • Then click Upload routes YAML
  • Navigate to Members, click on the cog at top right and select Import members. Upload the file you exported earlier from the source.
  • Head over to the Design view, and click Upload a theme, select your theme .zip file, and activate it.
  • The final step is to upload the images by unzipping the archive into content folder on the new server
cd /var/www/ghost/content
unzip images.zip