User Tools

Site Tools


Build a WEB server with Lighttpd and PHP-fpm on Cubieboard

About this Article


In this article, we focus on building a WEB server with Lighttpd and PHP support which is suitable for most of middle-scale or small-scale applications. We mainly talk about Lighttpd + PHP-fastcgi and Lighttpd + PHP-fpm here, which are two different schemes, and you may choose one of them.

This tutorial requires Lubuntu running on a Cubieboard/Cubietruck. Use the terminal on an desktop Lubuntu to execute the following command lines.

Lighttpd + PHP-fastcgi

It's quite easy and will be descriped briefly. Install the Lighttpd first.

$ sudo apt-get install lighttpd

Then enable fastcgi and fastcgi-php support

$ sudo lighttpd-enable-mod fastcgi fastcgi-php 

:!: fastcgi & fastcgi-php should be enabled together, otherwise you will get 403 Forbidden sort of error

Now, you can restart Lighttpd and see what happens.

$ sudo /etc/init.d/lighttpd force-reload

You may test your web site with your browser now.

Lighttpd + PHP-fpm

PHP-fpm is well known as an efficient backend for handling php requests, more efficient than fastcgi-php, people say. The installing and configuring procedure is a bit more tricky, but far from complicated, you can follow these steps.


The key problem is how Lighttpd and PHP-fpm communicating with each other. If they work in the exact same system and the exact same machine, commucating through native Unix domain sockets is apparently efficient than TCP sockets, while communicating through TCP sockets could physically seperate Lighttpd and PHP-fpm processes, which is good for distributed systems. We discuss these two kinds of configurations below.

First, we create a script to support fastcgi and PHP-fpm.

$ sudo touch /etc/lighttpd/conf-available/10-php-fpm.conf

Then, we talk about details of different configurations.

Native Unix domain socket commucating configuration

Edit /etc/lighttpd/conf-available/10-php-fpm.conf as follows

fastcgi.server = ( ".php" =>
    ( "localhost" =>
         "socket" => "/var/run/php5-fpm.sock"

TCP socket communicating configuration

Edit /etc/lighttpd/conf-available/10-php-fpm.conf as follows

fastcgi.server = ( ".php" =>
         "host" => "",
         "port" => "9000"

Meanwhile, we need modify /etc/php5/fpm/pool.d/www.conf , locate this line

listen = /var/run/php5-fpm.sock

change it to


Restart the service

If we tend to use PHP-fpm, we must disable fastcgi-php (but remain the fastcgi), and enable our script for PHP-fpm.

$ sudo lighttpd-disable-mod fastcgi-php
$ sudo lighttpd-enable-mod php-fpm

Restart PHP-fpm and Lighttpd now

$ sudo /etc/init.d/php5-fpm restart
$ sudo /etc/init.d/lighttpd restart


Lighttpd's default www folder is in /var/www/, we create a new test file /var/www/index.php, modify it as follows


Test this web site with your browser now. If the following message is displayed, you make it.

Other PHP modules

We can install more modules to make our server a more powerful one.

$ sudo apt-get install  php5-memcache php5-curl php5-gd php5-mysql php5-mcrypt php5-sqlite

Network tuning

tutorials/common/applications/lighttpd_and_php-fpm.txt · Last modified: 2013/12/23 14:50 (external edit)