Skip to content


Cakephp Skipjack Component

Hi, I just released a new Cakephp component for the Skipjack payment processor provider

I post it on Github with a detailed README file with info about how to implement it…

Hope it helps… Patches welcome! if someone finds a bug? Want a feature? Submit an issue here.

Posted in CakePHP, PHP.

Tagged with , , , .


How to set up Magento on XAMPP with php 5.3 +

Magento still doesn’t support PHP 5.3 (current default PHP env on XAMPP ), therefore this is what I had to do:

First be sure that you have the required setting:

http://www.magentocommerce.com/wiki/general/installing_on_windows_with_xampp_and_wamp

Change in file /lib/Varien/Object.php on line ~ 484

  public function ___toString(array $arrAttributes = array(), $valueSeparator=',')

To this (change ___toString to __invoke

 public function __invoke(array $arrAttributes = array(), $valueSeparator=',')

In file /app/code/core/Mage/Core/Controller/Request/Http.php on line ~ 274

  $host = split(':', $_SERVER['HTTP_HOST']);

to

$host = explode(':', $_SERVER['HTTP_HOST']);

And all split() deprecated warnings change it with explode()

If you can’t login try this:

-Go to app/code/core/Mage/Core/Model/Session/Abstract/Varien.php file within your magento directory.

-Find the code,

session_set_cookie_params(
           $this->getCookie()->getLifetime(),
           $this->getCookie()->getPath(),
           $this->getCookie()->getDomain(),
           $this->getCookie()->isSecure(),
           $this->getCookie()->getHttponly()
       );

-Replace above code by,

session_set_cookie_params(
           $this->getCookie()->getLifetime(),
           $this->getCookie()->getPath()
           //$this->getCookie()->getDomain(),
           //$this->getCookie()->isSecure(),
           //$this->getCookie()->getHttponly()
       );

-Save it and try to login to your magento admin panel.
It would work. :)

If you want to add the sample data:
Download the “media” and SQL dump from here:
http://www.magentocommerce.com/download/noregister

  • Normally web install
  • delete the database, and create new one
  • copy the sample_media_files to magento’s media folder
  • import the sample_sql to your database

Posted in PHP.

Tagged with , .


Flash and xml not working on Cakephp (solution)

I was having some problems with a flash file that requires an external xml file so it can render random data…

Everything was working fine, except when it was in a cake app… long story short,
I found this post about PHP Proxy Script for cross-domain requests  which had everything I needed.

Just put the proxy.php like this in your server:

http://yourserver.com/proxy.php


<?php
// PHP Proxy
// Responds to both HTTP GET and POST requests
//
// Author: Abdul Qabiz
// March 31st, 2006
//

// Get the url of to be proxied
// Is it a POST or a GET?
$url = ($_POST['url']) ? $_POST['url'] : $_GET['url'];
$headers = ($_POST['headers']) ? $_POST['headers'] : $_GET['headers'];
$mimeType =($_POST['mimeType']) ? $_POST['mimeType'] : $_GET['mimeType'];

//Start the Curl session
$session = curl_init($url);

// If it's a POST, put the POST data in the body
if ($_POST['url']) {
	$postvars = '';
	while ($element = current($_POST)) {
		$postvars .= key($_POST).'='.$element.'&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;';
		next($_POST);
	}
	curl_setopt ($session, CURLOPT_POST, true);
	curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}

// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, ($headers == "true") ? true : false);

curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
//curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Make the call
$response = curl_exec($session);

if ($mimeType != "")
{
	// The web service returns XML. Set the Content-Type appropriately
	header("Content-Type: ".$mimeType);
}

echo $response;

curl_close($session);

?>

Go to your action script file and modify your content_xml.load:

  content_xml.load("http://www.yourserver.com/xml/menu.xml");

Finally, in your cake app:


    <!--Valid flash version 8.0-->
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="your width" height="your height" id="your id" accesskey="your accesskey" tabindex="your tabindex" title="your title">
      <param name="movie" value="http://yourserver.com/proxy.php?url=http%3A//someserver.com/swf.swf&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;mimeType=application/x-shockwave-flash" />
      <param name="quality" value="your value" />
      <param name="wmode" value="your value" />
      <param name="swfversion" value="6.0.65.0" />
      <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
      <param name="expressinstall" value="/Scripts/expressInstall.swf" />
      <param name="SCALE" value="your value" />
      <param name="allowScriptAccess" value="your value" />
      <param name="base" value="http://yourserver.com/" />
      <param name="allowNetworking" value="all" />
      <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://yourserver.com/proxy.php?url=http%3A//someserver.com/swf.swf&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;mimeType=application/x-shockwave-flash" width="980" height="325">
        <!--<![endif]-->
        <param name="quality" value="your value" />
        <param name="wmode" value="your value" />
        <param name="swfversion" value="6.0.65.0" />
        <param name="expressinstall" value="/Scripts/expressInstall.swf" />
        <param name="SCALE" value="your value" />
        <param name="allowScriptAccess" value="always" />
        <param name="base" value="http://yourserver.com/" />
        <param name="allowNetworking" value="all" />
        <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
        <div>
          <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
          <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>
        </div>
        <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

Posted in CakePHP, Hacks, PHP, Programming.

Tagged with , , .


Cakephp, phpUnderControl & SimpleTest

Lately I’ve been working with phpUnderControl and I think it’s a very cool project… the problem is that it doesn’t support Simpletest (which is the default test suit for Cake…)

Searching for a solution, I saw this Drupal patch that pretty much let you run simpletest with phpUnderControl on Drupal apps.
So I started hacking on it so it would work on Cake apps… and after a while, I got it work a bit… however, there are still some simpletest configurations requirements that I haven’t been able to figure out…

So, if someone else is interested in running simpletest with phpUnderControl and would like to contribute with some code, I uploaded what I have so far on github…

http://github.com/jpablobr/cakeUnderControl

 

Posted in CakePHP, Git, Hacks, PHP, Programming, Web Development, unit-testing.

Tagged with , , , , , , , .


CURL in XAMPP

There appear to be a lot of misguided people claiming all sorts of things you have to do to get CURL to work on a Windows-based XAMPP install. However it’s really quite simple.

– uncomment extension=php_curl.dll in your php.ini file, then restart Apache1.

NOTE: As of the 1.7.0 release, the php.ini file is found in /xampp/php/php.ini.

Posted in PHP, Programming, Web Development.

Tagged with .


CakePHP API search with Firefox

This is an awesome tip by teknoid:

