====== Setting up Lighttpd on a Mac ======= ===== 1.0 Install MacPorts ===== First step is to install [[http://www.macports.org/|MacPorts]]. They have [[http://trac.macosforge.org/projects/macports/wiki/InstallingMacPorts|a good tutorial]] for it so I won't be covering that subject here. ===== 2.0 Install Lighttpd ===== Before installing lighttpd you have to install lua. sudo port install lua Next install lighttpd using MacPorts: sudo port install lighttpd +cml **Warning**: The launchctl command creates following error ''Workaround Bonjour: Unknown error: 0.''. I've read it's harmless - let's hope so :) Automatically launch lighttpd on (re)boot: sudo launchctl load -w /Library/LaunchDaemons/org.macports.lighttpd.plist ==== 2.1 Lighttpd Settings ==== Create the configuration file for lighttpd. You can copy the default config file by this command: cp /opt/local/etc/lighttpd/lighttpd.conf.default /opt/local/etc/lighttpd/lighttpd.conf === 2.1.1 Document Root === If you'r going to use the folders the default configure file of lighttpd suggests then create following directories: sudo mkdir /www/pages sudo mkdir /www/logs You can run those commands without sudo, too. If you want to use the same document root as the preinstalled Apache uses, make the following changes to the configuration file using your favourite editor, or vi: ''vi /opt/local/etc/lighttpd/lighttpd.conf'' row 40. server.document-root = "/Library/WebServer/Documents/" 43. server.errorlog = "/Library/Logs" === 2.1.2 Mod Rewrite === Enabling mod_rewrite makes it (hopefully) possible to use the .htaccess magic... # Rewrite server.modules += ("mod_rewrite") === 2.1.3 Users' Site Directories - userdirs === If you'd like to use the user directories like ''/~username/'' add these lines to the end of the ''/opt/local/etc/lighttpd/lighttpd.config'' file: # userdir server.modules += ("mod_userdir") userdir.path = "Sites" userdir.basepath = "/Users/" === 2.1.4 Directory Listing === Lighttpd provides a directory listing that you probably want to use if you came from Apache, which has it enabled by default. So add these lines to the end of the config file: # directory listing dir-listing.activate = "enable" ===== 3.0 MySQL ===== Install MySQL with the following command: sudo port install mysql5 +server **Warning**: The launchctl command creates following error ''Workaround Bonjour: Unknown error: 0.''. I've read it's harmless - let's hope so :) And enable the automatic launch by: sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist You can also install the non-automatic version by typing: sudo port install mysql5 ==== 3.1 Set up databases ==== Set up the DB so that MySQL can be used. sudo -u mysql mysql_install_db5 And root password for MySQL mysqladmin5 -u root password [yourpw] ===== 4.0 PHP ===== Install PHP with the following command: sudo port install php5 +fastcgi +mysql5 +pear Copy the php.ini file: sudo cp /opt/local/etc/php.ini-dist /opt/local/etc/php.ini ==== 4.1 Enable FastCGI to handle PHP scripts ==== Add this line to your ''/opt/local/etc/php.ini'': cgi.fix_pathinfo = 1 And add these lines to your ''/opt/local/etc/lighttpd/lighttpd.conf'' file: # FastCGI server.modules += ("mod_fastcgi") fastcgi.server = ( ".php" => (( "bin-path" => "/opt/local/bin/php-cgi", "socket" => "/opt/local/var/run/php5/php.socket" )) ) More about this subject [[http://trac.lighttpd.net/trac/wiki/TutorialLighttpdAndPHP#Configuration|here]]. ===== 5.0 Running lighttpd as project server ===== Save this file to somewhere in your project/application/site directory, f.e. ''[application]/config/lighttpd/lighttpd.conf'' Note that the following line: magnet.attract-physical-path-to = ( CWD + "/../akelos/lib/AkActionController/lighttpd/akelos.lua" ) has to be relative path from your [project/application/site] directory to your akelos framework directory - including the first slash. # Default configuration file for the lighttpd web server # Start using ./script/server lighttpd server.bind = "0.0.0.0" server.port = 3000 static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" ) index-file.names = ( "index.php" ) server.modules = ( "mod_accesslog", "mod_fastcgi", "mod_compress", "mod_expire", "mod_magnet" ) server.document-root = CWD + "/public/" server.errorlog = CWD + "/log/lighttpd.error.log" accesslog.filename = CWD + "/log/lighttpd.access.log" fastcgi.server = ( ".php" => (( "bin-path" => "/opt/local/bin/php-cgi", "socket" => CWD + "/tmp/php.socket" )) ) $HTTP["url"] =~ "^/" { index-file.names = ( "index.php" ) magnet.attract-physical-path-to = ( CWD + "/../akelos/lib/AkActionController/lighttpd/akelos.lua" ) } compress.filetype = ( "text/plain", "text/html", "text/css", "text/javascript" ) compress.cache-dir = CWD + "/tmp/cache" expire.url = ( "/favicon.ico" => "access 3 days", "/images/" => "access 3 days", "/stylesheets/" => "access 3 days", "/javascripts/" => "access 3 days" ) 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", ".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" ) # Making sure file uploads above 64k always work when using IE or Safari # For more information, see http://trac.lighttpd.net/trac/ticket/360 $HTTP["useragent"] =~ "^(.*MSIE.*)|(.*AppleWebKit.*)$" { server.max-keep-alive-requests = 0 } And this file to your akelos framework directory [akelos_framework]/lib/AkActionController/lighttpd/akelos.lua function file_exists(path) local attr = lighty.stat(path) if (attr) then return true else return false end end function removePrefix(str, prefix) return str:sub(1,#prefix+1) == prefix.."/" and str:sub(#prefix+2) end -- local prefix = '/akelos' local prefix = '' if (not file_exists(lighty.env["physical.path"])) then request_uri = removePrefix(lighty.env["uri.path"], prefix) if request_uri then lighty.env["uri.path"] = prefix .. "/index.php" local uriquery = lighty.env["uri.query"] or "" lighty.env["uri.query"] = uriquery .. (uriquery ~= "" and "&" or "") .. "ak=" .. request_uri lighty.env["physical.rel-path"] = lighty.env["uri.path"] lighty.env["request.orig-uri"] = lighty.env["request.uri"] lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"] end end Create the folders [application]/tmp, ./tmp/cache, ./log I needed to add session.save_path = "/tmp" to my ''/opt/local/etc/php.ini'' file Run the lighttpd "project" server: lighttpd -f config/lighttpd/lighttpd.conf -D And go to ''http://localhost:3000/'' ===== Summary ====== For now, everything seems to be ok for me. Only problem is that lighttpd doesn't support .htaccess files and to get the pretty URIs work the magic should be added to ''/opt/local/etc/lighttpd/lighttpd.conf'' With the "project server" approach everything - even the pretty URIs - works.