Install KeystoneJS on an Ubuntu 14.04

install-keystonejs-on-an-ubuntu-14-04In this blog post we will show you how to install KeystoneJS on an Ubuntu 14.04 VPS with the latest version of Nginx as a reverse proxy. KeystoneJS is a Node.js content management system and web application platform built on MongoDB and Express. This guide should work on other Linux VPS systems as well but was tested and written for Ubuntu 14.04 VPS.

Login to your VPS via SSH

ssh user@myVPS

Update the system and install necessary packages.

user@myVPS:~# sudo apt-get update && sudo apt-get -y upgrade
user@myVPS:~# sudo apt-get install python-software-properties

Install Node.js

We will install the latest nodejs package from Chris Lea’s repo.

user@myVPS:~# sudo add-apt-repository ppa:chris-lea/node.js
user@myVPS:~# sudo apt-get update
user@myVPS:~# sudo apt-get install nodejs

Install MongoDB

We will install the latest mongo package from the official MongoDB repository.

user@myVPS:~# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
user@myVPS:~# echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
user@myVPS:~# sudo apt-get update
user@myVPS:~# sudo apt-get install -y mongodb-org

Install KeystoneJS

We will install KeystoneJS using the KeystoneJS generator made with Yeoman.

user@myVPS:~# sudo npm install -g generator-keystone
user@myVPS:~# mkdir ~/myKeystoneApp
user@myVPS:~# cd ~/myKeystoneApp
user@myVPS:~# yo keystone

The generator will ask you a few questions, install all npm dependencies and configure and copy all the files into the newly created project.

When the installation is finished, run the following to start the KeystoneJS:

user@myVPS:~# node keystone

If you see the below message, it means you’ve successfully installed KeystoneJS.

------------------------------------------------
KeystoneJS Started:
My Site is ready on default port 3000
------------------------------------------------

Stop the process with Control-C and continue with the Forever installation.

In case you never heard of Forever, it is a tool which ensures that a given script runs forever.

user@myVPS:~# sudo npm install forever -g

Now you can use forever to start your KeystoneJS instance.

user@myVPS:~# cd ~/myKeystoneApp
user@myVPS:~# forever start keystone.js

Install and Configure Nginx

The latest version of Nginx 1.6.2 is not available via the default Ubuntu repositories, so we will add the “nginx/stable” PPA, update the system and install the nginx package.

user@myVPS:~# sudo add-apt-repository ppa:nginx/stable
user@myVPS:~# sudo apt-get update
user@myVPS:~# sudo apt-get install nginx

Create a new Nginx server block with the following content

user@myVPS:~# sudo nano /etc/nginx/conf.d/myKeystoneApp.com
server {
    server_name myKeystoneApp.com;
    listen 80;

    access_log /var/log/nginx/myKeystoneApp-access.log;
    error_log /var/log/nginx/myKeystoneApp-error.log;

    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:3000;
    }
 
}

Test the Nginx configuration and restart the server

user@myVPS:~# sudo nginx -t
user@myVPS:~# sudo /etc/init.d/nginx restart

That’s it. Now open your browser and type the address of your website ex: http://myKeystoneApp.com.

For more information about how manage your KeystoneJS application ,please refer to the official KeystoneJS website.


Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

1 thought on “Install KeystoneJS on an Ubuntu 14.04”

Leave a Comment