Monday, July 5, 2010

New 10.4 LTS Dev Environment

Today I slicked my drive full of Ubuntu upgrades and performed a fresh install using the latest version of 10.4 LTS. It occurred to me this might be a good time to document some steps to get a minimum dev environment up and going on Ubuntu:

1) Install Java
  • Download from http://java.sun.com/javase/downloads/index.jsp
  • chmod 777 jdk-6u20-linux-x64.sh
  • ./jdk-6u20-linux-x64.sh
  • mv jdk1.6.0_20 /usr/local/lib/jdk1.6.0_20/bin/java
  • sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/lib/jdk1.6.0_20/bin/java" 1
  • sudo update-alternatives --set java /usr/local/lib/jdk1.6.0_20/bin/java
  • Create sym link for Firefox Java Plugin:
  • ln -s/usr/local/lib/jdk1.6.0_20/lib/amd64/libnpjp2.so ~/.mozilla/plugins
2) Install Eclipse
  • Download from http://www.eclipse.org
  • Extract to "eclipse" and move to new home
  • Install SVN plugin and checkout project from sourceforge
3) Install Apache & PHP 5.3
  • sudo apt-get install php5 php5-mysql php5-pgsql php5-sqlite php5-curl php5-xsl php5-mcrypt php5-dev php5-xdebug php-pear php-gettext
  • sudo vim /etc/php5/cli/conf.d/mcrypt.ini (remove deprecated ini #comment)
4) Install & configure MySQL 5.1
  • sudo apt-get install mysql-server mysql-client
  • grant all privileges on *.* to php@localhost identified by 'php007';
5) Install & configure PostgreSQL 8.4
  • sudo apt-get install postgresql
  • sudo -s
  • su postgres
  • createuser -P -s -e php (password php007)
CREATE ROLE php PASSWORD 'md51a344967d2534f238d89148a8f67bd7a' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
  • - createdb -O php php
6) Import agilephp_test and agilephp_studio MySQL schemas
  • mysql -u root -p < /storage/Apps/eclipse-galileo/workspace/AgilePHP/test/agilephp_test.sql
  • mysql -u root -p < /storage/Apps/eclipse-galileo/workspace/AgilePHP/studio/agilephp_studio.sql
7) Configure Apache Virtual Host
  • vim /etc/apache2/conf.d/agilephp
<VirtualHost *:80>
ServerName agilephp
DocumentRoot "/storage/Apps/eclipse-galileo/workspace/AgilePHP"
DirectoryIndex index.php

<Directory "/storage/Apps/eclipse-galileo/workspace/AgilePHP">
AllowOverride All
Allow from All
</Directory>

</VirtualHost>
  • Create hosts entry that points "agilephp" to localhost
8) Make AgilePHP/test/logs writable
  • sudo chmod -R 777 test/logs
9) Install Phing
  • sudo pear channel-discover pear.phing.info
  • sudo pear install --alldeps phing/phing
11) Install PHPUnit
  • sudo pear channel-discover pear.phpunit.de
  • sudo pear install phpunit/PHPUnit
12) Install PEAR_PackageFileManager
  • sudo pear install PEAR_PackageFileManager channel://pear.php.net/XML_Serializer-0.20.0
13) Install JSlint
  • Download from http://www.javascriptlint.com/download.htm
  • Extract archive
  • cd jsl-0.3.0/src
  • make -f Makefile.ref
  • sudo ln -s /storage/Sources/jsl-0.3.0/src/Linux_All_DBG.OBJ/jsl /usr/bin/jsl
14) Install YAML
  • apt-get install libyaml-0-2 libyaml-dev
  • sudo pecl install yaml channel://pecl.php.net/yaml-0.6.3
  • sudo vim /etc/php5/conf.d/yaml.ini
  • # yaml.ini
    extension=yaml.so
15) Install Sendmail
  • sudo apt-get install sendmail
16) Restart Apache
  • sudo /etc/init.d/apache2 restart
17) Install Locales (used in unit tests)
  • sudo locale-gen es_ES (Spanish)
  • sudo locale-gen de_DE (German)
  • sudo locale-gen fr_FR (French)
18) Give Apache Write Privileges
  • sudo chown -R jhahn.www-data AgilePHP
19) Update AgilePHP/build.properties
  • locate phpunit-frames.xsl (note directory)
  • phpunit.styles.dir=(path to directory noted above)
20) Phing/AgilePHP Bug Fix

phing/Phing.php
line 1016 $pieces = explode(DIRECTORY_SEPARATOR, $path);
line 1017 $class = preg_replace('/\.php/', '', array_pop($pieces));
line 1018 if(class_exists($class, false)) return;

21) Build the project
jhahn@xenia:/storage/Apps/eclipse-galileo/workspace/AgilePHP$ phing

Buildfile: /storage/Apps/eclipse-galileo/workspace/AgilePHP/build.xml
[property] Loading /storage/Apps/eclipse-galileo/workspace/AgilePHP/build.properties

AgilePHP Framework > delete-logs:

[delete] Deleting /storage/Apps/eclipse-galileo/workspace/AgilePHP/test/logs/agilephp_07-05-10.log
[delete] Deleting directory /storage/Apps/eclipse-galileo/workspace/AgilePHP/test/logs
[delete] Deleting directory /storage/Apps/eclipse-galileo/workspace/AgilePHP/studio/logs
[mkdir] Created dir: /storage/Apps/eclipse-galileo/workspace/AgilePHP/test/logs
[mkdir] Created dir: /storage/Apps/eclipse-galileo/workspace/AgilePHP/studio/logs
[chmod] Changed file mode on '/storage/Apps/eclipse-galileo/workspace/AgilePHP/test/logs' to 777
[chmod] Changed file mode on '/storage/Apps/eclipse-galileo/workspace/AgilePHP/studio/logs' to 777

