How to set up a Clojure/Noir website on WebFaction
Setting up a Noir site on WebFaction is surprisingly easy, thanks to Leiningen. Here’s how I did it. I’m assuming you already have the site built in Noir and you basically know your way around a Linux machine.
Note, this assumes that you haven’t already installed Clojure or Leiningen, but that you already have the JRE, which I believe comes by default on all WebFaction servers.
- In the WebFaction panel, create a new “Custom” -> “Custom App (listening on port)” application and assign it to a website, just like you’re setting up any other site in the panel. Make a note of the port your app was assigned (it’s a column on the Apps List page).
- Download and install Leiningen according to the instructions on the GitHub readme. Basically, just wget the script, chmod it to 755, and put it in /home/yourusername/bin.
- Download your site’s code to the directory for the webapp you created in step 1, so that your project’s project.clj file is directly under /home/yourusername/webapps/yourappname.
- Change the port number in your codebase to the port you made a note of in step 1. To do this, edit Noir’s src/projectname/server.clj file and change 8080 to the new port.
- Now you’re ready to run it. From within the same directory as your project.clj file, run
lein run prodand all of your dependencies should download and install. Once all that’s done, you should be able to pull the site up in a browser.
You should also probably set up a cron job to restart the process if it ever ends (like if the server restarts or the process is killed) using something like this.