Using (Fast)CGI for non-PHP websites

Documentation

Using (Fast)CGI for non-PHP websites

You're not stuck with PHP if you want to make a dynamic website. You can use all sorts of frameworks and programming languages with ULYSSIS, as long as it has CGI or FastCGI support.

If you want to use a certain programming language or framework, and you can't get it to work, don't hesitate to contact us at ulyssis@ulyssis.org. We will of course not write any code for you, but we can give you some pointers or directions.

Contents

CGI

CGI is a simple way to create a dynamic website. We use Apache's mod_cgid to provide support for CGI. Note, however, that CGI is inefficient and
in general we recommend you to use a framework together with FastCGI. There are many frameworks, ranging from very simple and lightweight, to more complex and feature rich.

If, for example, you want Apache to interpret all files with the extension .cgi as CGI scripts, use the following .htaccess file (to be placed in your www folder):

Options +ExecCGI
AddHandler cgi-script .cgi

Here's an example of a very simple Python CGI script (called hello.cgi):

FastCGI

In order to use FastCGI, you will generally need a starter script specific to your framework and application. Just do a web search for "framework mod_fcgid", where you framework is the framework you're using, and you will find good instructions. There's a Django example below.

You'll want to treat this starter script as a mod_fcgid script, and usually, you'll want to redirect everything to this script, so you can use an .htaccess file that looks like this:

Replace starter.fcgi with the name of your starter script. Don't forget to make your starter script executable:

chmod +x starter.fcgi

The starter script must be located in the same folder as the .htaccess file.

Warning: Do not place sensitive files inside the web accessible folder.Make sure they are located in a folder outside the document root, or they will be downloadable through the webserver.

It is adviced to only place the fcgi starter script, .htaccess and static files (images, stylesheets) inside the document root.

Startup time and persistency

It is important to keep in mind that our Apache webworkers will only run your start script when a request is made. As soon as that first request has been received, it will try and keep a few instances of your application around for future use. This of course affects how you restart your application after changes (see below), but also means that applications with a longer start up time (for example a language such as Python combined with a larger framework) will experience an initial slow request. This slow startup is obviously not a factor for faster languages such as Haskell, C++ or Go.

Sadly, Apache is unable to have FastCGI processes persist beyond a reload or restart. This means in practice that every night around 6h25 when the logs are rotated, which requires Apache to be reloaded, all running fcgi processes will be gracefully terminated. The same thing happens when we make changes to the Apache configuration when a new website or user is added.

For those who have a very high startup time and don't generate enough traffic to not experience issues with this behaviour, it's possible to use a cronjob to visit the website every night at 6h30 or 7h, or even hourly.

Restarting your application

If you've changed your application, you will need to restart it for these changes to take effect. However, because you're editing the application on a different server than were it is running, you do not have access to the running process. You'll have to create some sort of mechanism to restart the process.

In the Django example below, the starter script has been written so that when it is changed, the application is automatically restarted within 1 second. The same mechanism can be applied to other Python sites. You can change the modification date without actually changing the contents of the starter script by using touch:

touch starter.fcgi

Replace starter.fcgi with the name of your starter script.

Example: Django

If you want to make a website using Django, we recommend that you use a virtualenv. This tool is already preinstalled on our shell servers.

You can use the following steps to get up and running with Django at ULYSSIS: