Buildroot SDK/Lighttpd and PHP

From Chiliboard Wiki
Jump to: navigation, search

Lighttpd and PHP

In BR directory

$ make menuconfig

Find and enable following packages:

Target packages --->
 Interpreter languages and scripting  --->
     [*] php                       
         Extensions  --->            
         Interface (CGI)  --->      
         External php extensions  --->               
Target packages --->
 Networking applications  --->
     [*] lighttpd                           
         [ ]   openssl support (NEW)   
         [ ]   zlib support (NEW)                 
         [ ]   bzip2 support (NEW)                
         [*]   pcre support (NEW)                 
         [ ]   webdav support (NEW)               
         [ ]   lua support (NEW)

Exit and save BR configuration. To build newly selected packages and generate new root filesystem:

$ make

Default configuration files provided with PHP and lighttpd packages will be installed on target filesystem:

output/target/etc
├── lighttpd
│   ├── conf.d
│   │   ├── access_log.conf
│   │   ├── debug.conf
│   │   ├── dirlisting.conf
│   │   ├── fastcgi.conf
│   │   └── mime.conf
│   ├── lighttpd.conf
│   └── modules.conf
└── php.ini

To modify default configuration files, we will use overlay directory to overwrite existing configuration files with our versions. Please configure your BR according to instructions in section Modyfing filesystem content.

Copy all /etc/lighttpd files into root filesystem overlay directory:

$ cp -a output/target/etc/lighttpd board/grinn/chiliboard/rootfs_overlay/etc
$ cp -a output/target/etc/php.ini board/grinn/chiliboard/rootfs_overlay/etc


Recent version of PHP comes with short_open_tag option disabled [1]. If you want to run some legacy php code, please enable it in file board/grinn/chiliboard/rootfs_overlay/etc/php.ini

short_open_tag = On

Go to directory

$ cd board/grinn/chiliboard/rootfs_overlay/etc/lighttpd

Edit modules.conf and add new fastcgi module:

server.modules = (
  "mod_access",
#  "mod_alias",
#  "mod_auth",
#  "mod_evasive",
#  "mod_redirect",
#  "mod_rewrite",
#  "mod_setenv",
#  "mod_usertrack",
  "mod_fastcgi"
)

Uncomment include for fastcgi.conf

##
## FastCGI (mod_fastcgi)
##
include "conf.d/fastcgi.conf"

Creaate conf.d/fastcgi.conf

$ touch conf.d/fastcgi.conf

With following content

fastcgi.server = ( ".php" => ((
                     "bin-path" => "/bin/php-cgi",
                     "socket" => "/tmp/php.socket"
                 )))

Create php test page (and remove default one):

$ rm -f board/grinn/chiliboard/rootfs_overlay/var/www/index.html
$ mkdir -p board/grinn/chiliboard/rootfs_overlay/var/www 
$ echo '<?php phpinfo(); ?>' > board/grinn/chiliboard/rootfs_overlay/var/www/index.php

Rebuild filesystem image

$ make

To debug problems running lighttpd please check lighttpd log files:

# cat /tmp/lighttpd-error.log
# cat /tmp/lighttpd-access.log