Some of you might know this, but…

  1. Go here: http://mycroft.mozdev.org/search-engines.html?name=cakephp
  2. Click the “CakePHP API” link (or any other you might think is useful)
  3. Add “CakePHP API” to the list of engines available in the search bar?… Most definitely “Add”
  4. (Sure, let’s try it right away)
  5. Ctrl + K (windows) or similar shortcut for your OS
  6. Type search string, hit “Enter”
  7. See results

Nice!

Posted in CakePHP, PHP, Programming, Web Development.

Tagged with , , .


MySQL; InnoDB and MyISAM

The storage-engine is what will store, handle, and retrieve information for a particular table.

Advantages of InnoDB

  1. InnoDB should be used where data integrity comes a priority because it inherently takes care of them by the help of relationship constraints and transactions.
  2. Faster in write-intensive (inserts, updates) tables because it utilizes row-level locking and only hold up changes to the same row that’s being inserted or updated.

Disadvantages of InnoDB

  1. Because InnoDB has to take care of the different relationships between tables, database administrator and scheme creators have to take more time in designing the data models which are more complex than those of MyISAM.
  2. Consumes more system resources such as RAM. As a matter of fact, it is recommended by many that InnoDB engine be turned off if there’s no substantial need for it after installation of MySQL.
  3. No full-text indexing.

Advantages of MyISAM

  1. Simpler to design and create, thus better for beginners. No worries about the foreign relationships between tables.
  2. Faster than InnoDB on the whole as a result of the simpler structure thus much less costs of server resources.
  3. Full-text indexing.
  4. Especially good for read-intensive (select) tables.

Disadvantages of MyISAM

  1. No data integrity (e.g. relationship constraints) check, which then comes a responsibility and overhead of the database administrators and application developers.
  2. Doesn’t support transactions which is essential in critical data applications such as that of banking.
  3. Slower than InnoDB for tables that are frequently being inserted to or updated, because the entire table is locked for any insert or update.

The comparison is pretty straightforward. InnoDB is more suitable for data critical situations that require frequent inserts and updates. MyISAM, on the other hand, performs better with applications that don’t quite depend on the data integrity and mostly just select and display the data.

Comparison

MyISAM in most cases will be faster than InnoDB for run of the mill sort of work. Selecting, updating and inserting are all very speedy under normal circumstances. It is the default engine chosen by the MySQL development team which speaks to its integrity, reliability, and performance.
InnoDB, or the OSX of the database-engine world, has emerged with some nifty features and created a niche for itself very quickly. Boasting features like row-level locking, transaction-safe queries, and relational table design are all very temping. The first two features really shine in a table that is constantly getting hammered like a logs, or search engine-type table. Since queries happen in the blink of an eye (faster actually) table-level locking(MyISAM) is sufficient in most other normal cases.
InnoDB recovers from a crash or other unexpected shutdown by replaying its logs. MyISAM must fully scan and repair or rebuild any indexes or possibly tables which had been updated but not fully flushed to disk.

REMEMBER!
It’s OK to mix table types in the same database! In fact it’s recommended and frequently required. However, it is important to note that if you are having performance issues when joining the two types, try converting one to the other and see if that fixes it. This issue does not happen often but it has been reported.

Extra Reading

MySQL Performance Blog – Graphically shows how InnoDB overtakes MyISAM at a certain number of queries per second.
MySQL Manual InnoDB Overview – Great overview of capabilities and limitations.
MySQL Manual MyISAM Overview – Same as above
MySQL Manual Storage Engines – Information on the other less-used storage engines MySQL offers.
MySQL – InnoDB vs MyISAM

Posted in Design, Mysql, PHP, Programming, Ruby, SQL, Web Development.

Tagged with , .


Cakephp, display random records

The Controller

We find a random record, and then we reuse the current view action and template.

controllers/posts_controller.php

class PostsController extends AppController {
        var $name = 'Posts';

        function random() {
                $random = $this->Post->find('first',array(
                        'conditions' => array(
                                'Post.active'=>1,
                        ),
                        'order' => 'rand()',
                ));
                $this->view($random['Post']['id']);
                $this->render('view');
        }
}

Posted in CakePHP, PHP, Programming, Web Development.

Tagged with , , .


CakePHP, Controller Action without View

Just add:

$this->autoRender = false;

Plus:

$this->redirect( ‘/’ );

So it will redirect you to a specific view, instead of just displaying a blank page.

Posted in CakePHP, PHP, Programming, Web Development.

Tagged with , , .


CakePHP, Blueprint CSS framework

This is how I include the Blueprint CSS framework in my cake app.

NOTE: In $html->css($path, $attributes), the first argument is the path from app/webroot/css. The second argument is html attributes.

<head>
<?php
echo $html->css(array('blueprint/screen', 'blueprint/ie', 'style'), null, array('media' => 'screen, projection'));
echo $html->css('print', null, array('media' => 'print'));
?>
</head>

Results in:

<link rel="stylesheet" type="text/css" href="/app/css/blueprint/screen.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="/app/css/blueprint/ie.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="/app/css/style.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="/app/css/print.css" media="print" />

Linking JavaScript libraries is very similar.

$jslibraries = array('prototype', 'scriptaculous', 'jquery');

This will link to prototype.js, scriptaculous.js and jquery.js respectively as long as there in app/webroot/js.
Put echo $javascript->link($jslibraries); into the head of your layout and you’re done. You have all three JavaScript libraries at your disposal.

Other good resources:

http://book.cakephp.org

http://anthonygthomas.com

Posted in CakePHP, PHP, Web Development.

Tagged with , , .


How to install phpUnderControl on Windows

First install CruiseControl. (I wrote a post about it.)

 I pretty much followed this tutorial (for linux)...I also wrote a similar post on how to set it up to work But with Git on a linux Unbuntu server.

I will assume that you already have a working PHP environment…

Note:  You will need java jdk,  xdebug installed, very important! Run “php –m” in your command prompt to check if you have the module installed.

For the graphs we need the ezComponents Graph library, so from the command prompt run:

pear channel-discover components.ez.no
pear install -a ezc/Graph

Now we get to phpUnderControl itself:

  pear config-set preferred_state beta
  pear channel-discover pear.phpunit.de
  pear install --alldeps phpunit/phpUnderControl
  

phpUnderControl is still in beta, and by default PEAR does not install components in beta status, so we have to use config-set to make it install.

Now you can Configure CruiseControl for phpUnderControl by running the install script:

Assuming that you have your CruiseControl working installation in C:\CruiseControl you can run the following commands

phpuc install C:\CruiseControl 

Install the example project: (this is very important so you can have a base project)

