Alice.

Wednesday September 5, 2007

Porting lighttpd to the iPhone.

After a full night of hacking, nearly bricking my iPhone once, and way too much caffeine, I have finally done it. I have a viable port of lighttpd for the iPhone. Even CGI using Perl, Python, and Ruby works, if installed!


iPhone Screenshot
If you are visiting this page from a link on a forum, please be aware that the URL may be truncated. Please use this link instead, and update your bookmarks. The Comments feature will not work unless you use the correct URL.
This article has been updated with information regarding the latest iPhone firmware.

Apache was already available via Installer.app, but just thinking about what a resource hog Apache can be, I decided I'd rather run lighttpd. Lighttpd, after running a few requests, uses 876 bytes of real memory and has a virtual footprint of 267KiB. That's damn good.

Getting it compiled was a bit of a pain, though, and took a long, long time. I followed the handy instructions on the iPhone Dev Wiki, downloaded and extracted the latest lighttpd source, and ran the following commands:

export CC=/usr/local/arm-apple-darwin/bin/gcc
export CXX=/usr/local/arm-apple-darwin/bin/g++
export LDFLAGS=-Wl,-syslibroot,$HEAVENLY
export DESTDIR=/Users/amcgregor/Public/iPhone/lighttpd-1.4.17/stage/

./configure --host=arm-apple-darwin --prefix=/usr/local
make
make install

I copied the contents of the stage folder to the root of my iPhone, wrote up a simple configuration file, SSH'ed in, and gave it a whirl. Worked like a hot damn. With the finishing touches I wrote a launchd init-script and filled out the configuration file to offer CGI via Perl, Python, and Ruby.

Lighttpd is available using Installer.app thanks to the gracious hosting of Ste packaging (accessed through Community Sources). Please install from there.

The webroot is in /private/var/root/Sites/. The reason for this vs. /Library/WebServer/Documents as per Mac OS X Server and the iPhone Apache installation is because /Library is normally a read-only filesystem (when jailed) and has limited storage space. The home folder is stored in a separate partition which uses the vast majority of the 4 or 8 GB of the device.

In iPhone Firmware 1.1.3 using the root account is frowned upon. You can move the webroot using SSH, SFTP, AFPD, or SMBD from `/private/var/root/Sites` to `/private/var/mobile/Sites` if you wish. Just remember to change the ownership of the files (as root) after moving using something similar to the following:

chown -R ~mobile/Sites

Modify /usr/local/etc/lighttpd.conf and change the first line:

server.document-root = "/private/var/mobile/Sites/"

Enjoy!

— Alice.

Written by Alice McGregor at 7:04 AM.

profile

Name:Alice McGregor →アリス

Location:British Columbia, CA

Duration of HRT:

Growing up in a small town is tough when you're this strange.

View my complete profile

E-MAIL: alice@gothcandy.com

MSN: alice@gothcandy.com

AIM: GothAliceMalk

Tags

This entry has been tagged with the following keywords:

花鳥風月

We having the same spirit of faith, according as it is written, I believed, and therefore have I spoken; we also believe, and therefore speak;

For which cause we faint not; but though our outward man person perish, yet the inward man person is renewed day by day.

For our light affliction, which is but for a moment, worketh for us a far more exceeding and eternal weight of glory;

While we look not at the things which are seen, but at the things which are not seen: for the things which are seen are temporal; but the things which are not seen are eternal.

— 2 Corinthians 4