Sample code/PHP/Hello World

This page presents a PHP variation of the classic "Hello World" program. hello.php does not need to be executable with lighttpd. Others, like BOA, require it since they also require the #!/usr/bin/php-cgi. lighttpd doesn't have those requirements, it's a bit more 'sane'.

The source
The source code for the Hello World program is presented here:



Enabling the lighttpd webserver
Enabling lighttpd is relatively simple. This first part is done on the host PC where the buildroot is located.

First, type: make menuconfig

Then, select the php option: Package Selection for the target ---> [*] php [*] cli interface [*] cgi interface [*] openssl suport [*] zlib support

Just select php and the others will by selected as default. Exit the menu and remember to select yes to save the configuration.

make

Reflash your gumstix via the Replacing Filesystem Image page.

Navigate to lighttpd.conf on the gumstix and do the following:


 * Note - You'll need to use some form of a text file editor. You can do this by selecting one in the menuconfig menu. I'm using nano to edit these files; you could use vi or ed as well.

nano /etc/lighttpd.conf

Under server.modules I have the following uncommented: "mod_access", "mod_cgi",

Next, the document-root: server.document-root       = "/www/pages"
 * 1) a static document-root, for virtual-hosting take look at the
 * 2) server.virtual-* options

Comment out the $HTTP directive so that it looks like:
 * 1) $HTTP["url"] =~ "\.pdf$" {
 * 2)  server.range-requests = "disable"
 * }

Add the following below under the appropriate part of the document: cgi.assign                 = ( ".php" => "/usr/bin/php-cgi") Replace /usr/bin/php-cgi with where php-cgi is located within your file system.

Save and exit: ctrl-x y

You'll need to create the directories: /www /www/logs and /www/pages. cd / mkdir www && mkdir /www/logs && mkdir /www/pages

Test to see if the config file works: Syntax OK
 * 1) lighttpd -tf /etc/lighttpd.conf

Finally, start lighttpd:
 * 1) lighttpd -f /etc/lighttpd.conf

That should do it!

Using hello.php
Upload hello.php to the gumstix folder /www/pages and change the permissions. chmod 755 /www/pages/hello.php

With lighttpd running, navigate your browser to the gumstix ip address: http://localhost:port/hello.php

i.e. http://192.168.167.16:82/hello.php

The default port is 80 but that can be changed in lighttpd.conf.

Using SQLite
I tried for two weeks and wasn't able to get PHP talking with SQLite3. As such, I'm using Python which seems to work rather well.