Skip to content
Example FastCGI web application with Fano Framework which listening on Unix Domain Socket
Pascal HTML Shell Batchfile PHP C++ Other
Branch: master
Clone or download
Latest commit e6d984e Aug 14, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin "Initial commit" Jun 28, 2019
config "Initial commit" Jun 28, 2019
public add missing asset files Jul 20, 2019
resources/Templates/Home update fano repo Jul 29, 2019
src update fano Aug 14, 2019
tools "Initial commit" Jun 28, 2019
vendor update fano Aug 14, 2019
.gitignore "Initial commit" Jun 28, 2019
.gitmodules "Initial commit" Jun 28, 2019
LICENSE Initial commit Jun 28, 2019 implement basic controller Jun 28, 2019
build.cfg.sample implement basic controller Jun 28, 2019
build.cmd "Initial commit" Jun 28, 2019 "Initial commit" Jun 28, 2019 "Initial commit" Jun 28, 2019 "Initial commit" Jun 28, 2019

Example FastCGI Web Application with Fano Web Framework

FastCGI Web application skeleton using Fano Framework, Pascal web application framework. This application is listen to Unix Domain Socket.

This project is generated using Fano CLI command line tools to help scaffolding web application using Fano Framework.




libcurl development package installation

Check if libcurl package for development is installed by running curl-config.

$ curl-config --version

If libcurl installed you will get something like libcurl x.xx.x where x.xx.x is version. For example libcurl 7.47.0 otherwise you get

The program 'curl-config' can be found in the following packages:
 * libcurl4-gnutls-dev
 * libcurl4-nss-dev
 * libcurl4-openssl-dev
Try: sudo apt install <selected package>

In case libcurl not installed, run

$ sudo apt install libcurl4-gnutls-dev

Free Pascal installation

Make sure Free Pascal is installed. Run

$ fpc -i

If you see something like Free Pascal Compiler version 3.0.4, you are good to go.

Clone this repository

$ git clone --recursive

--recursive is needed so git also pull Fano repository.

If you are missing --recursive when you clone, you may find that vendor/fano directory is empty. In this case run

$ git submodule update --init

To update Fano to its latest commit, run

$ git checkout master && git submodule foreach --recursive git pull origin master

Above command will checkout to master branch of this repository and pull latest update from master branch of Fano repository.

Copy *.cfg.sample to *.cfg. Make adjustment as you need in build.cfg,, and run shell script (if you are on Windows, then build.cmd).

These *.cfg files contain some Free Pascal compiler switches that you can turn on/off to change how executable is compiled and generated. For complete explanation on available compiler switches, consult Free Pascal documentation.

Also copy src/config/config.json.sample to src/config/config.json and edit configuration as needed. For example, you may need to change baseUrl to match your own base url so JavaScript or CSS stylesheets point to correct URL.

$ cp config/config.json.sample config/config.json
$ cp
$ cp
$ cp build.cfg.sample build.cfg
$ ./

tools/ shell script is provided to simplify copying those configuration files. Following shell command is similar to command above.

$ ./tools/
$ ./

By default, it will output binary executable in public directory.

Build for different environment

To build for different environment, set BUILD_TYPE environment variable.

Build for production environment

$ BUILD_TYPE=prod ./

Build process will use compiler configuration defined in vendor/fano/fano.cfg, build.cfg and By default, contains some compiler switches that will aggressively optimize executable both in speed and size.

Build for development environment

$ BUILD_TYPE=dev ./

Build process will use compiler configuration defined in vendor/fano/fano.cfg, build.cfg and

If BUILD_TYPE environment variable is not set, production environment will be assumed.

Change executable output directory

Compilation will output executable to directory defined in EXEC_OUTPUT_DIR environment variable. By default is public directory.

$ EXEC_OUTPUT_DIR=/path/to/public/dir ./

Change executable name

Compilation will use executable filename as defined in EXEC_OUTPUT_NAME environment variable. By default is app.cgi filename.

