Bitnami Ghost for Google Cloud Platform

Description

Ghost is a platform dedicated to one thing: Publishing. It is beautifully designed, completely customizable and completely open source. Ghost allows you to write and publish your own blog, giving you the tools to make it easy and even fun to do.

First steps with the Bitnami Ghost Stack

Welcome to your new Bitnami application running on Google Cloud Platform! Here are a few questions (and answers!) you might need when first starting with your application.

What is the administrator username set for me to log in to the application for the first time?

Username: user@example.com

What is the administrator password?

What SSH username should I use for secure shell access to my application?

SSH username: bitnami

How to start or stop the servers?

Each Bitnami stack includes a control script that lets you easily stop, start and restart servers. The script is located at /opt/bitnami/ctlscript.sh. Call it without any service name arguments to start all services:

$ sudo /opt/bitnami/ctlscript.sh start

Or use it to restart a single service, by passing the service name as argument. For example, if the stack uses the Apache Web server, use the command below to restart it:

$ sudo /opt/bitnami/ctlscript.sh restart apache

Or, if the stack uses the Nginx server, use the command below to restart it:

$ sudo /opt/bitnami/ctlscript.sh restart nginx

Use this script to stop all services:

$ sudo /opt/bitnami/ctlscript.sh stop

Restart the services by running the script without any arguments:

$ sudo /opt/bitnami/ctlscript.sh restart

Obtain a list of available services and operations by running the script without any arguments:

$ sudo /opt/bitnami/ctlscript.sh  

How to create a full backup of Ghost?

Backup

The Bitnami Ghost Stack is self-contained and the simplest option for performing a backup is to copy or compress the Bitnami stack installation directory. To do so in a safe manner, you will need to stop all servers, so this method may not be appropriate if you have people accessing the application continuously.

Follow these steps:

  • Change to the directory in which you wish to save your backup:

      $ cd /your/directory
    
  • Stop all servers:

      $ sudo /opt/bitnami/ctlscript.sh stop
    
  • Create a compressed file with the stack contents:

      $ sudo tar -pczvf application-backup.tar.gz /opt/bitnami
    
  • Restart all servers:

      $ sudo /opt/bitnami/ctlscript.sh start
    

You should now download or transfer the application-backup.tar.gz file to a safe location.

Restore

Follow these steps:

  • Change to the directory containing your backup:

      $ cd /your/directory
    
  • Stop all servers:

      $ sudo /opt/bitnami/ctlscript.sh stop
    
  • Move the current stack to a different location:

      $ sudo mv /opt/bitnami /tmp/bitnami-backup
    
  • Uncompress the backup file to the original directoryv

      $ sudo tar -pxzvf application-backup.tar.gz -C /
    
  • Start all servers:

      $ sudo /opt/bitnami/ctlscript.sh start
    

If you want to create only a database backup, refer to these instructions for MySQL and PostgreSQL.

How to configure outbound email settings?

Google Cloud Platform doesn't allow SMTP traffic through default ports: 25, 465, 587. Check Google cloud documentation to learn how to use a VPN to bypass these restrictions or use a different port for sending emails from your application.

Configure the email settings in the /opt/bitnami/apps/ghost/htdocs/config.js file by adding the code below in the environment section between the url and database fields, eg. production. Here's an example using Gmail. Replace USERNAME and PASSWORD with your Gmail account username and password respectively.

mail: {
    from: 'USERNAME@gmail.com',
    transport: 'SMTP',
    host: 'smtp.gmail.com', 
    options: {
        service: 'Gmail', 
        port: 465,
    secure: true, // use SSL 
        auth: { 
            user: 'USERNAME@gmail.com',
            pass: 'PASSWORD' 
        },
    }, 
 },

Then, restart all services for changes to take effect:

$ sudo /opt/bitnami/ctlscript.sh restart ghost
$ sudo /opt/bitnami/ctlscript.sh restart apache

To configure the application to use other third-party SMTP services for outgoing email, such as SendGrid or Mandrill, refer to the FAQ.

