Building Titanium with PHP

Mon, 5 Oct 2009 19:48 UTC

Several months ago, I started the process of embedding PHP into the Titanium platform. After several sprints of work, the Appcelerator team was finally ready to merge my work into their master branch, and Martin Robinson worked to bring the implementation to maturity. The current release of Titanium Developer does not yet have the PHP support built in to the bundled SDK, and I’m not sure when it will be released, so I thought I’d share how to get a development version built with PHP support so you can start playing with it and even help the Appcelerator team by catching bugs in the implementation.

If you’re not familiar with Titanium, it’s a development platform that allows you to build native desktop applications for Windows, Mac OS X, and Linux using the Web technologies we use on a daily basis: HTML, JavaScript, CSS, Python, Ruby, and now PHP. Titanium is built on top of WebKit, and it includes a micro-kernel called Kroll that does all of the pre-processing and runtime processing of the code. Languages are modules in Kroll and are first-class citizens in the runtime environment. So, when using the runtime, you can pass objects back and forth between JavaScript, PHP, Python, and Ruby. This, however, can’t be done when using pre-processing mode, but in that case, your PHP scripts will work just like you’re used to them working on a web server.

Since it may still be a while before the next release of Titanium that includes PHP, I’ve decided to provide instructions here on how to build the SDK from the master branch and connect it to the Titanium Developer application. Sorry, but I don’t have instructions for Windows; these work on Mac or Linux.

  1. Download (and install) Titanium Developer from http://www.appcelerator.com/products/download/
  2. Launch Titanium Developer and let it do its thing (you’ll have to create an acct)
  3. Now you may close it
  4. You should now have a Titanium directory with the SDK in it at either:
    • /Library/Application\ Support/Titanium/ (Mac)
    • ~/.titanium/ or /opt/titanium/ (Linux)
  5. Now, build the development SDK to use with Titanium Developer. You’ll need Python, scons, a compiler, and possibly other prerequisites.
    $> git clone git://github.com/appcelerator/titanium_desktop.git
    $> cd titanium_desktop/
    $> git submodule update --init
    $> scons dist
    
  6. Unzip the built SDK to some location. I like to use ~/.titanium-dev/
    $> unzip build/osx/dist/sdk-0.7.0.zip -d ~/.titanium-dev/
    
  7. Move Titanium Developer SDK out of the way and point to your build SDK
    $> cd /Library/Application\ Support/Titanium/
    $> mv modules/ modules-old/
    $> mv runtime/ runtime-old/
    $> mv sdk/ sdk-old/
    $> ln -s ~/.titanium-dev/modules modules
    $> ln -s ~/.titanium-dev/runtime runtime
    $> ln -s ~/.titanium-dev/sdk sdk
    
  8. Now relaunch Titanium Developer.

You’re now ready to build a project with PHP!

Click Create to generate a stub project. I’ll cover more about development with PHP in Titanium in the future, but let’s get started by showing a phpinfo() page.

Open the index.html file in the Resources directory of your project and add the following anywhere in the page:

<p><a href="phpinfo.php" style="color:gray;">See the phpinfo()</a></p>

In the Resources folder, create the phpinfo.php script and add the following to that script:

<?php phpinfo(); ?>

Now, go back to Titanium Developer, click the Test & Package tab for your project, then click the Launch tab. To build and run your application for testing, click the Launch App button.

You should now see a dark gray test page with the “See the phpinfo()” link you created. Click that link, and it should take you to the phpinfo.php script you created with the proper phpinfo() output. Congratulations!

Visit the Appcelerator Codestrong developer center for more information on building Titanium applications. Visit #titanium_app on Freenode IRC to ask questions about application development. If you want to help develop the project and contribute PHP tests to it, join #titanium_dev.


12 Responses to “Building Titanium with PHP”

Very Cool! Awesome work. I’ll have to mess with it tonight.

Comment by OnyxRaven
Mon, 5 Oct 2009 at 21:28 UTC | Permalink

Anyone compiled for windows yet?

Comment by EllisGL
Tue, 6 Oct 2009 at 1:55 UTC | Permalink

We’re hoping to release end of this week. Developer will be updated with final PHP support in the next day or so. We hope 0.7 will be released by Friday if all testing goes well.

Thanks for your help, Ben. We couldn’t have done it without you!

Comment by Jeff Haynie
Tue, 6 Oct 2009 at 7:22 UTC | Permalink

Had some problems compiling on Ubuntu (latest version). I forced it to ignore errors and got the linux build to compile.

Following your instruction above didn’t quite work as advertised. I have to update the Titanium Developer manifest file to say it was using version 0.7.0 to get it to run.

Then even when I do run it it hangs and has to be killed with kill -9.

The last line output in the terminal is:

[10:58:19:881] [Titanium.Host] [Information] Loaded module = tiworker

Can’t wait to get developing with PHP in this!

Any suggestions?

Thanks

Comment by Jon
Tue, 6 Oct 2009 at 10:59 UTC | Permalink

For ubuntu users, the README on github provides you with all the dependencies you might need. Save yourself some time and simply copy that line into your console. Once you have, it compiles perfectly.

The only problem I have is the “relaunch Titanium Developer”—I can’t find a binary that does this within the linux install (either from the original distribution or the source distribution). It installed on the initial install, but I can’t find where to do launch it myself.

Comment by Matthew Weier O'Phinney
Tue, 6 Oct 2009 at 14:18 UTC | Permalink

Matthew: in the Titanium Developer.tgz package you downloaded from http://www.appcelerator.com/products/download, you should find the Titanium Developer binary. Just execute it to launch it.

Comment by Ben Ramsey
Tue, 6 Oct 2009 at 18:30 UTC | Permalink

Ive yet to play with titanium but after reading this i’ll be giving it a go this weekend :)

Comment by Phil
Wed, 7 Oct 2009 at 14:03 UTC | Permalink

That is great news. I’ve been waiting for this for quite a while, great work.

Comment by Tinu Coman
Wed, 14 Oct 2009 at 9:05 UTC | Permalink

Readers may be interested to know that version 0.7 of Titanium was released today, and it supports PHP. So, all the compiling above is optional.

Comment by Philip Olson
Wed, 14 Oct 2009 at 16:43 UTC | Permalink

Unfortunately when I create the index.html and the phpinfo.php file the application crashes :)

Comment by Andrew Wooldridge
Wed, 14 Oct 2009 at 20:04 UTC | Permalink

Dear Ben,

I have been going around in circles trying to see how to use PHP extensions (.so or .dll) in the mix.

Would you mind please explaining it?

TIA

Paul

Comment by Paul A Norman
Wed, 4 Nov 2009 at 3:15 UTC | Permalink

I am encountering a problem while building project using PHP with Titanium. After packaging I am getting fatal error while launching project.

Comment by Haresh Patel
Tue, 15 Dec 2009 at 10:14 UTC | Permalink

Leave a Comment

XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
APPROVAL: Comments may require approval. Please be patient.