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 http://packages.monkey-project.com/primates_pi 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
...
    # FASTCGI
    # =======
    # Adds FastCGI proxy support.
    #
    Load /usr/lib/monkey/monkey-fastcgi.so
...

ESC ZZ

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
...
[FASTCGI_SERVER]
        ServerName php5-fpm1
        ServerPath /var/run/php5-fpm.sock
        MaxConnections 5

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

ESC ZZ

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

Leave a Reply