If you are using Gmail as the outbound email server and you are not receiving emails correctly, make sure that the Google "Allow less secure apps" option is activated. To do so:

Allow less secure apps in Gmail

How to upload files to the server with SFTP?

Although you can use any SFTP/SCP client to transfer files to your server, the link below explains how to configure FileZilla (Windows, Linux and Mac OS X), WinSCP (Windows) and Cyberduck (Mac OS X). It is required to use your server's private SSH key to configure the SFTP client properly. Choose your preferred application and follow the steps in the link below to connect to the server through SFTP.

How to upload files to the server

How to enable HTTPS support with SSL certificates?

NOTE: The steps below assume that you are using a custom domain name and that you have already configured the custom domain name to point to your cloud server.

Bitnami images come with SSL support already pre-configured and with a dummy certificate in place. Although this dummy certificate is fine for testing and development purposes, you will usually want to use a valid SSL certificate for production use. You can either generate this on your own (explained here) or you can purchase one from a commercial certificate authority.

Once you obtain the certificate and certificate key files, you will need to update your server to use them. Follow these steps to activate SSL support:

  • Use the table below to identify the correct locations for your certificate and configuration files.

    Variable Value
    Current application URL https://[custom-domain]/
      Example: https://my-domain.com/ or https://my-domain.com/appname
    Apache configuration file /opt/bitnami/apache2/conf/bitnami/bitnami.conf
    Certificate file /opt/bitnami/apache2/conf/server.crt
    Certificate key file /opt/bitnami/apache2/conf/server.key
    CA certificate bundle file (if present) /opt/bitnami/apache2/conf/server-ca.crt
  • Copy your SSL certificate and certificate key file to the specified locations.

NOTE: If you use different names for your certificate and key files, you should reconfigure the SSLCertificateFile and SSLCertificateKeyFile directives in the corresponding Apache configuration file to reflect the correct file names.
  • If your certificate authority has also provided you with a PEM-encoded Certificate Authority (CA) bundle, you must copy it to the correct location in the previous table. Then, modify the Apache configuration file to include the following line below the SSLCertificateKeyFile directive. Choose the correct directive based on your scenario and Apache version:

    Variable Value
    Apache configuration file /opt/bitnami/apache2/conf/bitnami/bitnami.conf
    Directive to include (Apache v2.4.8+) SSLCACertificateFile "/opt/bitnami/apache2/conf/server-ca.crt"
    Directive to include (Apache < v2.4.8) SSLCertificateChainFile "/opt/bitnami/apache2/conf/server-ca.crt"
NOTE: If you use a different name for your CA certificate bundle, you should reconfigure the SSLCertificateChainFile or SSLCACertificateFile directives in the corresponding Apache configuration file to reflect the correct file name.
  • Once you have copied all the server certificate files, you may make them readable by the root user only with the following commands:

     $ sudo chown root:root /opt/bitnami/apache2/conf/server*
    
     $ sudo chmod 600 /opt/bitnami/apache2/conf/server*
    
  • Open port 443 in the server firewall. Refer to the FAQ for more information.

  • Restart the Apache server.

You should now be able to access your application using an HTTPS URL.

How to create an SSL certificate?

