| lighttpd with PHP5 Tutorial |
|
|
|
| Written by macsat | |
| Thursday, 24 November 2005 | |
|
The Tutorial is made using a ASUS WL-500G Deluxe (or WL-500GX and WL-500GD as it is sometimes called). It should however apply to all "OpenWRT Compatible" devices, even though some details like hardware addresses, storage locations and so on could differ if you use other hardware. Check out the General OpenWRT Tutorial Information page for more information. After following this tutorial you will have a complete running installation of lighttpd with php5 support. In lighttpd you will have the modules mod-simple-vhost, mod-cgi and mod-status running In PHP the GD graphics / image module will be installed and configured for use Tutorial Index1. Prerequisites - What is needed to get started.2. Installing lighttpd. 3. Installing PHP5 4. Problem: Fatal error: Call to undefined function: preg_match() PrerequisitesAll you need is :Installing lighttpdThe version of lighttpd I have chosen to use here, is version 1.4.4 from nicos testing repository.Installing can be done as:
ipkg install http://downloads.openwrt.org/backports/rc6/lighttpd_1.4.11-1_mipsel.ipk
ipkg install http://downloads.openwrt.org/backports/rc6/lighttpd-mod-simple-vhost_1.4.11-1_mipsel.ipk ipkg install http://downloads.openwrt.org/backports/rc6/lighttpd-mod-status_1.4.11-1_mipsel.ipk ipkg install http://downloads.openwrt.org/backports/rc6/lighttpd-mod-cgi_1.4.11-1_mipsel.ipk Now some configuration needs to be done. First of all, the file /etc/default/lighttpd should look like :
OPTIONS="-f /etc/lighttpd.conf"
For making the web server startup at boottime, you should start by disabling the build-in httpd server:
mv /etc/init.d/S50httpd /etc/init.d/K50httpd
Now create the file /etc/S80lighttpd containing something like:
#!/bin/sh
BINDIR=/usr/sbin/ BIN=lighttpd DEFAULT=/etc/default/$BIN LOG_D=/var/log/$BIN RUN_D=/var/run PID_F=$RUN_D/$BIN.pid [ -f $DEFAULT ] && . $DEFAULT case $1 in start) mkdir -p $LOG_D mkdir -p $RUN_D ${BINDIR}${BIN} $OPTIONS ;; stop) [ -f $PID_F ] && kill $(cat $PID_F) ;; *) echo "usage: $0 (start|stop)" exit 1 esac exit $? Dont forget to make the file executable
chmod +x /etc/inid.t/S80lighttpd
All that is needed now is to make a few changes to the main thttpd configurationfile. This file is found in /etc and is called lighttpd.conf The file is too large to post here with any level of meaningfulness, but I will try to explain what to change to make it run with the modules we installed above. On the top of the file, the server-modules are defined. Remove wht "#" mark in front of the following three modules:
"mod_status",
"mod_simple_vhost", "mod_cgi", The next thing you might wanna change is the server-document root. This is /www as default. Personally I use my USB disk on /opt, so I have changed this to /opt/www and keep my httpd files on the USB drive. Now move a little further down, until you reach the virtual hosts area. This is most relevant if you own several domains, or have several free domains fro places like www.dyndns.org pointing at your IP. Virtual hosts are handled a bit different in lighttpd than in apache. But I do belive that the handling is very cool :-) Consider your webpages to be stored in /www and you having to different domains, www.domain1.com and www.domain2.com Then you should create the two folders and maybe even symlinks for the domains without the "www" prefix:
mkdir -p /www/www.domain1.com
mkdir -p /www.www.domain2.com ln -s /www/www.domain1.com /www/domain1.com ln -s /www.www.domain1.com /www/dommain2.com Now back in the lighttpd.conf file, change the simple-vhost settings to something like:
simple-vhost.server-root = "/www/"
simple-vhost.default-host = "www.domain1.com" simple-vhost.document-root = "/" Now - whenever you use www.domain1.com to access your web server, you get the contents of /www/www.domain1.com and when you use www.domain2.com you get contents of /www/www.domain2.com. Also - when you use some other domain name that is pointing to your IP, you get the www.domain1.com contents. In this way, creating more domains, or subdomains (like http://sub1.domain1.com) all that is needed is to make the appropiate folder in /www Isnt this cool? ;-) Next thing in the configfile is the cgi module, allowing you to use php If you use the cgi version of PHP, this section should look like:
cgi.assign = ( ".php" => "/bin/php" )
Now that PHP is enabled, you might want to make the server use index.php as the default page when you point your browser to http://www.yourdomain.com/someurl/ that contains an index.php file. To do this, find the server.indexfiles = part of lighttpd.conf and change to something like:
server.indexfiles = ( "index.html", "index.htm", "index.php")
#### status module
status.status-url = "/status" status.config-url = "/config" This gives you the pages you can see in http://your_router_ip/status and http://your_router_ip/config once we get as far as to get the server stated. That should be it, lighttpd is ready to run, as soon as we get php installed and configured. Installing PHPAs mentioned above, PHP is installed as a CGI module to the lighttpd server. There is also a fastcgi version available, I dont know if this gives better performance or not.Installing the CGI version of PHP is done simply by:
ipkg install http://downloads.openwrt.org/backports/rc6/php5-cgi_5.0.5-1_mipsel.ipkg
ipkg install http://downloads.openwrt.org/backports/rc6/php5-mod-gd_5.0.5-1_mipsel.ipk As you can see above, I have installed both PHP and the GD module for PHP. This is mostly to show how to install and enable modules. You can check http://downloads.openwrt.org/people/nico/testing/mipsel/packages/ for an overview of modules you can install to your PHP. The configuration file for PHP is /etc/php.ini In this file you can make a lot of settings. Setting max memory usage pretty low might be a good idea in OpenWRT due to the low amount of RAM typically in an OpenWRT compatible device. To enable the gd extention, you should find the place in the file that has this entry:
;extension=gd.so
Remove the ";" so that the line becomes:
extension=gd.so
Now the gd extention will be available to php :-) To test your new webserver and its PHP capabilities, you need to create a php file and start the server :
echo "<?php phpinfo(); ?>" > /www/phpinfo.php
/etc/init.d/S80lighttpd Now you should be able to point your browser to: http://your_router_ip/phpinfo.php and see the phpinfo page. If you for some reason get :
No input file specified.
You could try to change :
doc_root = /www
to:
doc_root =
For some reason that helped me here :-) Problem: Fatal error: Call to undefined function: preg_match()
|
|
| Last Updated ( Wednesday, 31 January 2007 ) |
| < Prev | Next > |
|---|







