We will see in this tutorial how to install Ghost in only a few minutes on a Simple Hosting NodeJS / MySQL instance.
In this tutorial, we will use the Gandi CLI to simplify the installation and deployment. To install and configure Gandi CLI, navigate to http://cli.gandi.net
First, we will create the instance :
$ gandi paas create --name Ghost --type nodejsmysql --duration 1m password: Repeat for confirmation: Creating your PaaS instance.
We will then clone the repository (which will be empty because we just created the instance) :
$ gandi paas clone Ghost
We will then navigate to the 'default' directory, which is where our application code must reside, followed by downloading and decompressing the Ghost application from the official website :
$ cd default $ wget https://github.com/TryGhost/Ghost/releases/download/1.5.2/Ghost-1.5.2.zip $ unzip Ghost-1.5.2.zip && rm Ghost-1.5.2.zip
As Ghost prefers the latest Node LTS version, create an .nvmrc file with the following command to specify the version of Node your instance will use :
$ echo '6.9.5' > .nvmrc
We will now connect to the console of the instance to create a database and user named 'ghost', and as well assign the proper rights :
$ gandi paas console Ghost hosting-user@Ghost:/srv/data$ mysql -u root mysql> CREATE DATABASE ghost; Query OK, 1 row affected (0.01 sec) mysql> CREATE USER ghost; Query OK, 0 rows affected (0.00 sec) mysql> GRANT ALL ON ghost.* to 'ghost'@'localhost' identified by 'RRTCPDK%'; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> quit hosting-user@Ghost:/srv/data$ exit
We will create a production config file in the root of the project directory :
$ touch config.production.json
Add the below code to the json file and edit the following :
{ "url": "http://dac8feb342.testurl.ws", "server": { "host": "127.0.0.1", "port": 8080 }, "database": { "client": "mysql", "connection": { "socketPath": "/srv/run/mysqld/mysqld.sock", "user": "ghost", "password": "RRTCPDK%", "name": "ghost", "charset": "utf8" } }, "auth": { "type": "password" }, "paths": { "contentPath": "content/" }, "logging": { "level": "info", "rotation": { "enabled": true }, "transports": ["file", "stdout"] } }
Next, we need to verify that the “knex-migrator” dependency is at least at version 2.1.6, which has MySQL unix socket support.
Use your favorite editor :
$ nano package.json
And edit the following line if required to 2.1.6 or above :
"knex-migrator": "2.1.6",
We will replace the database initialization and migration script required in Ghost > 1.x :
$ rm MigratorConfig.js $ touch MigratorConfig.js
Add the below code to the MigratorConfig.js file and edit the following :
var ghostVersion = require('./core/server/utils/ghost-version'); require('./core/server/overrides'); module.exports = { currentVersion: ghostVersion.safe, database: { client: 'mysql', connection: { socketPath: '/srv/run/mysqld/mysqld.sock', user: 'ghost', password: 'RRTCPDK%', charset: 'utf8', database: 'ghost' } }, migrationPath: process.cwd() + '/core/server/data/migrations', currentVersion: ghostVersion.safe };
We are now ready to deploy the application on the instance :
$ git add . $ git commit -am "First commit with Ghost source files and setup" $ git push origin master $ gandi deploy
Connect to the instance's console :
$ gandi paas console Ghost
Navigate to the default vhosts directory, initialize the database, and reload the application :
hosting-user@Ghost:/srv/data$ cd /srv/data/web/vhosts/default/ hosting-user@Ghost:/srv/data/web/vhosts/default$ NODE_ENV=production node_modules/.bin/knex-migrator init hosting-user@Ghost:/srv/data/web/vhosts/default$ reload_application
Once done, your application should then be available at the website address you specified. In this example, we did not use add a new virtual host, but used the default vhost provided when the instance is created.