Ok, so you have your hosting setup and you’re ready to get to work. But you’re not planning to use one of the pre-built installers which take care of just about all of the work for you. You’re planning to deploy an application using KeystoneJS.
The question is, how do you do it? Well, at the moment, there’s no pre-built installers outside of these, so you need to install it by hand.
But not to worry, this guide’s here to guide you through the process, so that you’ll be up and running in no time; right from creation of the sub-domain, through to viewing the running application.
By the time we’re done, you’ll see the site as in the screenshot below:
What is KeystoneJS
In a nutshell, KeystoneJS is:
Node.js CMS and web application platform built on Express and MongoDB.
- Dynamic Routing
- Form Processing
- Email Sending
- Session Management
- Auto-generated Amin Interface
To find out more about it, check out the official website.
To complete today’s tutorial, you’re only going to need a few prerequisites. These are:
- Root access (or user with sufficient privileges or who’s in the sudoers list)
Right, so what do we need to do to set it up? Thanks to the modern UI, and intelligent layout available in Plesk 12, it’s a real no brainer, requiring only a few steps to have it live, which are as follows:
- Create a Sub-Domain
- Setup SSH Access
- Install NodeJS
- Configure NodeJS
- View The Application
Let’s work through the process now.
Create a Sub-Domain
When you first login to your account, click the Domains in the left-hand side navigation bar, under Hosting Services. This will then show you the list of your websites & domains. To keep this simple, we’re going to create a new sub-domain, specifically under huffyscrew.com.
On the far right of that domain’s row in the table, click “Manage Hosting“. This will display the domain and sub-domain entries, which you can see in the screenshot below.
Above the first entry, you’ll see three buttons: “Add New Domain“, “Add New Subdomain” and “Add New Domain Alias“. Click “Add New Subdomain”, and on the form which appears, enter “keystonejs” for the subdomain name.
The Document root field will be pre-populated, based on the Subdomain name you entered. It may take a minute or two for the subdomain to be created, based on your server’s specifications. But it shouldn’t take too long.
When it’s finished you’ll be back on the domains page you started at, with your new domain available at the bottom of the list. In the entry, you’ll see all the pertinent details, along with links to more, as well as to make changes.
Setup SSH Access
Now we need to check that SSH access is setup properly, so that we can login and run a few command line scripts. If you’re not too familiar with command line scripts, that’s ok. The one’s I’ve listed here are quite simple and have sufficient documentation, should it be needed.
At the bottom of the subdomain’s entry, click the tab titled “Show More“, then click the first entry in the exposed list, titled “Web Hosting Access“. On the page that appears, you’ll see four sections.
In the second section, titled “System user“, make sure that the last option, “Access to the server over SSH“, is set to /bin/bash or /bin/sh and click OK at the bottom.
The reason for this is because these scripts need that environment to run in. sh may work, but bash works best for this example. Now you’re ready to login and begin installing the application.
Note: if you’re not sure of the user’s password, either regenerate it or check with your systems administrator.
As KeystoneJS uses MongoDB to store its data, we need to get it installed. I’m assuming that you’re using a Linux distribution, either Debian or Redhat-based, covered the respective installation options for below.
Installing on Debian/Ubuntu
MongoDB is available in the Debian and Ubuntu APT repositories, but I’ve never really found it to be too stable. So instead I suggest you use the official MongoDB repository. To integrate them with APT, run the following commands:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list sudo apt-get update sudo apt-get install mongodb-org
What these commands do are to import the required public key into the package manager, add the MongoDB repository to the list of available package repositories, update the package database and install MongoDB.
What they don’t do is to start the MongoDB server. To do that, run
sudo /etc/init.d/mongod start
Installing on Redhat/Centos
As with the Debian and Ubuntu APT repositories, I’ve never really found the installation of MongoDB provided by Yum to be too stable either. So to install the official distribution, first create the file/etc/yum.repos.d/mongodb.repo, and in it add the configuration below:
[mongodb] name=MongoDB Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/ gpgcheck=0 enabled=1
With that saved, run the following commands, which install and start the MongoDB server:
yum install mongo-10gen mongo-10gen-server sudo /etc/init.d/mongod start
One of the best things about KeystoneJS is that it uses Node.js Package Manager (NPM), making it so easy to install. So from the command line, run the following command, which gets everything done.
npm install -g generator-keystone
Creating The First KeystoneJS App
Now that all the dependencies are satisfied, let’s build the first project. From the project directory root run the following commands:
mkdir my-test-project cd my-test-project yo keystone
Collectively, these create a project directory then use Yeoman to create the first KeystoneJS project. It’s a really helpful installer which will guide you through the installation process, which you can see a screenshot of below:
The installer asks you a number of questions, including the project name, the template language to use, whether you want a blog, email and Cloudinary configuration to be setup with it. Answer the questions as best suit your environment. When you’re done, you’ll see output like this below.
Your KeystoneJS project is ready to go! For help getting started, visit http://keystonejs.com/guide We've included a demo Cloudinary Account, which is reset daily. Please configure your own account or use the LocalImage field instead before sending your site live. To start your new website, run "node keystone".
This means that you’re all ready to go. So to start up the app and see it in action, run node keystone. This will give you a helpful confirmation message, as below, and you’ll then be able to view the application at http://<your ip address>:3001.
------------------------------------------------ KeystoneJS Started: Conetix Test Site is ready on port 3001 ------------------------------------------------
View The Application
It’s not that special, actually it’s only a one page application, but it works and is ready to be built on as you see fit and looks like the screenshot below. Nice, simple and effective.
So there you go. In just a few minutes, we’ve stepped through creating and configuring a sub-domain, and installing a sample KeystoneJS application.
Now it’d be great if it was simpler, such as having an installer for Drupal, Joomla and WordPress. But it’s a bit hard to compare off the shelf applications, such as these, to frameworks which allow for creating nearly any kind of application.
What I’m hoping for is to have an installer which lays the foundation for this process, which may just be available in the future.
Till then, share your thoughts in the comments. Has this made it simpler for you to start creating applications with KeystoneJS on Plesk? I hope so. I’d love to hear how you feel.