Bring a laptop to my ZF2 tutorial at PHPNW11

5th October 2011

If you are attending my ZF2 tutorial at the PHPNW11 conference on Friday, I thought I'd remind you that you may find it useful to bring a laptop.

Ideally, your laptop should be set up with PHP 5.3 and MySQL and a working copy of my ZF1 tutorial. It would be a good idea to have a vhost set up on http://zf2tutorial.localhost or similar. Ability to create additional vhosts may come in handy. The PHP cli tool should also work as you'll need to run some php scripts from the command line.

I'm going to be covering ZF2's autoloader, dependency injector, event manager and then we'll go through the current Mvc prototype. We'll also be doing some exercises if we have time.

I'm looking forward to it and hope you are too!

Day Camp 4 Developers #3: Project Management

31st August 2011

I'm delighted to be able to announce that I'm speaking at the next Day Camp 4 Developers on 1st October.

Day Camp 4 Developers is a one-day online conference run by our friend Cal Evans and is now onto its 3rd outing. An online conference is one that you attend in your own home (or office!) which keeps the costs down considerably, so you have no excuse not to buy a ticket: just $40!

Day Camp 4 Developers is unusual in that it it concentrates on the "soft" skills that a developer needs in order to do their job well. The topic for this Day Camp is Project Management which is something that every developer should have knowledge about. Even if you aren't a project manager yourself, understanding what it is and why it helps is vital for your career development in any team based undertaking.

I'm talking on how we manage projects in my company. The idea is to give you an idea of the things that have to be done in order to take a proposal through to a live website as there's more to it than just writing the code. I've found that now that all of our team here understand the project management side of the job, the whole process goes much more smoothly and more profitably for everyone. Hopefully I'll be able to help you understand what your project managers are doing during their day too!

Setting up PHP & MySQL on OS X 10.7 Lion

25th July 2011

With OS X 10.7, Apple continues to ship PHP 5.3 with PEAR, GD and PDO_MYSQL out of the box. This is how to set it up from a clean install of 10.7.

/usr/local

Ensure that the following directories exist:

sudo mkdir /usr/local/include
sudo mkdir /usr/local/bin
sudo mkdir /usr/local/lib
sudo mkdir -p /usr/local/man/man1

MySQL

  1. Download the 64bit DMG version of MySQL 5.1.x (or 5.5.x) for OS X 10.6 from mysql.com and install the pkg, the startup item and the pref pane.
  2. Add /usr/local/mysql/bin to the path: vim ~/.bash_profile and add:
    export PATH=~/bin:/usr/local/bin:/usr/local/mysql/bin:$PATH
    export EDITOR=vim
    

    at top of file. (Note that we set EDITOR whilst we are here so that svn is happy!)

  3. Set up MySQL root password:
    mysqladmin -u root password {new-password}
    mysqladmin -u root -p{new-password} -h localhost password {new-password}
    mysqladmin -u root -p{new-password} reload
    

    Clear the history file by typing history -c so that {new-password} isn't in plain text on the disk.

  4. Now ensure that the mysql.sock file can be found by PHP:
    1. Ensure that MySQL is running
    2. sudo mkdir /var/mysql
    3. sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Apache

  1. cd /etc/apache2
  2. Give write permission the config file to root: sudo chmod u+w httpd.conf
  3. sudo vim httpd.conf
  4. Find #LoadModule php5_module libexec/apache2/libphp5.so and remove the leading #
  5. Find AllowOverride None within the <Directory "/Library/WebServer/Documents">section and change toAllowOverride All so that .htaccess files will work.
  6. Change permissions back: sudo chmod u-w httpd.conf
  7. Restart Apache by unticking and then ticking again the Web Sharing checkbox in System Preferences -> Sharing
  8. Open Finder and navigate to /Library/WebServer/Documents/ using shift+cmd+g
  9. Create a new folder called "orig" and place all files currently in the Documents folder into it. (note that it will ask for your password as the Documents folder is only writable by root.
  10. Create a new file called info.php with <?php phpinfo(); inside it.
  11. Use Safari to navigate to http://localhost/info.php and check that the PHP version is displayed (5.3.6 at the time of writing).

php.ini

  1. cd /etc
  2. sudo cp php.ini.default php.ini
  3. sudo chmod ug+w php.ini
  4. sudo chgrp admin php.ini
  5. vim php.ini (assuming your user is a member of the admin group) and change settings appropriately. Change:
    error_reporting  =  E_ALL | E_STRICT
    display_errors = On
    html_errors = On
    extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20090626"

    (I like to see my xdebug errors in bright orange!)
    Also, change all instances of /var/mysql/mysql.sock to /tmp/mysql.sock

Xdebug

Can't have a PHP development environment without xdebug! Apple appears to agree as Lion ships with it.

  1. vim /etc/php.ini
  2. Find the line:
    ;zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
    and remove the semicolon at the start
  3. If you want to configure your xdebug settings, then scroll to the end of the file and look for the [xdebug] section. I like these settings:
    xdebug.var_display_max_children = 999
    xdebug.var_display_max_data = 99999
    xdebug.var_display_max_depth = 100
    

    (use with caution…)

  4. Restart apache: sudo apachectl restart and check in the phpinfo that xdebug is now loaded.

PEAR

We need PEAR! For some reason, it's not set up ready to on Lion, but the install phar file is here, so we just need to run it.

  1. cd /usr/lib/php
  2. sudo php install-pear-nozlib.phar
  3. Edit/etc/php.ini and find the line: ;include_path = ".:/php/includes" and change it to:
    include_path = ".:/usr/lib/php/pear"
  4. sudo pear channel-update pear.php.net
  5. sudo pecl channel-update pecl.php.net
  6. sudo pear upgrade-all

PHPUnit and friends

I assume that everyone needs these…

  1. sudo pear channel-discover pear.phpunit.de
  2. sudo pear channel-discover components.ez.no
  3. sudo pear channel-discover pear.symfony-project.com
  4. sudo pear install phpunit/PHPUnit
  5. sudo pear install phpunit/phpcpd
  6. sudo pear install PHP_CodeSniffer

PECL OAuth

A couple of projects I work on use the PECL OAuth component:

  1. Ensure you have installed Xcode from the Mac App Store
  2. Download the latest PCRE source code from http://sourceforge.net/projects/pcre/files/pcre/ and unzip to a folder on your desktop
  3. cd ~/Desktop/pcre-8.12
  4. ./configure
  5. sudo cp pcre.h /usr/include/
  6. Remove the pcre folder on your desktop as you don't need it any more
  7. sudo pecl install oauth
  8. Edit/etc/php.ini add these lines to the end of the file:
    [oauth]
    extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/oauth.so"
  9. Restart apache: sudo apachectl restart and check in the phpinfo that OAuth is now loaded.

mcrypt

This is useful! Follow the installation details by Michale Gracie here: http://michaelgracie.com/2011/07/21/plugging-mcrypt-into-php-on-mac-os-x-lion-10-7/)

It all works on this machine, anyway :)