phpuc example C:\CruiseControl

And that’s about it… Now you can follow the rest of my tutorial on configuring it or the original tutorial…
Cheers!

Note: I had some problems with the path in general since windows uses “\” and the web server uses “/”… considering this slashes issues while troubleshooting could be a time saver!

 

Posted in PHP, Programming, Web Development, unit-testing.

Tagged with , , , , , , .


Migrating from WAMP TO XAMPP Pear issues (2008 server)

I’ve being playing around with the Apache Ant tool and definitely WAMP server was not up to the challenge. I started having several issues with xdebug and Pear features in general… So, I thought about giving a try to XAMPP (which I think that the home page is king of weird… lol, any way…) it comes with much more configuration options… therefore if you” know” what you are doing I think is much better!
Well, firs problem was that I Got the following error on running pear.bat from command.com.

  The PHP_PEAR_INSTALL_DIR is set to  ='c:\wamp\php\php5.2.6'. you need to change the path in the environment  variables or change it in pear.bat file.

I tried deleting the environment variables from my 2008 server System (pretty much the same as vista) & restarted. But no luck!
Then again deleted the environment variables I created and logged off and on my computer…then again ran pear.bat from command.com…now got the initial error again:

C:\Documents and Settings\ Administrator\pear
PHP_PEAR_INSTALL_DIR is not set correctly.
Please fix it using your environment variable or modify
the default value in pear.bat
The current value is:
C:\wamp\bin\php\php5.2.6\pear

go-pear.bat still gives me the same error:

C:\xampp\php>go-pear.bat
ERROR: manifest length read was "1236" should be "678716787"Press any key to continue . . .

Then I tried adding them using DOS SET command, though found that its a temporary command. Then added them through right click “computer” > System > Advanced > Environment variables…

PHP_PEAR_BIN_DIR=C:\xampp\php
PHP_PEAR_INSTALL_DIR=C:\xampp\php\pear
PHP_PEAR_PHP_BIN=C:\xampp\php\.\php.exe

Ran pear.bat….it ran this time w/o any errors & this was the output, which made me realize that the env variables are being taken from some file located elsewhere in the C:\ drive.

C:\Documents and Settings\Administrator\Desktop>pear config-show
CONFIGURATION (CHANNEL PEAR.PHP.NET):
=====================================
Auto-discover new Channels     auto_discover    <not set>
Default Channel                default_channel  pear.php.net
HTTP Proxy Server Address      http_proxy       <not set>
PEAR server [DEPRECATED]       master_server    pear.php.net
Default Channel Mirror         preferred_mirror pear.php.net
Remote Configuration File      remote_config    <not set>
PEAR executables directory     bin_dir          C:\wamp\bin\php\php5.2.6
PEAR documentation directory   doc_dir          C:\wamp\bin\php\php5.2.6\docs
PHP extension directory        ext_dir          C:\xampp\php\ext\
PEAR directory                 php_dir          C:\wamp\bin\php\php5.2.6\pear
PEAR Installer cache directory cache_dir        C:\DOCUME~1\sifar786\LOCALS~1\Te
mp\pear\cache
PEAR configuration file        cfg_dir          C:\wamp\bin\php\php5.2.6\cfg
directory
PEAR data directory            data_dir         C:\wamp\bin\php\php5.2.6\data
PEAR Installer download        download_dir     C:\wamp\bin\php\php5.2.6\tmp
directory
PHP CLI/CGI binary             php_bin          C:\wamp\bin\php\php5.2.6\.\php.e
xe
php.ini location               php_ini          <not set>
PEAR Installer temp directory  temp_dir         C:\wamp\bin\php\php5.2.6\tmp
PEAR test directory            test_dir         C:\wamp\bin\php\php5.2.6\tests
PEAR www files directory       www_dir          C:\wamp\bin\php\php5.2.6\www
Cache TimeToLive               cache_ttl        3600
Preferred Package State        preferred_state  stable
Unix file mask                 umask            0
Debug Log Level                verbose          1
PEAR password (for             password         <not set>
maintainers)
Signature Handling Program     sig_bin          c:\gnupg\gpg.exe
Signature Key Directory        sig_keydir       C:\WINDOWS\pearkeys
Signature Key Id               sig_keyid        <not set>
Package Signature Type         sig_type         gpg
PEAR username (for             username         <not set>
maintainers)
User Configuration File        Filename         C:\WINDOWS\pear.ini
System Configuration File      Filename         C:\WINDOWS\pearsys.ini

Searched and found a pear.ini file in the c:\windows directory & it had the following old paths….

#PEAR_Config 0.9
a:12:{s:15:"preferred_state";s:6:"stable";s:8:"temp_dir";s:28:"C:\wamp\bin\php\php5.2.6\tmp";s:12:"download_dir";s:28:"C:\wamp\bin\php\php5.2.6\tmp";s:7:"bin_dir";s:24:"C:\wamp\bin\php\php5.2.6";s:7:"php_dir";s:29:"C:\wamp\bin\php\php5.2.6\pear";s:7:"doc_dir";s:29:"C:\wamp\bin\php\php5.2.6\docs";s:8:"data_dir";s:29:"C:\wamp\bin\php\php5.2.6\data";s:7:"cfg_dir";s:28:"C:\wamp\bin\php\php5.2.6\cfg";s:7:"www_dir";s:28:"C:\wamp\bin\php\php5.2.6\www";s:8:"test_dir";s:30:"C:\wamp\bin\php\php5.2.6\tests";s:7:"php_bin";s:34:"C:\wamp\bin\php\php5.2.6\.\php.exe";s:10:"__channels";a:2:{s:5:"__uri";a:0:{}s:12:"pecl.php.net";a:0:{}}}

So I deleted all these files outside of my XAMPP directory > restart > and that was it… I can now use pear with out a problem and configure XAMPP however I want to…

Posted in Hacks, PHP, Programming, Web Development.

Tagged with , .


.gitignore file not ignoring files

Initialized Git repo with a .gitignore file that is not ignoring files

Run command:

git rm -r --cached . 

This removes everything from the index, then just run:

git add . 

Commit it:

git commit -m ".gitignore is now working"

Posted in Git, Programming, Web Development.

Tagged with , .


PHP Staging environment for continuous integration part 2

In this second part, I will setup phpUnderControl (using Git for source control) and the installation of all the necessary software… Plus I will make reference to a couple of good tutorials on how to set up a PHP apps to work with Capistrano for deployment.

For the phpUnderControl setup, I pretty much followed this tutorial.

However, I changed some things… such as, using Git instead of SVN and a bit more specific on certain areas that gave me some trouble…

