Sag Rising

Notes to Myself

How to Use Lighty in a Development Environment

Posted by Richard Cockrum on February 4, 2009

It is a given that one needs to have a local server set up in order to develop and test PHP applications. Most people use Apache, either by installing Apache, PHP, and MySQL individually or by installing one of the LAMP, WAMP, or MAMP packages. Until recently, that was the route I took, using XAMPP Lite from Apache Friends.

Unfortunately, the latest release of XAMPP Lite, version 1.7.0, forced me to begin looking for an alternative. Until this version things worked relatively well. I was able to create, run, and test dynamic web applications, notably Habari, using both MySQL and SQLite for the database backend, and debug them using XDebug, first using Notepad++ with its DBGP plugin as a makeshift IDE, then using NetBeans (which I've come to like a lot) as its PHP support improved.

When I upgraded to XAMPP Lite 1.7.0 my development productivity died. First, connecting to MySQL was an impossibility. Researching the issue, I found that other people were having the same problem. The fix was to download PHP from and install the standard distributions libraries in place of the ones that came with XAMPP Lite. Second, I was unable to use XDebug. XDebug has always been problematic for me with XAMPP Lite. I was able to get it to work, but would still have frequent instances in which the loading of the XDebug extension killed Apache. With the latest version of XAMPP Lite, every load of XDebug killed Apache, causing me to have to give up any attempt to actually trace running code and use only var_dump() or Habari's Utils::debug() function to check variables at times I'd decide using my best guess as to where problems might lie. Needless to say, this quickly became intolerable.

I could have looked for another WAMP replacement for XAMPP Lite, but decided that since a lot of my issues revolved around the interaction of XDebug and Apache, it would be a good idea to look into other server software. I remembered talk that Habari could be installed on Lighty, the lighttpd server which is used by the likes of YouTube and Wikipedia, so I decided to give it a try.

Just as there are various WAMP packages, there are LIMP (horrible acronym by the way) packages combining lighttpd, MySQL, and PHP in a single installable package. The most notable of these for Windows is the WLMP Project, but one further requirement I have is that, if at all possible, I'd like to have software that can be run from a flash drive as well as my computer's hard drive. That was the reason I was using XAMPP Lite instead of the full XAMPP package to begin with. I found such a package for lighttpd in Lighty2Go.

Installing Lighty2Go is easy. All you have to do is download the package and unpack it in the location of your choice using an archiver that is able to deal with the 7 Zip archiving format. Starting the lightppd and MySQL servers is accomplished by running the Start-Lighty2Go.exe executable that is located in the root of the package. This activates the servers and installs a menu in Windows' tray, which is identified by Lighty's paper airplane logo. You can verify that Lighty is up and running by navigating to http://localhost in your browser, where you'll see the Lighty2Go test page if all is well, which for me, it immediately was.

There are a couple of changes you have to make to get Lighty2Go to work with Habari and XDebug. The first of these requires editing Lighty2Go's configuration file, which is located at Lighty2Go/LighTPD/conf/lighttpd-l2g.conf. Lighty's configuration is somewhat different than Apache's. Most notably, from what I've been able to find out. all configuration has to performed in this one file or files which it includes. Overriding it's settings from the equivalent of individual .htaccess files in ad hoc directories isn't possible. Within this main configuration file similar functions to those used in Apache's configuration are possible, though.

The first change you'll have to make is to ensure that url rewriting is enabled by uncommenting the line that says "mod_rewrite" in the server.modules section. Like Apache, Lighty uses the # symbol for comments, so just delete that symbol from the appropriate line.

The next thing you'll want to do is enable virtual hosting for Lighty. Lighty has several ways to do this, but the following has been the simplest for me.

  1. Decide where you want to keep your web documents. I just added a /www subdirectory to Lighty2Go's HTDOCS directory in which to keep my personal web documents and scripts. You could also put your web documents somewhere completely different since you can set the document root in your vhost configuration. This way was simplest for me though, because I can just transfer the entire directory structure between my hard drive and flash drive.
  2. Create a file in the same directory as Lighty2Go's configuration file. I just named it lighttpd-vhost.conf.
  3. Add this line somewhere in lighttpd-l2g.conf
    include var.l2gDir + "/LightTPD/conf/lighttpd-vhost.conf"
    I added it right after the section labelled virtual hosts
  4. Open up lighttpd-vhost.conf. Add a section similar to this for each vhost you want to have:
    $HTTP["host"] == "www.sagrising.loc" {
        server.document-root = var.l2gDir + "/HTDOCS/www"
        dir-listing.activate = "disable"
    	url.rewrite = (
    		"^/(.*)\.(.+)$" => "$0",
    		"^/(.+)/?$" => "/index.php/$1"
    This code is doing four things. First, it tells you the name of the site. Second, it sets the document root for the site. Note the use of the variable var.l2gDir. This is set up by Lighty2Go's scripts and always points to Lighty2Go's root directory. It also illustrates that variables and simple scripting can be done in Lighty's configuration files. Lua has been often used for this. Third, it turns directory listing off. This isn't really an issue with a local install, but is a security measure for sites open to the web. Fourth is the rewrite rule. Note the difference from the rewrite rule given on Habari's wiki on the Habari installation page. The rewrite rule listed there works, but if the directory structure of Habari ever changes, I believe there's a chance it could break. The rewrite rule listed above I found at Guy Rutenberg's Clean URLs (Permalinks) for Wordpress on Lighttpd. I know little about regex expressions, but my understanding of this is that the first line allows static files to be found and loaded properly, while the second line allows posts to be found and loaded properly. All I really know is that to date, it has worked for me and doesn't depend on Habari having a certain directory structure.

The las thing you need to do is configure PHP.

  1. Open Lighty2Go's php.ini file. It is located at Lighty2Go/PHP/php.ini.
  2. Enable PDO by uncommenting the lines loading php_pdo.dll, php_pdo_mysql.dll, and php_pdo_sqlite.dll. While you're there, make sure php_curl.dll and php_mbstring.dll are also being loaded.
  3. Scroll down to the bottom of the file and add these lines to load XDebug
    ; Only Zend OR (!) XDebug
    xdebug.profiler_output_name = cachegrind.out.%t.%p
    Save the fle and close it.
  4. If you haven't already done so, get XDebug and unpack it. Rename the dll to php_xdebug.dll and place it in Lighty2Go/PHP/ext.

That's it. Restart Lighty2Go and navigate to the website you just enabled. It should pop right up for you.

I've had no issues using this setup since I installed it. Debugging in NetBeans worked out of the box for me, allowing me to step through code and check the values of variables without problem. As an added bonus, most WAMP packages take upward of 200MB of space. Lighty2Go uses under 100MB. Functionality without issues in half the space. I can live with that.

2 Pingbacks to How to Use Lighty in a Development Environment

5 Responses to How to Use Lighty in a Development Environment

This post peaked my interest. I did not want to take advantage of Lighty2Go since I only wanted to put lighttpd and PHP (with SQLite) on a Flash drive and use it that way. I got lighttpd to work on my own by downloading the windows binaries without the installer, copying them to the flash drive, updating the config file and running it. Worked great. I cannot, however, get PHP to work as a CGI without adding the registry key that it wants and possibly updating the path statement. Since I will be using this on my primary development computer some times, I don't want to affect my current PHP, MySQL, Apache environment running there. Is there anyway that you know to run PHP as a CGI with Lighty and not have to create entries in the path or registry of the machine in question? Any help or suggestions would be greatly appreciated!

From what I can see, Lighty2Go doesn't make any entries in your registry or change your path permanently.

If you don't want to use MySQL, it looks like all you have to do is just unzip the Lighty2Go archive where ever you want it, then delete the MySQL directory and the phpMyAdmin directory.

Next, find set-path.bat in Lighty2Go's base-files directory. REM out the line SET startservers=true.

After that, use Start-Lighty2Go.exe in Lighty2Go's base directory to start the tray menu. Right click in the tray menu and select Start LightTPD to start the lighty server. To shut it down, right click in the tray menu and select Shutdown. You should be good.

I'd take nginx anyday, not to start a flame, but just because nginx config files makes more sense to me. :)


Understood. I've never looked at nginx myself, but I know a lot of people like it. The simplicity of lighttpd's config file compared to Apache is one of the things I've liked about it.

What do you think?
Comments for this post are disabled.