2 minute read

The Gandi guides on using NodeJS and MySQL seem to be outdated and it fails on Gandi simple hosting without some tweaking. Here is a simple guide on how to do it. The first thing you want to do is set the hosting environment through Gandi. You need to select the plan - NodeJS with MySQL:

NodeJS with MySQL Gandi Instance

When you have paid for the instance and created you will need to connect to the instance over SFTP. These details are on your Gandi control panel:

Gandi Instance Control Panel

Download the Ghost install package from https://ghost.org/download/. From here you want to unzip the file and open the package.json file in your favourite text editor. Line 66 shows sqlite3 as a dependency. This line needs to be removed as Gandi don’t allow you to build sqllite3 on the simple hosting platform. Without this I found that Ghost would not install properly and just complained of sqllite3 being critical and missing.

Line 66 Package.json removal

We now need to create a MySQL Database and User. You can do this through the phpMyadmin interface Gandi provide. Its strongly recommended you do not use the root user for connecting the database for security.

For speed you can also run these two SQL statements from PhpMyAdmin setting the password appropriately:


CREATE USER ghost@localhost IDENTIFIED BY 'password';

GRANT create,delete,insert,select,update,alter ON ghost.* TO 'ghost'@'localhost';

FLUSH privileges;

phpMyAdmin database, user and permissions setup

Next you need to ssh into your server copy config.sample.js config.js - edit it in a text editor such as Nano:

nano config.js

Change the URL to the correct one, I used the default in this example
setting the url

If you have not done it already, add the following lines, removing the SQLLite database information. Please note Gandi use the following socket /srv/run/mysqld/mysqld.sock, this code block is setup to allow MySQL to connect using a socket, make sure you use the correct mysql details such as the password you set earlier:

    client: 'mysql',
    connection: {
        database: 'ghost',
        user: 'ghost',
        password: 'password',
        socketPath: '/var/run/mysqld/mysqld.sock',
        charset: 'utf8',

Next amend the file so that the ip and port so that is reads below:

    server: {
      port: '8080'

Above is important as your application won’t work without it. Gandi automatically sets Apache to reverse proxy to this port. Now run it! You may get a lot of errors, don’t worry just ignore them.

npm install --production

ssh command

Almost done. On Gandi’s platform they don’t have ability to set the environment on startup. This is easy to fix, all we need to do is edit the core/index.js file in nano and change the default environment from development to production.

Ghost prod from dev setting

Finally we need to start Ghost!

Swap back by to the previous directory using cd .. and then start Ghost using:npm start --production Go to the website address http://your-domain.tld/ghost and you will see the setup screen. The database tables will be created automatically.

The finished product

Setting up Ghost with Gandi was a bit of a pain however it does have many advantages. Its managed for you and pretty cheap. The methods of access are good and you get easy tools and some unusually powerful features such as root database access. Upgrades should be easy from now on, just make sure you remove the sqlite3 and change the start up environment each time using the steps above.



Leave a comment