Knowledgebase
Installing or updating to Ghost 0.4.2 with a MySQL Database
Posted by on 29 October 2013 11:23 AM

Note: the tactic detailed below ONLY works for shared plans. If you have a VPS/Cloud or Dedicated server, no fear... just get in touch with us. We'll prep your server for the Ghost change.

Preparing Your Account For Ghost

Note: you can now use Ghost in a subfolder, but you cannot use the folder "ghost" or you'll break it!

Log in to your cPanel account and create a database

You will need to know the name of  the database, the database user, and the password for the database user when installing Ghost. For the purposes of this document, we'll use 'user_dbname', 'user_dbuser' and 'dbpassword' as examples.

Note: you will need shell access to complete a Ghost installation. If you do not have SSH access currently please contact support to have it enabled and ensure you can connect with an SSH client.

Upgrading Ghost

  1. If you're installing Ghost for the first time, please skip this section and proceed to Installing Ghost.
  2. For our instructional purposes, we'll assume our Ghost install is located at /home/user/ghost.
  3. It is strongly recommended that you have proper backups before upgrading any software or scripts, Ghost included.
  4. cd /home/user/ghost
  5. rm -fr core node_modules app.js
  6. wget --no-check-certificate https://ghost.org/zip/ghost-0.4.2.zip
  7. unzip -o ghost-0.4.2.zip
  8. npm install --production
  9. ln -s index.js app.js
  10. mkdir -p tmp
  11. touch tmp/restart.txt

Installing Ghost

  1. Create a folder in which you can install Ghost

    Note: Since SSH is required in later steps we'll walk through the process using SSH. The folder should not be within your public_html folder and should exist in a non-web accessible area of your web hosting space.
     
  2. cd /home/user
  3. mkdir ghost
  4. Via the download link at http://ghost.org obtain the current source version of Ghost, which is 0.4.2.
  5. Place the Ghost source code in the newly created folder
  6. cd ghost
  7. wget --no-check-certificate https://ghost.org/zip/ghost-0.4.2.zip
  8. unzip ghost-0.4.2.zip     
  9. rm -f ghost-0.4.2.zip

Configure Ghost for Your Website and Database

Ghost provides an example configuration file that we'll use as a template. Where you just installed the Ghost source make a copy of the example configuration file to one Ghost will use.
  1. cp config.example.js config.js
  2. Open config.js and navigate to the Production: section so that you can make a handful of changes:
    • url: - Set this to the full URL for the finished ghost
      • Example - url: 'http://blog.domain.tld'
    • mail: - If you want to configure it refer to the config.example.js file for details (around lines 13-26), otherwise leave this blank
    • database: - Set your database details per the following as examples

      database: {
      client: 'mysql',
        connection: {host: '127.0.0.1',
        user: 'user_dbuser',
      password: 'dbpassword',
      database: 'user_dbname',
      charset: 'utf8'
      }, 
    • debug: - We recommend that this stays set to 'false'

Note: the server: section should be kept, but does not need to be adjusted.

Install Ghost's Dependencies

  1. npm install mysql
  2. npm install --production

    Note: you will see an error regarding sqlite3 in step 1.2; failing to compile. This is normal and should be ignored. Sqlite3 is available via the globally available node.js modules instead.
     
  3. Create the following symlink (to configure the node.js applications for the server): ln -s index.js app.js
  4. Create a tmp directory for node.js applications so that Ghost can function properly: mkdir tmp
  5. Trestart Ghost in the future: touch /home/user/ghost/tmp/restart.txt
  6. Go to the public_html directory for the domain that will be hosting Ghost (if the web hosting account has nothing else in it, this is probably public_html in the root of your account): cd /home/user/public_html
  7. Create a file named .htaccess (make sure to include the period at the beginning) and tell the web server to use Ghost by placing the following in the .htacces file:

    PassengerEnabled on
    PassengerAppRoot /home/user/ghost
    SetEnv NODE_ENV production
    SetEnv NODE_PATH /usr/lib/node_modules  

Ghost should now be installed. Go ahead and create the administration user for Ghost by visiting http://blog.domain.tld/admin/ (if url: is set to http://blog.domain.tld), which will prompt you to create the admin user for Ghost.

You can stop here for a standard setup. If you're interested in multiple configurations or using SQLite, read on....

Multiple Configurations, SQLite and more

Ghost also supports SQLite for a database backend, along with multiple configurations. For instance, you could set up a developer config with an SQLite database for testing. In the config.js file from earlier we only had you adjust the production configuration.

To set up an alternate configuration:

Open config.js in your favorite editor and in the development: section set the database: portion to:

                database: {
                    client: 'sqlite3',
                    connection: {
                     filename: path.join(__dirname, '/content/data/mytesting.db')
                        },
The filename about is relative to the installed directory, so in this case would be /home/user/ghost/content/data/mytesting.db
  1. In the .htaccess file from earlier adjust the NODE_ENV line to development. You can do this for any configuration in the config.js file, just make sure it matches the name from that file. The new file will look like:

    PassengerEnabled on
    PassengerAppRoot /home/user/ghost
    SetEnv NODE_ENV development
    SetEnv NODE_PATH /usr/lib/node_modules

     
  2. If your blog is already running restart to apply the new configuration automatically: touch /home/user/ghost/tmp/restart.txt
  3. Visit your blog, which should now be using the alternate configuration
Note: all settings are stored in the database, so don't be surprised that it looks like a newly installed blog. Simply revert the change in the .htaccess file and restart Ghost again to bring it back.

Backing up Ghost

Ghost does provide rudimentary backup features, but please be aware that backups consist of text only. Binary items such as images are not included. For example purposes, we'll assume ghost is located at  http://blog.domain.tld.
  1. Browse to http://blog.domain.tld/ghost/debug/.
  2. Click the Export button.
  3. Choose a safe location to save your backup.

Ghost is behaving very strangely, images and links are broken, stylesheets are missing, etc and soforth!

Did you install Ghost to a sub-directory, with something like Wordpress installed above it? If so, the .htaccess file above the ghost install is most likely causing the problem. Open the .htaccess file you created for Ghost, and add this line at the top, then save the file:
RewriteEngine off
I changed or updated Ghost's theme and the changes aren't displaying!

Since Ghost runs as a persistent process for an amount of time, Ghost simply needs to be restarted for the changes to take effect. To do this, simply:
touch /home/user/ghost/tmp/restart.txt

Remember that the above path is only an example, you'd need to touch the tmp/restart.txt file under your actual ghost install.
(8 vote(s))
This article was helpful
This article was not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
Help Desk Software by Kayako Fusion