You can create your own SSL certificate with the OpenSSL binary. A certificate request can then be sent to a certificate authority (CA) to get it signed into a certificate, or if you have your own certificate authority, you may sign it yourself, or you can use a self-signed certificate (because you just want a test certificate or because you are setting up your own CA).

  • Create your private key (if you haven't created it already):

     $ sudo openssl genrsa -out /opt/bitnami/apache2/conf/server.key 2048
    
  • Create a certificate:

     $ sudo openssl req -new -key /opt/bitnami/apache2/conf/server.key -out /opt/bitnami/apache2/conf/cert.csr
    
    IMPORTANT: Enter the server domain name when the above command asks for the "Common Name".
  • Send cert.csr to the certificate authority. When the certificate authority completes their checks (and probably received payment from you), they will hand over your new certificate to you.

  • Until the certificate is received, create a temporary self-signed certificate:

     $ sudo openssl x509 -in /opt/bitnami/apache2/conf/cert.csr -out /opt/bitnami/apache2/conf/server.crt -req -signkey /opt/bitnami/apache2/conf/server.key -days 365
    
  • Back up your private key in a safe location after generating a password-protected version as follows:

     $ sudo openssl rsa -des3 -in /opt/bitnami/apache2/conf/server.key -out privkey.pem
    

    Note that if you use this encrypted key in the Apache configuration file, it will be necessary to enter the password manually every time Apache starts. Regenerate the key without password protection from this file as follows:

     $ sudo openssl rsa -in privkey.pem -out /opt/bitnami/apache2/conf/server.key
    

Find more information about certificates at http://www.openssl.org.

How to debug Apache errors?

Once Apache starts, it will create two log files at /opt/bitnami/apache2/logs/access_log and /opt/bitnami/apache2/logs/error_log respectively.

  • The access_log file is used to track client requests. When a client requests a document from the server, Apache records several parameters associated with the request in this file, such as: the IP address of the client, the document requested, the HTTP status code, and the current time.

  • The error_log file is used to record important events. This file includes error messages, startup messages, and any other significant events in the life cycle of the server. This is the first place to look when you run into a problem when using Apache.

If no error is found, you will see a message similar to:

Syntax OK

How to force HTTPS redirection?

Add the following to the top of the /opt/bitnami/apps/ghost/conf/httpd-prefix.conf file:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]

After modifying the Apache configuration files, restart Apache to apply the changes.

How to debug Apache errors?

Once Apache starts, it will create two log files at /opt/bitnami/apache2/logs/access_log and /opt/bitnami/apache2/logs/error_log respectively.

  • The access_log file is used to track client requests. When a client requests a document from the server, Apache records several parameters associated with the request in this file, such as: the IP address of the client, the document requested, the HTTP status code, and the current time.

  • The error_log file is used to record important events. This file includes error messages, startup messages, and any other significant events in the life cycle of the server. This is the first place to look when you run into a problem when using Apache.

If no error is found, you will see a message similar to:

Syntax OK

How to configure the Ghost domain name?

Ghost requires the domain name to be specified in the config.js file. For example:

