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
:
1# 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:
1# apt-get update
2# apt-get install monkey{,-auth,-dirlisting,-fastcgi,-liana,-logger,-mandril,-polarssl}
Afterwards PHP5 including FastCGI Process Manager and SQLite3 support is installed:
1# 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
:
1# vi /etc/monkey/plugins.load
2...
3 # FASTCGI
4 # =======
5 # Adds FastCGI proxy support.
6 #
7 Load /usr/lib/monkey/monkey-fastcgi.so
8...
9
10ESC 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.
1# vi /etc/monkey/plugins/fastcgi/fastcgi.conf
2...
3[FASTCGI_SERVER]
4 ServerName php5-fpm1
5 ServerPath /var/run/php5-fpm.sock
6 MaxConnections 5
7
8[FASTCGI_LOCATION]
9 LocationName php5_location
10 ServerNames php5-fpm1
11 KeepAlive On
12 Match /*.php
13
14ESC ZZ
After restarting the Monkey service PHP is availble:
1# service monkey restart
If you are planning to use this system as public web server you really should secure the system:
1# apt-get install fail2ban iptables-persistent aide
Of course firewall rules, Fail2Ban and AIDE configurations needs to be customized. 🙂