In this guide I'll try to run you through getting DBSlayer to work on Ubuntu (or a general Debian system). DBSlayer is a proxy for mysql databases through which you can communicate using JSON over HTTP. I still have to run a few tests because I'm afraid the overhead of making HTTP requests could be a problem, but it's not like I have to worry about high performing websites right now, right :p
So this guide is a continuation of
my previous guide to get
Node.js running "on Windows" using VirtualBox. So I'm running this on my relatively freshly installed Ubuntu having just installed Node.js. My system has a root user with unknown password, but you can basically sudo your way through anything using "reverse" as password.
Well then. In a nutshell we need to install
Subversion, because that's not installed on my system. We'll be using that to install DBSlayer and we'll install a
MySQL server. Note that, if SVN is installed on your system, you don't need to install it :) Likewise, if you already have a MySQL server running somewhere to which you can connect, you don't _need_ to install one on your machine.
Because I'm running a virtual machine, I don't really care about the things I install and how much they could screw up my OS, I only use it to play around. So be warned, I take no responsibilities for these steps or whatever. They worked on my environment, heck knows what it'll do to yours :)
You can use a flag to "automatically" sudo everything. Likewise, if you are logged in as root, the sudo prefix is not really needed for you. In my examples I prefix whatever is required to sudo, with sudo.
So, first we'll install SVN on the system. Go to your terminal (menu -> applications -> accessories -> terminal) and enter whatever is marked to be entered in the terminal. Please do look at your screen every now and then. Sometimes you have to wait and sometimes errors show up which I won't anticipate. Good luck with them :)
So, SVN. Skip this step if you already have it installed (you'll probably get a warning if you try anyways):
sudo apt-get install subversion
Now we'll download the latest version of DBSlayer from the "trunk":
svn co http://www.dbslayer.org/svn/dbslayer/trunk/ ./dbslayer
Download and install some libs to install DBSlayer:
apt-get install libapr1-dev libaprutil1-dev libmysqlclient15-dev
Go to the dbslayer dir SVN created:
cd dbslayer
And install DBSlayer:
./configure
make
sudo make install
Now we'll install a mysql server. Skip this if you already have a server somewhere...
sudo apt-get install mysql-server
The installation will ask you for a password. I've given it "toor", but you should pick a safe password (this one is common!). For this example I'll continue with "toor", so replace that with whatever password you picked.
Now we'll create a database. This is an optional step really, just to get started. I (clearly...) named it "moo".
mysqladmin create "moo"
Now we'll start DBSlayer:
dbslayer -s localhost -u root -x toor -c void
Note that the -c option is required, but the file ("void" above) does not need to exist. Refer to
DBSlayer documentation for more information about other options. The localhost should be replaced with whatever host your MySQL server can be found, if not localhost. The "root" should be the user that has access to that server and "toor" should be replaced by its password.
Starting DBSlayer will not show a sign of life (only if you did something wrong...), so don't be alarmed.
Now let's find our proxy! Open up Firefox (top center) and go to
http://localhost:9090 from there. By default, DBSlayer will listen on port 9090. This can be changed. Going to the URL will end up in an error "Not found". To "find" it, you need to navigate to
http://localhost:9090/db?{"SQL":"use moo"} and then go to
http://localhost:9090/db?{"SQL":"show databases"} (if you created that database). From there, the next steps should be obvious :D There are also
some special commands.
Now you can access this URL from within Node.js easily.
@rauchg created
an example script for that on github. It might also be interesting to read
an article from
@hbstone for running Node and Apache at the same time on the same website. Just getting you one step closer to infinite bliss :D
Hope it helped you!