cygwin lighttpd php mysql, the perfect dev setup for windows

Since a few months, after more than 10 years on Linux, I switched my main OS to win7 (I’ll write something about this switch in a different post) and I’m quite happy with it, if there’s a thing I wasn’t happy about (’till today) was my development servers environment, I had Zend Server + MySQL, both as windows services, eating my pc’s resources also if I was not using it to work. Another thing was that I only work on Linux production servers and having those “c:\” paths just felt wrong.

I already used the great cygwin for a bunch of things, most of all rsync backups, so I decided to try removing Zend Server + MySQL for windows and move those services inside the cygwin environment, so I can start them with a bash script whenever I need them and I’m finally free from the “c:\” paths.

The problem was that there’s no documentation at all about this kind of installation, so:

  • no problems with MySQL, just install the packages, run “mysql_install_db” just the first time, and then call “mysqld_safe &” to start it when you need it
  • I couldn’t make apache2 work so I decided to use lighttpd
  • Configure and install all PHP packages you need using the cygwin ports project cause the main cygwin repository doesn’t have them

I ran into a few troubles configuring PHP for lighttpd, so here you have my /etc/lighttpd/lighttpd.conf:

# lighttpd configuration file
# use it as a base for lighttpd 1.0.0 and above
# $Id: lighttpd.conf,v 1.7 2004/11/03 22:26:05 weigon Exp $

############ Options you really have to take care of ####################

## modules to load
# at least mod_access and mod_accesslog should be loaded
# all other module should only be loaded if really neccesary
# - saves some time
# - saves memory
server.modules = (
# "mod_redirect",
# "mod_alias",
# "mod_cml",
# "mod_trigger_b4_dl",
# "mod_auth",
# "mod_status",
# "mod_setenv",
# "mod_fastcgi",
# "mod_proxy",
# "mod_simple_vhost",
# "mod_evhost",
# "mod_userdir",
# "mod_compress",
# "mod_ssi",
# "mod_usertrack",
# "mod_expire",
# "mod_secdownload",
# "mod_rrdtool",
 "mod_accesslog" )

## a static document-root, for virtual-hosting take look at the
## server.virtual-* options
server.document-root = "/srv/www/htdocs/"

## where to send error-messages to
server.errorlog = "/var/log/lighttpd/error.log"

# files to check for if .../ is requested
index-file.names = ( "index.php", "index.html",
 "index.htm", "default.htm" )

## set the event-handler (read the performance section in the manual)
# server.event-handler = "freebsd-kqueue" # needed on OS X

