I am slowly hacking away at my identity faceting service and wanted to play with exposing facet history with atompub. I found Jeroen Hoekx’s php-atompub-server.
This post is how to setup an Atompub server using PHP5. This post assumes you are using (and are familiar with ) Apache2, PHP 5, and Linux. I will be doing this on an Ubuntu VM which I’ve hardcoded into my /etc/hosts file as ofaceatom.ubuntu. I’ll walk you through what I did to get the test app up and running, but you might want to read php atompub server’s wiki Overview and then HTTPServer for more background.
Pick a place to install. I will refer to this as $DEV_PATH
cd $DEV_PATH
svn checkout http://php-atompub-server.googlecode.com/svn/trunk/ php-atompub-server-read-only
On your development machine, map an apache2 VirtualHost’s DocumentRoot to $DEV_PATH/php-atompub-server-read-only
Edit $DEV_PATH/php-atompub-server-read-only/app/start/start.php
$base_uri = new URI(“http://ofaceatom.ubuntu/app”);
Create a .htaccess file in $DEV_PATH/php-atompub-server-read-only/app/
RewriteEngine On
RewriteRule ^(.+) start.php
DirectoryIndex start.php
chmod go+w $DEV_PATH/php-atompub-server-read-only/app
The server will create ’store’, ‘lists’, and ‘cache’ directories under the app directory, but mkdir will fail in appfilestore.php if apache doesn’t have permission to write here…
Make a request to http://ofaceatom.ubuntu/tools/ an ensure that you get a directory list of
data1.xml
manager
postatom.html
If you point your browser to http://ofaceatom.ubuntu/app/ you will see the output
<service>
−
<workspace>
<atom:title>PHP AtomPub Server</atom:title>
−
<collection href=”test/”>
<atom:title>AtomPub Test: Test</atom:title>
<accept>*/*</accept>
</collection>
−
<collection href=”news/”>
<atom:title>AtomPub Test: News</atom:title>
</collection>
−
<collection href=”media/”>
<atom:title>AtomPub Test: Media</atom:title>
<accept>*/*</accept>
</collection>
</workspace>
</service>
or it may ask you to save a file, depending on your setup. (the mime-type is application/atomsvc+xml)
Test Page
http://ofaceatom.ubuntu/tools/postatom.html
is an HTML based Atom client which you can use to test the server.
Change the URI feild to your hostname. For me that’s
http://ofaceatom.ubuntu/app/
Click Submit and you will see
STATUS: 200 Ok
Date: Sat, 24 Jan 2009 02:46:00 GMT
Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch
X-Powered-By: PHP/5.2.4-2ubuntu5.3
Cache-Control: must-revalidate
Etag: “21a609367f0b4ee98bba15771419be4d;gzip”
Content-Encoding: gzip
Vary: Content-Encoding
Content-Length: 254
Content-Type: application/atomsvc+xml
<?xml version=”1.0″ encoding=”utf-8″?>
<service xmlns=”http://www.w3.org/2007/app”
xmlns:atom=”http://www.w3.org/2005/Atom”
>
<workspace>
<atom:title>PHP AtomPub Server</atom:title>
<collection href=”test/”>
<atom:title>AtomPub Test: Test</atom:title>
<accept>*/*</accept>
</collection>
<collection href=”news/”>
<atom:title>AtomPub Test: News</atom:title>
</collection>
<collection href=”media/”>
<atom:title>AtomPub Test: Media</atom:title>
<accept>*/*</accept>
</collection>
</workspace>
</service>
Clicking the Clean button will clear the output.
Notice that there is a “test” collection… lets look at it.
Change the URI input to http://ofaceatom.ubuntu/app/test/
And press Submit
We see an empty Atom feed.
We’ve been using the GET method, let’s create an item.
Change the METHOD input to POST and click submit.
STATUS: 201 Created
You’ll need to have a unique SLUG value for each post on the test collection.
The item lives at http://ofaceatom.ubuntu/app/test/test.atomentry
Using PUT on this url, you can change the contents of that item.
Now you can go back to the atom feed at
http://ofaceatom.ubuntu/app/test/
And your item is in the list. Once you create more than 10 items, this feed is paginated.
You can now play around with news and media collections just like test. Note that news requires the http://htmlpurifier.org/ library to be installed as noted on the wiki at SanitizingInput.
If you get tired of changing the URI, you can edit line 11 of $DEV_PATH/php-atompub-server-read-only/tools/postatom.html to change the prefilled value for the atom service
document.getElementById(“uri”).value = “http://ofaceatom.ubuntu/app/”;
All in all a very cool project from Jeroen. To learn more and play with exposing your data via atompub, next steps are to do some hacking, and read HowItWorks, ExtensionModel and then phpBBStore.
