Building Titanium with PHP
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.
-
Download (and install) Titanium Developer from http://www.appcelerator.com/products/download/
-
Launch Titanium Developer and let it do its thing (you’ll have to create an acct)
-
Now you may close it
-
You should now have a Titanium directory with the SDK in it at either:
/Library/Application\ Support/Titanium/(Mac)~/.titanium/or/opt/titanium/(Linux)
-
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 -
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/ -
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 -
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.
14 Comments
Very Cool! Awesome work. I'll have to mess with it tonight.
Anyone compiled for windows yet?
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!
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
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.
Matthew: in the
Titanium Developer.tgzpackage you downloaded from http://www.appcelerator.com/products/download, you should find theTitanium Developerbinary. Just execute it to launch it.Ive yet to play with titanium but after reading this i'll be giving it a go this weekend :)
That is great news. I've been waiting for this for quite a while, great work.
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.
Unfortunately when I create the index.html and the phpinfo.php file the application crashes :)
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
I am encountering a problem while building project using PHP with Titanium. After packaging I am getting fatal error while launching project.
Hi all, I have a problem when using scons. Still having error after install the dependencies?? I have put that in the ubuntu forum as well. But any help will be appreciated here. Thanks ~
http://ubuntuforums.org/sho...
Hi Ben -
Have you been able to successfully load PHP shared modules using dl(...); ? I compiled imap.so and tried to dynamically load imap at runtime with no success.
Do you have any suggestions for those who are looking to do dynamic loading?
P.S. - I ran phpinfo() and noted that dl_enabled was not in the property list... also noted that the php build root is on /opt/php
Tech Notes: Running Mac OS X 10.6.5 / building from php-5.3.4 / macports pcre, libconv, etc, etc