Posts Tagged ‘Ubuntu’

Installing, Configuring, and Using the XHP PHP Extension by Facebook

Authored by Calvin Freitas on February 10th, 2010

Facebook announced the release of XHP yesterday. It is an extension for PHP which provides enhancements to the PHP language syntax and gives the language some convenient capabilities.

In this post I will provide you links to the essential sources of information about XHP, show some XHP sample code, and discuss the installation process for XHP on Ubuntu with Apache and PHP5.

The Essential Information
Download XHP at GitHub
How XHP Works
Building XHP
Configuring XHP

Example XHP Sample Code (View Code in Action):

<?php
require_once('/home/cal/facebook-xhp-290b185/php-lib/init.php');
$name  = 'Calvin Freitas';
$title = "{$name} loves XHP!";
$url   = 'http://calvinf.com/';

$permalink = 'http://wp.me/pcoLC-4e';

#create a <head> element
$head =
  <head>
   <title>{$title}</title>
  </head>;

#create a div
$div =
  <div id="header">
    <h1>{$title}</h1>
  </div>;

$body =
  <body>
    {$div}
    <div>
      <p>My name is {$name} and you should go visit <a href={$url}>my website</a> now.</p>
      <p>Read my <a href={$permalink}>guide to installing XHP on Ubuntu</a>. It includes the source code for this page. Comments and corrections are welcome.</p>
    </div>
  </body>;

echo
<html>
  {$head}
  {$body}
</html>;
?>

A few syntax notes
XHP forces you to properly nest tags — make sure you close them properly or it won’t compile and it will throw errors. Because XHP auto-escapes, when you’re creating a link (such as in an a element), you don’t need to put quotes around it.

<a href={$permalink}>guide to installing XHP on Ubuntu</a>

Installing XHP on Ubuntu
Server: Ubuntu 9.10 running on a slice at the Rackspace Cloud.
Web server: Apache 2
Apache installation guide (Slicehost article, but generally applicable)

Below I will go into more detail about the installation process.
Read the rest of this entry »