In any decent sized project, the more times you commit code, the bigger the chance is that you will break something. Call it the law of unintended consequences or the butterfly effect, but the fact is that in complex systems, we cannot anticipate all the effects of a change. To deal with this we can either adopt the “release and pay” method of software control, or we can setup systems to help us find the consequences of our actions, so we that can correct them before they become a problem. We usually call these systems Continuous Integration systems.

In this article, we will look at how to set up a Continuous Integration system for PHP using phpUnderControl. After reading this article, you should have a good understanding of the pieces involved in a Continuous Integration system and be able to set up and run your own.

What is Continuous Integration?

Thoroughly explaining Continuous Integration would require an article of its own or possibly a whole book. A good one-sentence definition of Integration is “Delivering a working system”, so Continuous Integration means “Continuously delivering a working system”; after every change made to the code the system can be proven to work.

Obviously, manually deploying and testing a system after every change is a very tedious job; however tedious jobs are what computers are really good at, and Continuous Integration systems are the programs that can do the work for us.

PhpUnderControl?

phpUnderControl is an add-on application for CruiseControl, a Continuous Integration system written in Java. It combines a number of popular PHP development tools like PHPUnit, phpDocumentor and PHP_CodeSniffer.

It can run unit tests, generate the API documentation, check the code for compliance with coding standards, and present you with a web interface to review the results. It can even turn on the lights.

Setting up phpUnderControl

For this tutorial, we will use Ubuntu Server as the reference platform, but the instructions should translate easily to other Linuxes, BSDs or even Windows. You should have a dedicated machine available, but if you don’t, it is possible can also install it on a machine used for other tasks.

As mentioned above, phpUnderControl is an add-on for CruiseControl, which is a Java application, so we install that first:

sudo apt-get install sun-java6-jdk

PHPUnit needs xDebug to generate the code coverage reports:

sudo apt-get install php5-dev php-pear
pear upgrade PEAR

Now install xdebug thru PECL.

sudo pecl install xdebug

Now we need to find where xdebug.so went (the compiled module)

find / -name 'xdebug.so' > /dev/null
/usr/lib/php5/20060613/xdebug.so

Then edit php.ini:

sudo gedit /etc/php/apache2/php.ini

Add the following line:

zend_extension="/usr/lib/php5/20060613/xdebug.so"

Then restart apache for changes to take effect.

You can also, rather than including the xdebug.so extension in your php.ini file, it is probably more appropriate to create an .ini file specifically for this extension in /etc/php5/conf.d/xdebug.ini. The file can be as simple as:

; xdebug debugger
zend_extension="/usr/lib/php5/20060613/xdebug.so"

And then to compliment this setup, add any xdebug configuration directives to this file as well.

This has two benifits:

  • 1. It will be automatically included by both cli php5 and apache2 php5
  • 2. It will persist regardless of what happens with your php setup.

If your main php.ini file gets changed or modified by some automated process, you don’t risk losing your xdebug setup stuff.

sudo /etc/init.d/apache2 restart

Check phpinfo() to make sure the extension is loaded correctly.

The following line should have been appended to the copyright lines:

with Xdebug v2.0.0, Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, by Derick Rethans

For more information about xdebug configuration and usage, please read the official documentation, found here: http://xdebug.org/docs/

For PHPUnit, PEAR is the recommended way to install it:

This also installs the php5-cli package which you need to run PHPUnit.

For the graphs we need the ezComponents Graph library:

sudo pear channel-discover components.ez.no
sudo pear install -a ezc/Graph

Now we get to phpUnderControl itself:

sudo pear config-set preferred_state beta
sudo pear channel-discover pear.phpunit.de
sudo pear install --alldeps phpunit/phpUnderControl

phpUnderControl is still in beta, and by default PEAR does not install components in beta status, so we have to use config-set to make it install.

And, of course, cruisecontrol itself.

To unzip the file we need unzip:

sudo apt-get install unzip

Now we can install CruiseControl:

sudo unzip cruisecontrol-bin-2.8.2.zip -d /opt

To make it easy to upgrade add a link to the current version:

sudo ln -s /opt/cruisecontrol-bin-2.8.2 /opt/cruisecontrol

Configure CruiseControl for phpUnderControl by running the install script:

sudo phpuc install /opt/cruisecontrol

Install the example project:

sudo phpuc example /opt/cruisecontrol

To start, CruiseControl needs the JAVA_HOME variable set. To set it add the lone below to your /etc/environment.

JAVA_HOME="/usr/lib/jvm/java-6-sun"

Additionally, to set JAVA_HOME in your current shell, execute the following command.

JAVA_HOME="/usr/lib/jvm/java-6-sun";export JAVA_HOME

We are now ready to start CruiseControl:

cd /opt/cruisecontrol
sudo -E ./cruisecontrol.sh

If you use the -E option, you retain your own environment variables. You need the JAVA_HOME for cruisecontrol.sh to work properly. You can also run cruisecontrol.sh as a regular user, but then you have to make sure you own the whole CruiseControl tree: (Don’t do this while CruiseControl is still running.)

sudo chown -LR user:user /opt/cruisecontrol

The -R option makes the command recursive. This ensures that the ownership of the link is changed along with all files beneath it. The -L options ensures that if there are symbolic links to directories that they are traversed also.

Configuring phpUnderControl for a sample project.

We can now fire up a browser and go to http://[ip-address of ci server]:8080/cruisecontrol and it should show something like this:

Don’t worry if you see error messages in the ‘coverage’ and ‘metrics’ tags about missing files in the ‘artifacts’ directory. The configuration of the installed example project is not quite correct. You can find a fix here.
We can now stop CruiseControl with:

kill `cat /opt/cruisecontrol/cc.pid`

Setting up a new project

Now you’re ready to set up a new project. In this example I will assume that you already have a working Git project which you can clone… after following the previous tutorial about Gitosis, most likely your project repo is in /home/git/repositories/. For this example we will call this project ‘my_project’.

If you already have a project with some PHPUnit tests perfect, use that! if not, copy this two files in your "my_project" directory

Calculator.php:

<?php
Class Calculator
{
  public static function Add($a, $b)
  {
    return $a + $b;
  }
}

CalculatorTest.php:

<?php

require_once 'PHPUnit/Framework.php';
include 'Calculator.php';

class CalculatorTest extends PHPUnit_Framework_Testcase
{
  public function testAdd()
  {
    $this->assertEquals(3, Calculator::Add(1,2));
  }
}

In order to add a new project to CruiseControl you have to do three main things:

  • Create a project configuration.
  • Set up a directory structure.
  • Add the project to the main configuration.