$ EXEC_OUTPUT_NAME=index.cgi ./


Run example Fano FastCGI application

$ ./public/app.cgi

By default it will listen on Unix domain socket /tmp/fano-fcgi-unix.sock file. You need to make sure /tmp/fano-fcgi-unix.sock permission is writeable by web server.

Run with a webserver

Setup a virtual host. Please consult documentation of web server you use.


You need to use Apache 2.4 and to have mod_proxy_fcgi installed and loaded. This module is Apache's built-in module, so it is very likely that you will have it with your Apache installation. You just need to make sure it is loaded. For example, on Debian,

$ sudo a2enmod proxy_fcgi
$ sudo systemctl restart apache2

Create virtual host config and add ProxyPassMatch, for example

<VirtualHost *:80>
     DocumentRoot /home/example/public

     <Directory "/home/example/public">
         Options +ExecCGI
         AllowOverride FileInfo
         Require all granted

    ProxyRequests Off
    ProxyPass /css !
    ProxyPass /images !
    ProxyPass /js !
    ProxyPassMatch ^/(.*)$ "unix:/tmp/fano-fcgi-unix.sock|fcgi://"

Last four line of virtual host configurations basically tell Apache to serve any files inside css, images, js directly otherwise pass it to our application.

Hostname after fcgi:// are ignored by mod_proxy_fcgi.

On Debian, save it to /etc/apache2/sites-available for example as fano-fcgi-unix.conf Enable this site and restart Apache

$ sudo a2ensite fano-fcgi-unix.conf
$ sudo systemctl restart apache2

If Apache returns HTTP 503 Service Unavailable and you get following similar messages in error log

[Fri Jun 28 15:46:52.111034 2019] [proxy:error] [pid 18974] (13)Permission denied: AH02454: FCGI: attempt to connect to Unix domain socket /tmp/fano-fcgi-unix.sock ( failed

then make sure that socket file is writeable by user where Apache runs.

If you get following message when running application,

ESocketError: Binding of socket failed: /tmp/fano-fcgi/fano-fcgi-unix.sock

Delete /tmp/fano-fcgi/fano-fcgi-unix.sock first then re-run application.


You need to deploy only executable binary and any supporting files such as HTML templates, images, css stylesheets, application config. Any pas or inc files or shell scripts is not needed in deployment machine in order application to run.

So for this repository, you will need to copy public, Templates, config and storages directories to your deployment machine. make sure that storages directory is writable by web server.

Known Issues

Issue with GNU Linker

When running script, you may encounter following warning:

/usr/bin/ld: warning: public/link.res contains output sections; did you forget -T?

This is known issue between FreePascal and GNU Linker. See FAQ: link.res syntax error, or "did you forget -T?"

However, this warning is minor and can be ignored. It does not affect output executable.

Issue with unsynchronized compiled unit with unit source

Sometime FreePascal can not compile your code because, for example, you deleted a unit source code (.pas) but old generated unit (.ppu, .o, .a files) still there or when you switch between git branches. Solution is to remove those files.

By default, generated compiled units are in bin/unit directory. But do not delete file inside this directory, as it is not being ignored by git.

$ rm bin/unit/*.ppu
$ rm bin/unit/*.o
$ rm bin/unit/*.rsj
$ rm bin/unit/*.a

Following shell command will remove all files inside bin/unit directory except file.

$ find bin/unit ! -name '' -type f -exec rm -f {} +

tools/ script is provided to simplify this task.

Windows user

Free Pascal supports Windows as target operating system, however, this repository is not yet tested on Windows. To target Windows, in build.cfg replace compiler switch -Tlinux with -Twin64 and uncomment line #-WC to become -WC.

Lazarus user

While you can use Lazarus IDE, it is not mandatory tool. Any text editor for code editing (Atom, Visual Studio Code, Sublime, Vim etc) should suffice.

You can’t perform that action at this time.