Ghost: Difference between revisions

From Newroco Tech Docs
Jump to navigationJump to search
No edit summary
No edit summary
Line 5: Line 5:
Open mysql and set a password for root
Open mysql and set a password for root
<code>mysql -u root
<code>mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';</code>
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
</code>


And put the password in '''/root/.my.cnf'''
And put the password in '''/root/.my.cnf'''
Line 14: Line 15:
Install Node.js
Install Node.js
<code>curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash
<code>curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash
apt-get install -y nodejs</code>
apt-get install -y nodejs
</code>


Install Ghost-CLI
Install Ghost-CLI
<code>npm install ghost-cli@latest -g</code>
<code>npm install ghost-cli@latest -g
</code>


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


Instalation questions:
Instalation questions:
Line 47: Line 52:


Edit the same file and configure ghost to use the local SMTP server to send emails
Edit the same file and configure ghost to use the local SMTP server to send emails
<code>  "mail": {
<code>   
"mail": {
     "transport": "SMTP",
     "transport": "SMTP",
     "options": {
     "options": {
Line 56: Line 62:
       }
       }
     }
     }
   },</code>
   },
</code>


Restart the ghost service
Restart the ghost service
Line 63: Line 70:
On the proxy point the domain to port 2368 instead of the default 80/443. The proxy vhost should look like this:
On the proxy point the domain to port 2368 instead of the default 80/443. The proxy vhost should look like this:


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


Line 82: Line 90:
SSLCertificateKeyFile /etc/letsencrypt/live/blog.oxfordarchaeology.com/privkey.pem
SSLCertificateKeyFile /etc/letsencrypt/live/blog.oxfordarchaeology.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost></code>
</VirtualHost>
</code>


Now you can go to the link provided by the ghost installer at the end and finish the installation on the web interface
Now you can go to the link provided by the ghost installer at the end and finish the installation on the web interface
Line 100: Line 109:
<code>cd /var/www/ghost/content</code>
<code>cd /var/www/ghost/content</code>
<code>zip -r images.zip images/*</code>
<code>zip -r images.zip images/*</code>
Ensure your images folder only contains images. Any other file types may cause import errors.
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:
* Now go to the new server and do the steps in the same order:

Revision as of 08:36, 8 December 2022

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