Cruisecontrol projects live in the subdirectory projects/ in the cruisecontrol/ directory, so the first step is to create a project directory:

cd /opt/cruisecontrol/projects
mkdir my_project
cd my_project

Then make a build.xml file there with the following content:

[/source]

The structure of a project section of build.xml is always the same, a target element with a name attribute that contains an exec element.

 <project>
  ...
  <target>
   <exec>
    <arg/>
   </exec>
  </target>
  ...
 </project>

The exec element has an executable attribute that points to the program to run and a dir attribute that determines the directory in which the program is executed. Within the exec element is an arg element that holds the command line argument.

So the checkout tagged in the exec element below

<exec executable="git" dir="${basedir}/source">
  <arg line="pull" />
</exec>

is equivalent to:

cd my_project/source
git pull 

A detailed description of the build.xml file can be found here.

This file lists all the steps needed to get a working system to test. Each step is called a ‘target’, and a target can depend on other targets to be finished before they can be executed.
The first step is to update the code:

<?xml version="1.0" encoding="UTF-8"?>
<project name="my_project" basedir=".">
  <target name="checkout">
    <exec executable="git" dir="${basedir}/source">
      <arg line="pull" />
    </exec>
  </target>
</project>

This will run ‘git pull’ (similar to ’svn update’) in the projects/my_project/source directory. To get our project files there, we need to a checkout first:

Git clone /home/git/repositories/my_project.git/  /opt/cruisecontrol/projects/my_project/source

You can now test your build.xml file:

../../apache-ant-1.7.0/bin/ant checkout

Ant is the program that actually runs the builds. The output should look like

this:  </p>

 checkout:
    [exec] At revision 1.

 BUILD SUCCESSFUL
 Total time: 1 second

Now we can add the other targets:

PhpDocumentor:

 <target name="php-documentor">
  <exec executable="phpdoc" dir="${basedir}/source">
   <arg line="-ct type -ue on -t ${basedir}/build/api
         -tb /usr/share/php/data/phpUnderControl/data/phpdoc
         -o HTML:Phpuc:phpuc -d ."/>
  </exec>
 </target>

An explanation for the various arguments can be found by typing

phpdoc -h 

The -tb argument makes sure phpdoc uses a template that looks good with phpUnderControl. Phpdoc stores its output in the build/api directory, which you will have to create manually in the my_project/ directory.

mkdir -p build/api

And as with the checkout target, you can check if it is correct by using Ant again:

../../apache-ant-1.7.0/bin/ant php-documentor

PHPUnit:

<target name="phpunit">
  <exec executable="phpunit" dir="${basedir}/source" failonerror="on">
    <arg line="--log-xml ${basedir}/build/logs/phpunit.xml
          --log-pmd ${basedir}/build/logs/phpunit.pmd.xml
          --log-metrics ${basedir}/build/logs/phpunit.metrics.xml
          --coverage-xml ${basedir}/build/logs/phpunit.coverage.xml
          --coverage-html ${basedir}/build/coverage
          CalculatorTest.php" />
  </exec>
</target>

This target puts its output in build/logs and build/coverage, which also have to be created manually:

mkdir -p build/logs build/coverage

The failonerror=on is needed to signal a failed build when phpunit returns an error. (It returns an error whenever it detects failed test). The command line arguments for PHPUnit are covered extensively in the PHPUnit documentation.

PhpCodeSniffer:

<target name="php-codesniffer">
  <exec executable="phpcs"
     dir="${basedir}/source"
     output="${basedir}/build/logs/checkstyle.xml">
    <arg line="--report=checkstyle
          --standard=PEAR
      ."/>
  </exec>
</target>

The command line arguments are documented in the php-codesniffer manual. A particularly useful parameter is –ignore, which gives you the option to ignore certain files when sniffing the code. Very useful if you have included external code which does not comply to your standards.

Putting the build.xml file together

Now we need to combine the targets to one target

 <target name="build" depends="checkout,php-documentor,php-codesniffer,phpunit" />

And to make sure the build target is the default target, we add the default attribute:

<project name="my_project" default="build" basedir=".">

The final build.xml file should look like this:

 <?xml version="1.0" encoding="UTF-8"?>
 <project name="my_project" default="build" basedir=".">
 <target name="build" depends="checkout,php-documentor,php-codesniffer,phpunit" />

 <target name="checkout">
 <exec executable="git" dir="${basedir}/source">
  <arg line="pull" />
 </exec>
 </target>

 <target name="php-documentor">
 <exec executable="phpdoc" dir="${basedir}/source">
  <arg line="-ct type -ue on -t ${basedir}/build/api
  -tb /usr/share/php/data/phpUnderControl/data/phpdoc
  -o HTML:Phpuc:phpuc -d ."/>
 </exec>
 </target>

 <target name="php-codesniffer">
 <exec executable="phpcs"
  dir="${basedir}/source"
  output="${basedir}/build/logs/checkstyle.xml">
  <arg line="--report=checkstyle
  --standard=PEAR
  ."/>
 </exec>
 </target>

 <target name="phpunit">
 <exec executable="phpunit" dir="${basedir}/source" failonerror="on">
  <arg line="--log-xml ${basedir}/build/logs/phpunit.xml
  --log-pmd ${basedir}/build/logs/phpunit.pmd.xml
  --log-metrics ${basedir}/build/logs/phpunit.metrics.xml
  --coverage-xml ${basedir}/build/logs/phpunit.coverage.xml
  --coverage-html ${basedir}/build/coverage
  CalculatorTest.php" />
 </exec>
 </target>
 </project>

Configuring CruiseControl

The central configuration file for CruiseControl is config.xml, which in our example can be found in /opt/cruisecontrol/config.xml For a detailed overview of the options available for this file, check the Cruisecontrol documentation. I am going to configure our project so that it periodically runs the build, even if nothing has changed.

First, rename the old config.xml file and replace it with an empty config.xml file:

<?xml version="1.0" encoding="UTF-8"?>
  <cruisecontrol>
    <project name="my_project" buildafterfailed="false">

    </project>
  </cruisecontrol>

The buildafterfailed=false attribute tells CruiseControl not to attempt a build if the previous one has failed and no changes have been found. If your tests depend on an external source that can fail, like a SOAP service or a database, it might be useful to set this value to ‘true’.

Then add the modification set:

<modificationset>
  <alwaysbuild/>
</modificationset>

The modificationset element lists the checks to find if anything has changed in the project. In this case we don’t check and always build.

