Drupal 7 served from the G1 phone using lighttpd web server, php-cgi, and php-sqlite

05 Feb 2009

Posted by CrashTest_

If that title doesn't get your attention, you aren't a geek, srsly.

drupal on the g1
After hearing a little interest from some people around irc-land, and from one person who I am considering starting a G1-fund for, I decided that I should try to get Drupal 7 working on my T-Mobile G1 phone. After all, it's an Open phone, right? I might have even uttered those words my wife and I always regret; "How hard can it be?"

Actually, it wasn't that hard :)

Many people have blazed trails in this direction, especially JesusFreke and Jay Saurik, by figuring out a new and better root hack for the G1 (and creating an image), and for creating a good way to get Debian on there once you have root.

Here is what I did:

First, I needed to get root access to my phone. For this I went to http://android-dls.com/wiki/index.php?title=Quick_Root and followed the directions. Pretty simple really. If you do have problems, a good place to ask questions is the Freenode IRC channel, #android-downloads, they were pretty darn helpful in there.

Second, I needed to install Debian. I tried, several times, to work through the fairly straightforward directions on Jay Saurik's post about getting Debian on the G1, however they didn't really take into account the new RC29 image by JesusFreke. Here is where I ran into the most problems, and they are all solved by going another route. After asking many seemingly dumb questions on irc.saurik.com #android, I was directed to an "installer" and was able to get Debian running smoothly using the instructions and files from here.

A couple of things to keep in mind when installing:

  • Some things seemed to have gotten corrupted, so check the hash.
  • Take your chances with this image, or download Jay's image, as I found tools that you might not want or need in this install, such as ettercap, tcpdump, aircrack-ng. Not sure what his game is, but it may not be good. You could always build your own image, as Jay mentions, and go from there.
  • With the newer images, insmod'ing ext2 and union isn't necessary, and in fact you will need to su, then modprobe ext2 instead.
  • I don't believe you have to use the version of BusyBox he mentions in the instructions, as JesusFreke includes a perfectly acceptable version in his image.
  • If you log out, you will need to su, and modprobe ext2 again before you can successfully run the bootdeb script again (actually I suppose this could just be added to that script).

One thing I want to mention, the "installer" guy uses passages and code directly from Jay's site, yet I don't see credit given there. I think saurik might say "Frowny Pants to that," maybe.

Third, if you make it through all of those hurdles, you can start installing stuff. I installed the following items, and modified some config files to get things to work:

  • apt-get install lighttpd php5-cgi php5-cli php5-sqlite
  • Edit /etc/php5/cgi/php.ini and include the line "cgi.fix_pathinfo = 1" at the end of the file
  • In that same file, up your timeout to something more reasonable for a phone ;) I put mine at 120 seconds
  • In the server.modules section of /etc/lighttpd/lighttpd.conf, you need to add "mod_fastcgi", including the quotes and the comma.
  • At the end of that same file add:
    fastcgi.server = ( ".php" => ((
                         "bin-path" => "/usr/bin/php5-cgi",
                         "socket" => "/tmp/php.socket"
                     )))
  • Lastly, after making these changes, you should be able to run "/etc/init.d/lighttpd restart" and have a Drupal 7 ready web server running.

Fourth, install Drupal. To do this, go to your /var/www directory, wget http://ftp.drupal.org/files/projects/drupal-7.x-dev.tar.gz and unpack it. Rename it what you like.

A couple of notes, on the phone, you will need to cp /var/www/yoursite/sites/default/default.settings.php to /var/www/yoursite/sites/default/settings.php. You will need to mkdir /var/www/yoursite/sites/default/files. I am not sure, but I think I needed to also create the db file by doing a "touch /var/www/yoursite/sites/default/files/.ht.sqlite" and chmod'ing all of these so the server can write to them.

Run ifconfig on your phone to figure out what your IP address is, then point your browser (on a computer) to that IP/your site directory.

During the install, if you have things setup, Drupal will contend that it can install, and give you only the option to install using sqlite. It will ask you for the database name, and you will give it, exactly:

sites/default/files/.ht.sqlite

Do not give it a username or password for the database setup portion, it will not work (taken from http://drupal.org/files/issues/INSTALL.sqlite.txt)

I will guarantee that if you hadn't upped your PHP timeout in the previous step, you will now run into issues, however, if you had, you should be able to make it through the install, and CONGRATULATIONS! you now have Drupal on your G1!

See, how hard was that? :)

Edit: A note about Apache. I did try to do this with Apache2, however it seems there may be a bug with the Arm version of Apache2 binary that you get from apt-get install apache2, as it gave me the error "[emerg] (38)Function not implemented: Couldn't create accept lock /usr/include/linux" every time. I didn't decide to try to track this down. After getting lighttpd up and running it occurred to me that perhaps lighttpd was already installed and locking the socket, maybe? Don't know, someone else can track that down and figure it out. Lighttpd/php5-cgi/php-sqlite works for me.

Sitewide Terms: 

Comments

why?


Pre-empting the obvious:

Q: Why on earth would you want to do that?
A: Because he can!


Pictures or it didn't happen! :)


haha im with them why on earth.... but only to show off the g1... GO G1 GO!!


proving once again, even in the event of a nuclear holocaust, Drupal 7 will live on...


it runs on a cockroach???


now to get dyndns working and you have a portable webserver on your G1


It's not a bug, it's a feature missing from the default kernel build. I can supply one that will run apache if you'd like.


For the exact reason noted in number 2: because I can... ;)

Great job, I'll have to look into it a bit more now that I r00ted this beast. Tahnks for the post! Appreciate the pics!


Thanks! been looking everywhere on how to do this|! appreciate it greatly.


tahst power!...

just one question, g1 vs iphone? is it possible compile apache,php,mysql etc from source on the iphone?


Good effort to get Drupal 7 working on your G1! You make it sound easy. And you are right, this is a seriously geeky topic! (edited by admin to remove spam link)