production: {
    url: 'example.com',

Set your own domain name in this file manually or change it automatically with the bnconfig configuration tool:

$ sudo /opt/bitnami/apps/ghost/bnconfig --machine_hostname example.com

Then, rename or remove this tool so that it does not change again at boot time:

$ sudo mv /opt/bitnami/apps/ghost/bnconfig /opt/bitnami/apps/ghost/bnconfig.back

How to configure the Ghost mode from "production" to "development"?

Bitnami Ghost is configured to use "production" mode by default. This is necessary to configure the email settings.

If you are developing a theme or you are editing files, you may prefer to use "development" mode. To do this, edit the /opt/bitnami/apps/ghost/scripts/ctl.sh file and replace the references to

"NODE_ENV=production" 

with

"NODE_ENV=development". 

Then, restart the Ghost server.

How to install a theme?

Install a theme using the command line

Ghost themes live in the /opt/bitnami/apps/ghost/htdocs/content/themes directory and are also available in Ghost Marketplace.

  • Download your theme and uncompress it in this folder alongside the Casper default theme. Then, configure the permissions appropriately:

      $ cd /opt/bitnami/apps/ghost/htdocs/content
      $ sudo chown -R bitnami:daemon themes
    

To switch to your newly added theme:

  • Restart Ghost.

       $ sudo /opt/bitnami/ctlscript.sh restart ghost
    
  • Log in to your application, and navigate to "Settings -> General".

  • Select your theme name and click the "Save" button.

Install a theme using the Web interface

  • Download the theme in Ghost Marketplace.

  • Log into the application and navigate to "Settings -> General" section. Scroll down to the bottom of the page. Click the "Upload a theme" button.

Ghost General Settings

  • Browse to the .zip file in your computer and drag and drop to upload it. Wait until the upload is complete.

Upload a theme

  • You will see a confirmation message. Click the "Activate now" button if you want to activate the theme. Click the "Close" button to exit.

Successful upload

  • The new theme is displayed in the "Themes" section. Select the theme in the list and click the action you want to perform.

Activate a new theme

How to upgrade Ghost?

Step 1: Export Ghost data

If you have important data, it is advisable that you create and try to restore a backup to ensure that everything works properly. Follow these basic steps to safeguard your information:

  • Log in to your application and navigate to "Settings -> Labs" section which is located in the left margin of the Administration panel.

  • Click the "Export" button. A .json file with your blog data will be automatically downloaded.

Ghost export

  • Create a backup of the images, plugins and themes. These files are in the /opt/bitnami/apps/ghost/htdocs/content folder.

  • Create a new folder in the root of your Ghost install and make a copy there of the content folder. Here's an example. Replace BACKUP with your new folder name.

      $ mkdir /opt/bitnami/apps/BACKUP
      $ cp -R /opt/bitnami/apps/ghost/htdocs/content  /opt/bitnami/apps/BACKUP  
    
Step 2: Get the latest Ghost version

Get the latest release of Ghost from Ghost download page, GitHub release page or by running this command:

$ wget https://ghost.org/zip/ghost-latest.zip
Step 3: Unzip the latest Ghost version

Once you have downloaded the latest version, unzip or extract the .zip file into a temporary location.

  • Create a temporary directory for unzipping latest Ghost version. Follow the example below and remember to replace GHOSTLATEST with your directory name.

      $ mkdir /opt/bitnami/apps/GHOSTLATEST
    
  • Extract the .zip file to the new temporary directory.

      $ unzip ghost-latest.zip -d /opt/bitnami/apps/GHOSTLATEST
    
Step 4: Delete old files

Delete the whole core directory and index.js file both of which are located in the /opt/bitnami/apps/ghost/htdocs/content directory.

NOTE: Do not delete the config.js file.
$ cd /opt/bitnami/apps/ghost/htdocs/content
$ sudo rm index.js
$ sudo rm -rf core
Step 5: Copy over new files
  • Copy the following directory and files from your newly downloaded latest version of Ghost. They will replace the older files you removed in the prior step:

    • core folder
    • index.js
    • package.json
    • nmp-shrinkwrap.json
  • You can also copy .md files in order to have updated useful information:

    • PRIVACY.md
    • README.md

Here is an example of how to copy the new core folder (which is critical for a successful upgrading). Repeat this procedure with all the files mentioned above.

$ sudo cp -R /opt/bitnami/apps/GHOSTLATEST/core  /opt/bitnami/apps/ghost/htdocs/ 
NOTE: All files must be copied to the /opt/bitnami/apps/ghost/htdocs/ directory.
Step 6: Check and update the permissions
  • Check if you have the correct permissions for the files recently copied. Make sure that you are in the /opt/bitnami/apps/ghost/htdocs/ directory.

  • Run the following command to update the permissions of the core directory:

      $ sudo chown -R bitnami:daemon core
    
Step 7: Update dependencies
  • Staying in the same directory as above, run the following command and wait for this to complete.

      $ sudo npm install --production
    

    This step needs to complete without errors (warnings must be OK). If anything goes wrong do the following:

  • Remove the node_modules folder.

      $ sudo rm -rf node_modules
    
  • Run this command in order to clean the cache:

      $ sudo npm cache clean
    
  • Try again to update dependencies:

      $ sudo npm install --production 
    
  • Check the updating process details in the npm-debug.log file which is located in the /opt/bitnami/apps directory.

Step 8: Restart Ghost

This step provides the information about that everything went well during the upgrading.

  • Stop and restart Ghost:

      $ sudo sudo /opt/bitnami/ctlscript.sh stop ghost
      $ sudo sudo /opt/bitnami/ctlscript.sh restart ghost
    
  • Exite the console and restart the server to get Ghost running normally again.

Step 9: Import Ghost data

  • Log in to your application and navigate to "Settings -> Labs" section which is located in the left margin of the Administration panel.
  • Click the "Import" button and attach the .json file you have downloaded before. Check Export Ghost Data section.

  • Once you have the new Ghost server running, import your blog data in the new installation.

Ghost import