Now we tell CruiseControl what to do:

  <schedule interval="60">
    <ant anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml"/>
  </schedule>

In the schedule element is a list with tasks to do on each build. In this case, run Ant on the build.xml file we just created. The ant element also has an optional target attribute, where you can choose the target to build. The interval attributes specifies how many seconds to wait between builds. To enable the front-end to show the status of the build, we have to add a listener:

<listeners>
  <currentbuildstatuslistener file="logs/${project.name}/status.txt"/>
</listeners>

The listener element holds elements that can communicate the status of the build to other parts of the system. In this case the currentbuildstatus puts the status in an HTML snippet that the CruiseControl webserver can read.

Now we need a place to put all the information gathered during the build process:

<log dir="logs/${project.name}">
  <merge dir="projects/${project.name}/build/logs/"/>
</log>

To publish the results of the build we need a publisher:

 <publishers>
  <artifactspublisher dir="projects/${project.name}/build/api"
            dest="artifacts/${project.name}"
            subdirectory="api"/>
  <artifactspublisher dir="projects/${project.name}/build/coverage"
            dest="artifacts/${project.name}"
            subdirectory="coverage"/>
  <execute command="phpuc graph logs/${project.name}
           artifacts/${project.name}"/>
 </publishers>
 

The two arifactpublishers take the information from the build and puts them in a publicly accessible directory. The first one takes the files from build/api, which holds the api documentation generated by phpDocumentor. The second one is for the code coverage information. The execute element generates the nice-looking graphs for your manager.

The total config.xml file should look like this:

 <?xml version="1.0" encoding="UTF-8"?>
 <cruisecontrol>
 <project name="my_project" buildafterfailed="false">
  <modificationset>
  <alwaysbuild/>
  </modificationset>

  <schedule interval="60">
  <ant anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml"/>
  </schedule>

  <listeners>
  <currentbuildstatuslistener file="logs/${project.name}/status.txt"/>
  </listeners>

  <log dir="logs/${project.name}">
  <merge dir="projects/${project.name}/build/logs/"/>
  </log>

  <publishers>
  <artifactspublisher dir="projects/${project.name}/build/api"
       dest="artifacts/${project.name}"
       subdirectory="api"/>
  <artifactspublisher dir="projects/${project.name}/build/coverage"
       dest="artifacts/${project.name}"
       subdirectory="coverage"/>
  <execute command="phpuc graph logs/${project.name}
       artifacts/${project.name}"/>
  </publishers>
 </project>
 </cruisecontrol>

You can now test your phpUndercontrol system.

To start CruiseControl:

cd /opt/cruisecontrol
./cruisecontrol.sh

And to stop it:

kill `cat /opt/cruisecontrol/cc.pid`

If you start up your browser go to http://[ip-address of ci server]:8080/cruisecontrol And click on the my_project link, you should see something similar to this:

Now we’re going to change the configuration file to only do the build after we have made change in the code.

Here you can find more information about how to use Git with CruiseControl

To enable CruiseControl to check Git we first have to add a plugin to the project:

 <plugin name="git" classname="net.sourceforge.cruisecontrol.sourcecontrols.git" />

And change the modification set:

 <modificationset quietperiod="60">
  <git localWorkingCopy="projects/${project.name}/source/"/>
 </modificationset>

The quietperiod attribute tells CruiseControl to wait with running a build for a minute after the last change to the repository. This gives you the opportunity to commit parts to the code without running the risk of breaking the build while you are still busy committing.

The final config.xml file should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<cruisecontrol>
<project name="my_project" buildafterfailed="true">
  <plugin name="git" classname="net.sourceforge.cruisecontrol.sourcecontrols.GIT" />
  <modificationset>
   <git localWorkingCopy="projects/${project.name}/source/"/>
  </modificationset>
...
...
 

If you now run CruiseControl for a while, you will see that the last build time will not change. When you make a change to the code, commit it and wait for a minute or two, you will see that a new build has been run.

Two nice features

In this section I will briefly describe two of the very many nice features available in CruiseControl, sending out an email when things break, and setting up and tearing down a database.

Sending mails when things break

You can make CruiseControl send an email on build failure by adding a publisher to config.xml:

<publishers>
  <email mailhost="smtp.your.company"
      returnaddress="builder@your.company"
      returnname="My Project Build Status"
      defaultsuffix="@your.company"
      spamwhilebroken="false"
      buildresultsurl="http://[ci server]:8080/cruisecontrol">
    <failure address="you@your.company" reportWhenFixed="true"/>
    <failure address="yourboss@your.company" reportWhenFixed="true"/>
  </email>
 ......
 

This sends out an email to you and your boss when the build breaks and one when it’s fixed.

Setting up a database

CruiseControl can set up and tear down a database for you. Below the set-up of the database. The tear-down is left as an exercise.

Simply add a new target:

<target name="db-create">
  <sql driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost:3306"
     userid="root"
     password="root"
     classpath="/usr/share/java/mysql.jar"
     src="${basedir}/db-create.sql"
     delimiter=";"/>
</target>

And add the target to de dependencies of the build target:

<target name="build" depends="checkout,db-create,php-documentor,php-codesniffer,phpunit" />

This uses the java mysql library, so we have to install that:

sudo apt-get install libmysql-java

To make the target work you also have to add a db-create.sql file to your project. I used this for the example:

DROP DATABASE IF EXISTS my_project;
CREATE DATABASE my_project;

And you can check if it is working by calling the target from Ant:

../../apache-ant-1.7.0/bin/ant db-create

In this example we hardcode the classpath in the target, but you can also add the CLASSPATH environment variable.

See the MySQL documentation for details.

This is how the phpUnderControl admin dashboard looks like, very nice!

phpUnderControl

You now have a working Continuous Integration system. Systems like this always take time to get setup and working properly. Now however, you have a powerful tool that will help you create better software faster. The return on investment in your time will be stable code and your client’s confidence in your work. Go and play around with phpUnderControl and discover more of its features and uses; spend the time to understand the system and customize it for your specific needs. The time you spend will be well worth it when you go to roll your next version into production.

If you are interested in Continuous Integration and want to read more about it, Continuous Integration by Paul M. Duval is a very good book on the subject.

More resources:

Last, but not least, Capistrano…

Now we can install Capistrano for our apps deployments… It is fairly simple; you can follow this couple of how-tos to get up and running!

Posted in CakePHP, Git, Linux, PHP, Programming, Web Development, unit-testing.

Tagged with , , , , , , , , .