AgilePHP Framework > clean:

[delete] Deleting directory /storage/Apps/eclipse-galileo/workspace/AgilePHP/build

AgilePHP Framework > test:

[mkdir] Created dir: /storage/Apps/eclipse-galileo/workspace/AgilePHP/build/reports/phpunit
[mkdir] Created dir: /storage/Apps/eclipse-galileo/workspace/AgilePHP/build/reports/phpunit/tests
[mkdir] Created dir: /storage/Apps/eclipse-galileo/workspace/AgilePHP/build/reports/phpunit/coverage
[coverage-setup] Setting up coverage database for 124 files
localhost[8404]: [6] localhost 07-05-10 2:22:05pm / info 2010-07-05T14:22:05-04:00
localhost[8404]: [4] localhost 07-05-10 2:22:05pm / warn 2010-07-05T14:22:05-04:00
localhost[8404]: [3] localhost 07-05-10 2:22:05pm / error 2010-07-05T14:22:05-04:00
localhost[8404]: [7] localhost 07-05-10 2:22:05pm / debug 2010-07-05T14:22:05-04:00
[phpunit] Tests run: 111, Failures: 0, Errors: 0, Incomplete: 0, Skipped: 0, Time elapsed: 103,57901 s
[coverage-report] Transforming coverage report

AgilePHP Framework > main:

// lots of ouput not included

BUILD FINISHED

Total time: 2 minutes 57,44 seconds

Monday, June 7, 2010

Lost sleep over REST

AgilePHP now supports multi-mime data exchange with automatic content negotiation. What an interesting component to build and lessons learned. REST is a cool technology, but all in all, I think far too much is left up to the interpretor (for example, which is the "right" way of creating and updating? POST = create, PUT = update or is it PUT = create or POST = update? Does it depend on who you talk to or the article you read? What is the "right way to read the data? From form variables or the body of the message?

The "AgilePHP way" of RESTing is to use POST to create and PUT to update. Send data using the body of the message, not using form variables. Thanks to JBoss Seam, RESTEasy and my buddy Warren for inspiration along the way.

The automatic content negotiation and data transformations made a great final touch. Minimal code to produce a very functional, secure and robust web service api.


/**
* AgilePHP Framework :: The Rapid "for developers" PHP5 framework
* Copyright (C) 2009-2010 Make A Byte, inc
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* @package com.makeabyte.agilephp.test.control
*/

/**
* Demonstrates the ability to make a simple, secure rest style web service using
* the MVC and REST framework components. Note this class can be used as a standard
* PHP class or a DAO for example, in conjunction with being a REST service, due to
* the Aspect Oriented Programming style using interceptors and annotations.
*
* @author Jeremy Hahn
* @copyright Make A Byte, inc
* @package com.makeabyte.agilephp.test.control
*/
#@BasicAuthentication
#@RestService
class users extends BaseController {

#@GET
public function index() {

return ORM::find( new User() );
}

#@GET
#@Path( resource = '/{username}' )
#@ProduceMime( type = 'application/xml' )
public function getUser( $username ) {

$user = new User();
$user->setUsername( $username );

return $user;
}

#@GET
#@Path( resource = '/{username}/role' )
public function getRole( $username ) {

$user = new User();
$user->setUsername( $username );

return $user->getRole();
}

#@GET
#@Path( resource = '/{username}/session' )
public function getSession( $username ) {

$user = new User();
$user->setUsername( $username );

return $user->getSession();
}

#@POST
#@Path( resource = '/{username}' )
#@ConsumeMime( type = 'application/xml' )
#@ProduceMime( type = 'application/xml' )
public function createUser( $username, User $user ) {

ORM::persist( $user );
return $user;
}

#@PUT
#@Path( resource = '/{username}' )
#@ConsumeMime( type = 'application/xml' )
#@ProduceMime( type = 'application/xml' )
public function updateUser( $username, User $user ) {

ORM::merge( $user );
return $user;
}

#@PUT
#@Path( resource = '/{username}/json' )
#@ConsumeMime( type = 'application/json' )
#@ProduceMime( type = 'application/json' )
public function updateUserJSON( $username, User $user ) {

ORM::merge( $user );
return $user;
}

#@PUT
#@Path( resource = '/{username}/wildcard' )
public function updateUserWildcard( $username, User $user ) {

ORM::merge( $user );
return $user;
}

#@DELETE
#@Path( resource = '/{username}' )
public function deleteUser( $username ) {

$user = new User();
$user->setUsername( $username );

ORM::delete( $user );
}
}

Happy RESTing

Wednesday, March 31, 2010

Community Activity

AgilePHP now has the support of Open Source Universe. We have a news area, user group, and forum where discussions can take place!

User Group:
http://www.opensourceuniverse.com/groups/groups/professional/agilephp-framework.html

News Space:
http://www.opensourceuniverse.com/agilephp-framework/index.php

Public Forum:
http://www.opensourceuniverse.com/forum-12534.html

I am very excited to see the project growing and taking interest. Your feedback, contributions, and participation in the project are welcome and encouraged!

A WIKI has also been created where documentation can be viewed on installation, configuration, tutorials, and code samples!
http://confluence.makeabyte.com

And last but not least, don't forget to check out the apidoc, the most valuable tool of all for developers!

http://makeabyte.com/agilephp/apidoc

Saturday, March 13, 2010

AgilePHP Presentation

This presentation describes AgilePHP, a rapid application development framework. For more information, see http://makeabyte.com/products_agilephp.html