Skip to content

Getting Started With ULib

stefano casazza edited this page Mar 12, 2019 · 18 revisions

Firstly a huge thankyou to Stefano Casazza not only for making ULib but for his patience in answering all my questions.

What is UServer

UServer is a extensible plugin based web server that is build on top of ULib.

ULib is installed as a set of shared object libraries and header files (like Boost).

Get a copy of the ULib source code

git clone https://github.com/stefanocasazza/ULib.git

configure your build

If you haven't had much experience playing with make read the config help or:

./configure -h

Having now decided on what features you need let ./configure do its magic.

For example:

./configure --enable-debug --with-sqlite3 
make 
sudo make install 

configure userver

Assuming you haven't changed the PREFIX make will install userver to /usr/local

At this point we need to configure /usr/local/etc/userver.cfg The file is well annotated at a bare minimum setup the following values:

userver {
DOCUMENT_ROOT /srv/http
LOG_FILE userver.log
#PLUGIN "http"
#PLUGIN_DIR /usr/local/libexec

# Database (ORM) settings
ORM_DRIVER "sqlite"
#ORM_DRIVER_DIR /usr/local/libexec
}

Environment Variables

userver_tcp expects some environment variables for debugging and database (ORM) functions to save typing it is easiest to put these into a bash script like this:

#!/bin/sh

# Database 
export ORM_DRIVER="sqlite"
export ORM_OPTION="host=localhost user=benchmarkdbuser password=benchmarkdbpass character-set=utf8 dbname=../db/fortune"

# Debug 
export UTRACE="0 20M 0"
export UTRACE_SIGNAL="0 20M 0"
export UOBJDUMP="0 10M 100"
export USIMERR="error.sim"

userver_tcp #-c /usr/local/etc/userver.cfg

Running your server (static pages)

Once you have configured your userver.cfg and placed the relevant html documents in your docroot just execute the bash script above.

Point your browser to localhost/filename you should now have a working server.

Dynamic Pages

userver offers a wide variety of ways to generate dynamic content depending on your needs:

SECURITY

As with all web servers do not run them as the root user. This introduction has been written to give you an idea of the ULib/UServer workflow. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is your responsibility to secure your web server and follow sound security conscious programming practices.