PHP Staging environment for continuous integration part 1

  • Ubuntu server: for the OS & Git (Part 1)
    1. Ubuntu server
    2. Git (Gitosis for users admin)
    3. Apache2, PHP (5 & 4) & MySql
    4. PhpMyadmin
    5. Cakephp configuration
  • phpUnderControl: for source controls (Git), custom continuous builds, notifications schemes, documentation, code sniffing, etc… Plus Capistrano: for deployment …(Part 2)

Ubuntu server configuration: (Ubuntu Jaunty Jackalope (Ubuntu 9.04))

Most of the how-to is a compilation from various how-to’s I used… (Check them for further reference)
First, I pretty much follow this tut till page # 3:

The Perfect Server – Ubuntu Jaunty Jackalope (Ubuntu 9.04)

Installing Git

Now that we have a fairly simple and stable environment I prefer to configure Git and the SSH requires just in case something goes wrong it wouldn’t be such a pain to reinstall everything…
I pretty much only installed openssh-server and set up the keys so I don’t need to use password authentication (which is a requirement for Git). Don’t continue if you don’t have this set up because that’s why I was talking about reinstalling the whole thing again…

I also wrote on this previews post, a how-to about how to set up RSA key authentication in Eclipse or Aptana IDE

However, here are some good resources for SSH:

This is the best tutorial I’ve found so far, and it has very good links references…

Installing Git on a server (Ubuntu or Debian)

Step 1: Install Git. You’ll have to do this ON BOTH YOUR SERVER AND LOCAL MACHINE. If you’re running a different OS for your client find and check out instructions for installing git on that OS instead. See this link for OS X if you don’t have Mac Ports.

sudo  apt-get update
sudo  apt-get dist-upgrade
sudo  apt-get install git-core

Step 2: Set up the server. We’ll have to do some work on the server. We’re going to use Gitosis which needs python and a python setup tool to get running. Grabbing the python setup tool in Debian/Ubuntu will grab all the requirements if you don’t already have them:

sudo  apt-get install python-setuptools

Step 3: Gitosis. Now it’s time to get Gitosis. For the most part I followed the instructions on scie.nti.st, so full credit and many thanks to them. Once you’re done with my instructions, I recommend you go visit them and read more details on adding users and some other advanced topics.
From your home directory on your server, create a new directory called src, and from there grab the gitosis code.

mkdir  ~/src
cd  ~/src
git  clone git://eagain.net/gitosis.git

Install it using the python setup tool we grabbed earlier.

cd  gitosis
  sudo  python setup.py install

Step 4: Setup some security. We’re next going to add a new user called git. This is the guy that will do all the heavy lifting for us!

sudo  adduser \
  --system \
  --shell /bin/sh \
  --gecos 'git version control' \
  --group
  --disabled-password \
  --home /home/git \
  git

IMPORTANT: If you have locked down ssh, don’t forget to go into your /etc/ssh/ssh_config file and add git to the list of Allowed Users that can login. That list of users is separated by a space not a comma.
I always encourage the use of public/private key exchange and in the case of gitosis it looks to be required. Generate a key if you haven’t already. See instructions for public/private key here. I’m going to assume that from this point on you can access your server from your local machine using a public key exchange!
Next, copy your id_rsa.pub file over to your server somewhere (in our example we’re using /tmp) and then run this command:

sudo  -H -u git gitosis-init < /tmp/id_rsa.pub

You’ll see output like this:

Initialized  empty Git repository in ./<br />
  Initialized  empty Git repository in .//source]<br />

  Others have reported seeing that 3  times but when I did it on Ubuntu Hardy Heron I only saw it twice.<br />
  <strong>Step 5: Minor permissions tweak.</strong> Just in case, let's make sure permissions are set  correctly: <br />

  [source='bash']sudo  chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

We’re now done with the server config! From your local machine, test it out with this:

git  clone git@YOUR_SERVER:gitosis-admin.git

If all went well you have a gitosis-admin directory with a gitosis.conf file and keydir directory. We’re basically setup now. We just need to create a new repository and push it to the server.

Also, as promised here are some resources: (I added a couple more)

Now we can continue with the rest of the system configuration.

Set system locale:

sudo locale-gen en_US.UTF-8
sudo /usr/sbin/update-locale LANG=en_US.UTF-8

Install PHP with php client and without apache (one long line):

 sudo aptitude -y install php5-common php5-dev php5-mysql php5-sqlite php5-tidy  php5-xmlrpc php5-xsl php5-cgi php5-mcrypt php5-curl php5-gd php5-memcache  php5-mhash php5-pspell php5-snmp php5-sqlite libmagick9-dev php5-cli

Fix issues with imagick:

sudo aptitude -y install make php-pear
sudo pecl install imagick

(Just press <ENTER> at prompt)

Adjust php.ini memory limit:

 sudo vim /etc/php5/cgi/php.ini

Find line:

memory_limit = 16M and change it to: memory_limit = 48M

Append to the end of this file this line:

extension=imagick.so

For installing Apache2, PHP (5 & 4) & MySql check this tut

After the MySql install

mysql-server libapache2-mod-auth-mysql php5-mysql

I like to run

mysql_secure_installation

Phpmyadmin and mysql-admin

PhpMyAdmin is a very famous MySQL management software package. To use it you should install and configure PHP, Apache and php mysql (or mysqli) extension see ApacheMySQLPHP for instructions.

Install phpMyAdmin From Package
(source)

Install phpMyAdmin from the Universe repository see InstallingSoftware for detailed instructions on using repositories and package managers.

From console:

sudo apt-get install phpmyadmin

  • If you’re using Ubuntu 7.10 (Gutsy) or later select Apache2 from the "Configuring phpmyadmin" dialog box.

To set up under Apache all you need to do is include the following line in /etc/apache2/apache2.conf.

Include /etc/phpmyadmin/apache.conf

  • If you are using Ubuntu 9.04 (Jaunty), there is no need to modify /etc/apache2/apache2.conf as the package installer already copied the file phpmyadmin.conf into /etc/apache2/conf.d directory. You can also skip the set up step and go directly to http://<hostname>/phpmyadmin and login with the user and password you set up during install.

Once phpMyAdmin is installed point your browser to http://localhost/phpmyadmin to start using it. You should be able to login using any users you’ve setup in MySQL. If no users have been setup, use admin with no password to login.