# mimetype mapping
mimetype.assign = (
 ".pdf" => "application/pdf",
 ".sig" => "application/pgp-signature",
 ".spl" => "application/futuresplash",
 ".class" => "application/octet-stream",
 ".ps" => "application/postscript",
 ".torrent" => "application/x-bittorrent",
 ".dvi" => "application/x-dvi",
 ".gz" => "application/x-gzip",
 ".pac" => "application/x-ns-proxy-autoconfig",
 ".swf" => "application/x-shockwave-flash",
 ".tar.gz" => "application/x-tgz",
 ".tgz" => "application/x-tgz",
 ".tar" => "application/x-tar",
 ".zip" => "application/zip",
 ".mp3" => "audio/mpeg",
 ".m3u" => "audio/x-mpegurl",
 ".wma" => "audio/x-ms-wma",
 ".wax" => "audio/x-ms-wax",
 ".ogg" => "application/ogg",
 ".wav" => "audio/x-wav",
 ".gif" => "image/gif",
 ".jar" => "application/x-java-archive",
 ".jpg" => "image/jpeg",
 ".jpeg" => "image/jpeg",
 ".png" => "image/png",
 ".xbm" => "image/x-xbitmap",
 ".xpm" => "image/x-xpixmap",
 ".xwd" => "image/x-xwindowdump",
 ".css" => "text/css",
 ".html" => "text/html",
 ".htm" => "text/html",
 ".js" => "text/javascript",
 ".asc" => "text/plain",
 ".c" => "text/plain",
 ".cpp" => "text/plain",
 ".log" => "text/plain",
 ".conf" => "text/plain",
 ".text" => "text/plain",
 ".txt" => "text/plain",
 ".dtd" => "text/xml",
 ".xml" => "text/xml",
 ".mpeg" => "video/mpeg",
 ".mpg" => "video/mpeg",
 ".mov" => "video/quicktime",
 ".qt" => "video/quicktime",
 ".avi" => "video/x-msvideo",
 ".asf" => "video/x-ms-asf",
 ".asx" => "video/x-ms-asf",
 ".wmv" => "video/x-ms-wmv",
 ".bz2" => "application/x-bzip",
 ".tbz" => "application/x-bzip-compressed-tar",
 ".tar.bz2" => "application/x-bzip-compressed-tar",
 # default mime type
 "" => "application/octet-stream",

# Use the "Content-Type" extended attribute to obtain mime type if possible
#mimetype.use-xattr = "enable"
## send a different Server: header
## be nice and keep it at lighttpd
# server.tag = "lighttpd"

#### accesslog module
accesslog.filename = "/var/log/lighttpd/access.log"

## deny access the file-extensions
# ~ is for backupfiles from vi, emacs, joe, ...
# .inc is often used for code includes which should in general not be part
# of the document-root
url.access-deny = ( "~", ".inc" )

$HTTP["url"] =~ "\.pdf$" {
 server.range-requests = "disable"

# which extensions should not be handle via static-file transfer
# .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

###### virtual hosts

## If you want name-based virtual hosting add the next three settings and load
## mod_simple_vhost
## document-root =
## virtual-server-root + virtual-server-default-host + virtual-server-docroot
## or
## virtual-server-root + http-host + virtual-server-docroot
#simple-vhost.server-root = "/srv/www/vhosts/"
#simple-vhost.default-host = ""
#simple-vhost.document-root = "/htdocs/"

## virtual directory listings

dir-listing.activate = "enable"
## select encoding for directory listings
dir-listing.encoding = "utf-8"


# chroot() to directory (default: no chroot() )
#server.chroot = "/"

## change uid to <uid> (default: don't care)
#server.username = "wwwrun"

## change uid to <uid> (default: don't care)
#server.groupname = "wwwrun"

cgi.assign = (".php"=>"/usr/bin/php-cgi")

Now that you’ve the right lighttpd config file, just start lighttpd with “/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf &” and you’re done, the perfect PHP dev environment on windows is yours.

7 thoughts on “cygwin lighttpd php mysql, the perfect dev setup for windows

  1. Mario Spada

    I am very surprised and I’m curious to know why you decided to switch from Linux to Windows…!
    Backslashed path, virus panic and other “pleasant” Windows things brought me, six years ago, to switch from Windows to Linux and now I’m an happy man (even with Unity…)

  2. Fabrizio Balliano Post author

    @Mario: no backslashed path in cygwin and no viruses till now, using some brain and a decent antivirus (microsoft security essential is enough for me). There are a lot of motivations why I chose windows after ten years:
    – badly hardware, my laptop is like a shuttle and worked like a bicycle under linux, cpu scaling and cooling most of all
    – crappy graphic drivers
    – not working suspend
    – missing 3rd party software, using skype most of my days I can’t use the linux version

    most of these points are not strictly linux related but i need to use all my hardware the right way and, now, i don’t really care about what kernel is running if it’s running fine

  3. Mario Spada

    Ok, I realized that hardware holds the balance of OS….
    It’s interesting to have known CygWin, it looks me something like Wine under Linux…
    However I bought a new Dell laptop Ubuntu certified: no hardware issues, even suspend works perfectly!

  4. Fabrizio Balliano Post author

    suspend working this ubuntu release, but next one? and next+1? had too many problems in the past.

    anyway cygwin is not an emulator and it works perfectly, wine instead didn’t work even one time for me

  5. Rich

    Wish it would install smoothly.

    I used the command in cygwin terminal: cygstart — /path/to/setup.exe -K

    Then added repository url and selected for use:

    Then selected PHP and a few PHP mods/plugins like mcrypt.

    It starts, but fails at 80%+ and asks if it would like to “try again”. And of course, fails again. I’ve tried all the other mirrors but it gives me “setup.ini” errors and cannot load packages.

    Any suggestions?

  6. Snick

    I understand the way drivers are bias toward windows, so I understand your motivation, but viruses can play havoc on Windows machines don’t underestimate it. Just this last week I went to a client site and Kaspersky caught five web viruses that get a foothold via browser. Nothing got through, but once something is on a windows machine it’s hard to root out, and it happens more often than people are actually aware of.

    I have a 50/50 split of Windows/Linux (Ubuntu, CentOS) on my local machines… I love both for certain things, but Windows can be tricky to keep clean. If you are more tech savvy I always recommend browsing in something like sandboxie, to help provide another layer of protection. It won’t protect you if you purposely move a file out of the sandbox but it helps protect against browser exploits.

    But that is not my reason for posting, I just wanted to mention that I have used cygwin in the past and if you want all the shell functionality that is a good option.

    But I have found for quick deployment and ease of maintenance on win, I much prefer either a complete linux VM in VirtualBox (Which works really well under windows), or a prepackaged LAMP stack like XAMPP or Z-WAMP. The only problem with the latter is the apache instead of lighttpd, which is quite a quick web server.

    I have both Z-WAMP and an instance of Ubuntu x64 running in VirtualBox right now (Plus Virus Scanner, Firefox, etc..) and my machine is running at between 5-10% CPU

    Just my two cents since this has been an issue I’ve dealt with over the past five years, and I have finally found a mix of solutions that cover most of my needs on win machines.


  7. adult social network adult sharing adult stories

    Hi I am so glad I found your website, I really found
    you by accident, while I was looking on Askjeeve for something else,
    Regardless I am here now and would just like to say many thanks for a remarkable post and a all
    round thrilling blog (I also love the theme/design), I don’t have time to look over it all at the minute but I have saved it and also added in your RSS feeds, so when I have time I will be back to read much more, Please do keep up the fantastic job.

Leave a Reply

Your email address will not be published. Required fields are marked *