Other options

If you'd rather use a packaged version, then these are two alternatives:

Zend_Config_Ini and a string

20th June 2011

One thing that is different between Zend_Config_Xml and Zend_Config_Ini is that with Zend_Config_Xml you can pass in an XML string as the first parameter of the constructor and it will work. This doesn't work with Zend_Config_Ini as we use parse_ini_file() under the hood.

With PHP 5.3 however there is is a new function called parse_ini_string() which will allow us to load arbitrary ini string into Zend_Config objects. This can't go into Zend Framework 1 though due to our PHP 5.2.4 minimum version requirement.

As I needed this for a project, I extended Zend_Config_Ini to support this feature, which means simply overloading a single method

class App_Config_Ini extends Zend_Config_Ini
{
    /**
     * Load the INI file from disk using parse_ini_file(). Use a private error
     * handler to convert any loading errors into a Zend_Config_Exception
     *
     * @param string $filename
     * @throws Zend_Config_Exception
     * @return array
     */
    protected function _parseIniFile($filename)
    {
        set_error_handler(array($this'_loadFileErrorHandler'));
        if (substr($filename, -4) == '.ini') {
            $iniArray parse_ini_file($filenametrue);
        } else {        
            $iniArray parse_ini_string($filenametrue);
        }
        restore_error_handler();

        // Check if there was a error while loading file
        if ($this->_loadFileErrorStr !== null) {
            /**
             * @see Zend_Config_Exception
             */
            require_once 'Zend/Config/Exception.php';
            throw new Zend_Config_Exception($this->_loadFileErrorStr);
        }

        return $iniArray;
    }
}

The actual change is to see if the last 4 characters of the filename are ".ini" and if they aren't then use parse_ini_string() instead of parse_ini_file(). The rest of the code is just error handling.

This is one area where I really like it when a class implements methods that done just one thing.

tek11 photos

16th June 2011

Following on from the previous post, these are some of my favourites from php|tek 11.

On the day before tek started, playing mini-golf with Helgi, Ian, Kathy, Rafael & Lorna was fun

Professional at work...

It wouldn't be a trip to Chicago without pizza!

Pizza!

I loved Liz's hat

Liz and her hat

Lig had a two-hands-one-mouth problem...

Red or White?!

The social events at tek are great. You can usually find Liz enjoying the party!

Centre of attention

It was always fun to see groups showing off some cool tech or another to each other. In this case, I think Lorna and Matthew were discussing using LaTeX for presentations

Matthew and Lorna

Jeremy took great pictures too and also posed on the couch

Here's looking at you!

I think the funniest moment of tek11 was when Ian read us excerpts from Page & Didday's Fortran 77 for Humans he found on the shelf at Potbelly's. Lunch will never be the same again.

Ian reads us exercepts from the Fortran book

Looking at this set of photos, you'd think that all we did was party. In fact, I also went to a number of amazing sessions where I learnt stuff, but I was so busy paying attention, I didn't take any photos during those times. I had a great time at both DPC and php|tek this year and if you haven't been to a PHP conference, then I recommend that you go to the next one you can!

The full set of photos is up on Flickr.