Should you get a 404 "Not Found" error when you point your browser to the location of phpMyAdmin (such as: http://localhost/phpmyadmin) this is likely caused by not checking the ‘Apache 2′ selection during installation. To redo the installation run the following:

sudo dpkg-reconfigure -plow phpmyadmin

Then select Apache 2 for the webserver you wish to configure.

If this does not work, then you can do the following to include the phpMyadmin-shipped Apache configuration into Apache:

sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
sudo /etc/init.d/apache2 reload

Troubleshooting Phpmyadmin & mysql-admin

If you get blowfish_secret error: Choose and set a phrase for cryptography in the file /etc/phpmyadmin/blowfish_secret.inc.php and copy the line (not the php tags) into the file /etc/phpmyadmin/config.inc.php or you will receive an error.

If you get a 404 error upon visiting http://localhost/phpmyadmin: You will need to configure apache2.conf to work with Phpmyadmin.

sudo vim /etc/apache2/apache2.conf

Include the following line at the bottom of the file, save and quit.

Include  /etc/phpmyadmin/apache.conf

These are the steps I followed in order to get cakephp working on my user public_html folder. (Source)
as many of you probably know, if you have apache’s userdir module loaded, you can put your web pages on /home/user/public_html , and access them with the url: http://localhost/~user/ . I really prefer this, so all my web pages are on my personal home, but how to configure cakephp to work with these paths, i got a hard time with this, but finally got it!. here’s how:

In case you don’t have apache2’s userdir module:

sudo ln -s /etc/apache2/mods-available/userdir.load /etc/apache2/mods-enabled/userdir.load
sudo ln -s /etc/apache2/mods-available/userdir.conf  /etc/apache2/mods-enabled/userdir.conf

You need the rewrite module also… (this could be done with the same method used for userdir)

sudo a2enmod rewrite

Now lets edit some apache files…

sudo vim  /etc/apache2/sites-enabled/mysite

Inside the first two <directory></directory> tags, change the AllowOverride lines:

	<Directory />
        Options FollowSymLinks
        AllowOverride All // change here
    </Directory>

    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All // change here
        Order allow,deny
        allow from all
        # This directive allows us to have apache2's default start page
        # in /apache2-default/, but still have / go to the right place
        #RedirectMatch ^/$ /apache2-default/
	</Directory>

Do the same on /etc/apache2/mods-enabled/userdir.conf

<Directory /home/*/public_html>
                AllowOverride All        // change here
                Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
  </Directory>

Now you need to restart you apache2 server…<

sudo  /etc/init.d/apache2 restart

I’ll assume you’ve already downloaded cakephp latest release or that you know where you can find it

Unpack the downloaded file in /home/user/public_html/
rename the extracted folder (thats the name of your application)

cd /home/user/public_html/application_name

edit the .htaccess file so it look like these:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
   RewriteBase  /~user/application_name/
</IfModule>

now point your browser to http://localhost/~user/application_name and you show see cakephp’s default page

Here you can find the second part of this how-to…

Posted in CakePHP, Git, Linux, PHP, Programming, Web Development, unit-testing.

Tagged with , , , , , , , , .


Git, Unable to create temporary sha1 filename ./objects/xx: File exists

Try run "git fsck" for any errors, and use "git prune", "git repack" to fix it. 

If none of that helps,

chown -R git:git /path/to/git/user/home

That did the trick for me…

Also this could help

Posted in Git, Hacks, Linux, Programming, Web Development.

Tagged with , .


How to set up CruiseControl on windows

Here the steps I have followed in order to install and run cruisecontrolas a windows service.

  1. Download cruisecontrol. I used the version 2.6.2 windows installer.
  2. Run the installer and check the windows service box.
  3. You should read the message: "wrapper | CruiseControl Service installed."
  4. Try to open a browser at the url: http://localhost:8180
  5. If you see the normal screen of cruisecontrol you have been lucky (not like me) and you are done!.
  6. …Otherwise…If you see an error like 500 code open thewrapper.log under the log folder. Check for a message like:

Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.

proceed with the following item.

  1. Copy the file tools.jar to <JAVA_HOME>\jre\lib\ext folder. I found this solution here.
  2. Restart the service, it should be works.
  3. If still doesn’t work… copy the tools.jar also under the folder/lib/ext

Posted in CakePHP, PHP, Programming, Web Development.

Tagged with , , , .


Talks Gordon Brown: Wiring a web for global good

We’re at a unique moment in history, says UK Prime Minister Gordon Brown: we can use today’s interconnectedness to develop our shared global ethic — and work together to confront the challenges of poverty, security, climate change and the economy

Posted in Uncategorized.


Integration of phpDocumentor into Eclipse or Aptana IDE

You can execute phpDocumentor directly from Aptana or Eclipse. The project you would like to document needs to be open.

1. Open the ‘External Tools’ Dialog through ‘Run -> External Tools -> External Tools…’

2. Click the ‘New’ button and enter the following data:

Name: You can give any name, such as ‘phpDocumentor’.

Location: Path to your php.exe file including the file name ‘php.exe’.

Working Directory: Path to your phpDocumentor installation directory.

Arguments: Enter any parameter according to the phpDocumentor manual. At least the parameters -d, -t und -o have to be set. -d <PathSource> stands for the directory or files you want to document, whereas -t <PathTarget> should lead to the directory where the documentation should be stored. The parameter -o sets the template you want to use.

Important: All paths used in arguments containing spaces need to be enclosed in double-quotes.

Posted in CakePHP, PHP, Web Development.

Tagged with , , .


How to build PHP documentation with phpDocumentor

You can build the project documentation using the command-line script phpdoc, or a Web-based interface. To begin, download the latest version of PHPDocumentor from the website, extracting it to a protected area of your web document root. Then navigate to the index.html file located in the PhpDocumentor directory. You’ll see several tabs at the top of the interface, including IntroductionConfigFilesOutputOptionsCredit, and Links. Feel free to browse each tab to get an idea of their purpose, however for the purposes of this example you’ll need to be concerned with only the Files and Output tabs. Navigate to the Files tab, depicted in Figure 1.

The Files Tab
Figure 1. The Files Tab

Note that you can specify input files in four manner: by file, by directory, files to ignore, and by package. I’ve added the directory containing the sample1.php and sample2.php files. Next click on the Output tab, depicted in Figure 2.

The Output Tab
Figure 2. The Output Tab

The Target field is used to specify the documentation destination directory. The Output type dropdown lists the variety of templates and documentation types available to you. Throughout this tutorial I’ve usedHTML:Smarty:default. Feel free to experiment with other formats. Add a target directory and press the create button located to the lower-right of the window. You can scroll through the output appearing in the lower frame to review PHPDocumentor’s actions. Assuming all goes okay, the output will conclude with "Operation Completed!!". Review your documentation by navigating to the target folder.

Posted in CakePHP, PHP, Programming, Web Development.




Fork me on GitHub