Monkey web server + PHP5 + SQLite on Raspbian

Using Raspbian it is possible to convert a Raspberry Pi into a full-featured Webserver with PHP support. Using SQLite the embedded web server is also capable of serving database-driven web applications.

First of all the official Monkey APT repository needs to be included – this can done very easily by addind a line into the configuration file /etc/apt/sources.list:

# echo "deb primates_pi main" >> /etc/apt/sources.list

The following commands are updating the APT cache and installing Monkey including SSL– and FastCGI support (needed for PHP) and some other plugins:

# apt-get update
# apt-get install monkey{,-auth,-dirlisting,-fastcgi,-liana,-logger,-mandril,-polarssl}

Afterwards PHP5 including FastCGI Process Manager and SQLite3 support is installed:

# apt-get install php5{,-fpm,-cgi,-sqlite} sqlite3

After that it is necessary to enable and configure the Monkey FastCGI module. Because Monkey offers no native PHP support FastCGI establishes a connection to PHP FastCGI Process Manager. This software communicates with the PHP interpreter and returns the generated content to the web server. The module is activated by adding a line in the configuration file /etc/monkey/plugins.load:

# vi /etc/monkey/plugins.load
    # =======
    # Adds FastCGI proxy support.
    Load /usr/lib/monkey/


The module is configurated afterwards in a dedicated configuration file in /etc/monkey/plugins/fastcgi.

The first category (FASTCGI_SERVER) contains information about the PHP FastCGI Process Manage. In my setup the default values were already correct. If you are having issues you should have a look whether the socket (/var/run/php5-fpm.sock in this case) exists.

Access limitations can be defined in the second category (FASTCGI_LOCATION). Basically it is a good idea to enable executing PHP files only for particular subdirectories. Rules are defined in regular expressions – in this case executing all PHP files is allowed for testing purposes. To make debugging easier unique names are definied in the particular categories (ServerName, LocationName).

In my setup I had the issue that PHP applications were not executed after some time. To fix this I altered the MaxConnections  and KeepAlive settings.

# vi /etc/monkey/plugins/fastcgi/fastcgi.conf
        ServerName php5-fpm1
        ServerPath /var/run/php5-fpm.sock
        MaxConnections 5

        LocationName php5_location
        ServerNames php5-fpm1
        KeepAlive On
        Match /*.php


After restarting the Monkey service PHP is availble:

# service monkey restart

If you are planning to use this system as public web server you really should secure the system:

# apt-get install fail2ban iptables-persistent aide

Of course firewall rules, Fail2Ban and AIDE configurations needs to be customized. 🙂

Sharing is caring

Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedInShare on XingShare on RedditPrint this pageEmail this to someone

2 comments Write a comment

  1. nice article, very helpful for getting php working with monkey. Do you know how to get sqlie3 working with it though? It doesn’t seem to work for me. I’ve got sqlite3 working on the command line but not via php scripts.

    • Hey john!
      Not really to be quite honest – haven’t used Monkey for a couple of years though. Maybe you want to ask on the official Monkey chat on -> #monkey – those guys have saved a couple of times. 🙂

      Best regards,

Leave a Reply