development
MAMP PRO, PECL, SSH2, and OSX CLI (AKA acronym madness)
by chance on Nov.08, 2011, under development, php, tutorial
Or madness in general. So as you may know, I've started using PHPStorm to work locally. I decided to dust off an old SSH2 wrapper I wrote and play with how PHPStorm uses PHPUnit and does refactoring. I knew that I would have to install the extension via PECL and was like, "Oh it can't be that bad to do it through MAMP PRO" and as you may have guessed, I sealed my own fate for a couple hours. One thing I can say is that, even though I use a convenient app like MAMP PRO to set up my local development environment, I'm glad my sysadmin-fu is up to snuff enough to fly without the conveniences because after this ordeal, I feel like I might as well have made my MAMP stack from scratch with all the hoops I jumped tonight. (I'm pretty sure that last sentence is also one of the worst run-on sentences ever).
The first thing you need to know is that the PECL command is located at the directory
/Applications/MAMP/bin/php/php5.3.6/bin
when I tried to run
sudo ./pecl install -a ssh2 channel://pecl.php.net/ssh2-0.11.3
from that directory, I got the error:
Notice: unserialize(): Error at offset 267 of 1133 bytes in Config.php on line 1050 PHP Notice: unserialize(): Error at offset 267 of 1133 bytes in /Applications/MAMP/bin/php/php5.3.6/lib/php/PEAR/Config.php on line 1050 ERROR: The default config file is not a valid config file or is corrupted.
I found out later that the error is most likely caused by the file
/Applications/MAMP/bin/php/php5.3.6/conf/pear.conf
So if you get an error, try doing
sudo mv /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf.bkp
If you're still getting the error, you can also the following:
- Install Xcode Tools from your Mac OS X DVD or download it from Apple Developer Connection
- Download the complete PHP source code from php.net into /Applications/MAMP/bin/php/php5.3.6/
- Create an include directory in the the php5.3.6 directory.
- Unzip/tar the php source archive and move it to/Applications/MAMP/bin/php/php5.3.6/include/
- Rename the php source directory to just php (so then it will look like /Applications/MAMP/bin/php/php5.3.6/include/php)
- In Terminal use the following commands to compile the extension:
cd /Applications/MAMP/bin/php/php5.3.6/include/php
./configure
That should allow you to run the PECL command however, you will probably get a complaint about not having libssh installed. So you will have to
- go download libssh2 (http://www.libssh2.org/). As much as I like git, I recommend downloading the latest release tarball instead of cloning the repo. For some reason, I got a version incompatibility error when trying to run the PECL install with the repo version and had to do all these steps over with the tarball release version.
- unzip the directory and cd to the upacked directory in the terminal.
- run: ./configure; make all install;
libssh should compile and place the output file in src/*.o - copy all headers from the include folder within the libssh2 directory to
/usr/local/include/ - copy all compiled files (*.o) from the src folder within the libssh2
directory to /usr/local/lib/
After you've successfully ran the the PECL install, it should tell you to Add the line
extension=ssh2.so
to the Dynamic Extensions area of your php.ini file. I believe both MAMP and MAMP PRO allow you to edit the necessary ini through File>Edit Template.
Lastly, restart apache. You should be able to see the SSH2 extension when you load a phpinfo() page.
Bonus round:
I'm not sure how I have PHP CLI working in OSX but if you've followed the steps above and try to verify the extension install with through the cli, it won't show up.
$ php -a
php> phpinfo();
This is because (if you're also using MAMP PRO) the binaries are different. The good news is that you can make things happy in 3 easy steps
- run `sudo ln -s /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/ssh2.so /usr/lib/php/extensions/no-debug-non-zts-20090626/ssh2.so` in the terminal.
- Edit the /etc/php.ini (copy /etc/php.ini.default if /etc/php.ini doesn't exist) like you did for the MAMP php.ini(s)
- profit.
Note: I still have to install PHPUnit into my current setup so that may or may not elicit another blog post.
Sources:
- http://smbjorklund.no/how-enable-pecl-uploadprogress-extention-mamp
- http://php.net/manual/en/ref.ssh2.php
- http://forum.mamp.info/viewtopic.php?t=13815
Related articles
- Using MySQL Workbench with MAMP (phpprotip.com)
Magento Extension GitIgnore Stub
by chance on Oct.24, 2011, under development, Magento, php
As you may or may not know, I've been working with Magento lately. In the past few months, one thing I've found that I needed is a stock .gitignore file for when making extensions. Haven't found one so I made one on github and will also post here for anyone else in need. I'm still relatively new at working with Magento and in someways git/github so please feel free to critique/streamline.
# replace {company} and {extension} placeholders with your information
# ignore phpstorm files
/.idea
# Ignore all not in app & skin
/*
!/app/
!/js/
# ignore all in js, except module files for this module
/js/*
!/js/{company}/
# Ignore all in app, except code & etc
# Ignore all in app/code except /local/{company}
/app/*
!/app/code/
!/app/etc/
!/app/design/
# Ignore all in app/code/local except {company}
/app/code/core
/app/code/community
/app/code/local/*
!app/code/local/{company}/
# use lines below if you have multiple company extensions
# and want to just commit a specific one
#/app/code/local/{company}/*
#!app/code/local/{company}/{extension}
# Ignore all of app/etc except our specific module files
/app/etc/*
!/app/etc/modules/
/app/etc/modules/*
!/app/etc/modules/{company}_{package}.xml
#Ignore all of app/design except for our files
/app/design/*
!app/design/frontend/
!app/design/adminhtml/
/app/design/frontend/*
!/app/design/frontend/base/
/app/design/frontend/base/default/etc/
/app/design/frontend/base/default/template/*
!/app/design/frontend/base/default/template/{extension}/
/app/design/frontend/base/default/layout/*
!/app/design/frontend/base/default/layout/{extension}/*
/app/design/adminhtml/*
!/app/design/adminhtml/default/
/app/design/adminhtml/default/find/
/app/design/adminhtml/default/default/etc/
/app/design/adminhtml/default/default/locale/
/app/design/adminhtml/default/default/template/*
!/app/design/adminhtml/default/default/template/{extension}/
/app/design/adminhtml/default/default/layout/*
!/app/design/adminhtml/default/default/layout/{extension}/*
Using MySQL Workbench with MAMP
by chance on Oct.07, 2011, under development, mysql, php, regex
Recently I've started working locally due to the PHPStorm IDE. In order to work locally, I invested in MAMP Pro to make use of their GUI interface for configuring vhosts. I also like to use MySQL Workbench for my database work, unfortunately these 2 items never seemed to work together for me before. After a brief google search I was able to find out how to connect to MAMP's MySQL install to do SQL Development, which is by done by choosing the local socket connection method and using the value /Applications/MAMP/tmp/mysql/mysql.sock for the connection.
After setting that up, I got to thinking, "I'm already using an IDE for code convenience and a GUI for vhost convenience, I should set up Server Administration with MySQL Workbench too!" So after some googling, I found an article to help me set up Server Administration with MAMP. Unfortunately the article only got things partially working and has no way to comment on it to have it corrected. So I'm going to outline the steps. Also I just noticed that the images with the article are updated correctly but it's hard to cut and paste an image of something someone has done so I'll just give you the value pairs
- Configuration File: /Applications/MAMP/tmp/mysql/my.cnf
- Start: /Applications/MAMP/bin/startMysql.sh -
- Stop: /Applications/MAMP/bin/stopMysql.sh -
- Check MySQL Status: ps -xa | grep "/Applications/MAMP/Library/bin/[m]ysqld"
expected exceptions annotations, mocked object calls, oh my.
by chance on Dec.24, 2010, under development, php, phpunit, unittesting
Note: I have tested this in PHPUnit 3.4.1 and haven't tried it out in 3.5.
Anyone who has worked with PHPUnit has most likely worked with expected exceptions and mock objects. The nice thing about working with expected exceptions is that we have access to a handy @expectedException annotation. I've gotten into the habit of using this for exceptions my fixtures should throw but also for when I'm using a mock object to verify a method call. So my tests usually expect foo_exception for fixture throws and when i'm testing method calls via a mock, they expect Exception. Therein lies my problem. Because all my custom class exceptions obviously extend the Exception class, I can get some false positives in testing.
equire_once 'Zend/Loader/Autoloader.php'; $loader = Zend_Loader_Autoloader::getInstance(); require_once('foo.php'); class tmpTest extends PHPUnit_Framework_Testcase { /** * @expectedException Exception */ public function testFooBar() { $foo=new foo(); $foo->bar(); } /** * @expectedException Exception */ public function testBarBaz() { $mock=$this->getMock('foo',array('baz')); $mock->expects($this->any()) ->method('baz') ->will($this->throwException(new Exception('baz'))); $mock->barbaz(); } }
class foo_exception extends Exception{} class foo { public function bar() { throw new foo_exception('bar'); } public function baz() { echo "bwah\n"; } public function barbaz() { $this->bar(); $this->baz(); } }
So here we have an expectation for Exception but if we look at the code, we see that the bar method throws a foo_exception and the testBarBaz test is trying to test for the baz call via a mock that throws an Exception. if we change the annotation to expect foo_exception, the test still passes. This leads me to believe the best way to isolate the behavior we wish to test is to not use annotation for these sorts of tests. Or if you want to use annotation, be sure to use a unique exception for the mock. This means, unfortunately for me, that I'll have to go back through all my tests and ensure there's no false positives.
Lesson learned: be careful using shortcuts (and don't stand in the fire).
On a side note, this part of PHPUnit is why those tests will behave that way. The behavior is completely my fault but I wanted to confirm it was behaving because of how it was verifying the expected exception.
fun with arrays and requirement chains
by chance on Dec.01, 2010, under development, php, web dev
Recently, I had to figure out if a given set of features contained all of their necessary requirements.
For better or worse, the table was modeled so that the feature table referenced itself so that it could create a parent/child requirement chain. For example:
| feature_id | requirement_id |
|---|---|
| 2 | null |
| 5 | 2 |
| 7 | null |
| 11 | 5 |
So my problem is to find out if a given set of requested features, make sure that the requirements are also present. This includes any requirements the requirement feature may have. In this example, 11 requires 5 which requires 2.
Let's take $featureRequest1=array(2,5,7,11) and $featureRequest2=array(7,5,11). If I were to run a look up of requirements, I would find that we have
$requirements=array(2,5).
I tried to use the php in_array function but it didn't work as I expected it to.
in_array($requirements,$featureRequest1); // i expect true var_dump(in_array($requirements,$featureRequest1)); // false in_array($requirements,$featureRequest2); // i expect false var_dump(in_array($requirements,$featureRequest2)); // false
I then realized what I need is for there to be a clear intersection between the requirements and the request.
$requirements==array_intersect($requirements,$featureRequest1); // expect true var_dump($requirements==array_intersect($requirements,$featureRequest1)); // true $requirements==array_intersect($requirements,$featureRequest2); // expect false var_dump($requirements==array_intersect($requirements,$featureRequest2)); // false
I should probably note that array_interest will preserve the array keys. To fix it, you can either flip the 2 arguments or pass the return array to array_values
Meet the PHP Dev Derby Team
by chance on Sep.10, 2010, under dev derby, development, php, the combine
I liked how the Dev Derby website did team leader profiles and decided to try to do something similar. No one provided any pictures but most did answer some questions I asked so without much further ado, meet the PHP Dev Derby Team.
The team consists of
- Dennis Rogers (@_drogers)
- Max Beatty (@maxbeatty)
- Matthew Haralovich (aka zon)
- Grant Simpson (@grantls)
- Ryan Dagey (@dageytech)
Update: added in Ryan Dagey's answers. And photo.
Valuable Professional Reading
by chance on Aug.11, 2010, under dev derby, development, php, the combine, zend

- Image via Wikipedia
The team leaders for Dev Derby have been asked to list what we consider valuable professional reading. Our book selections are not limited to our respective Languages. I thought I would share my list with everyone.
The first 2 (GoF design patterns and Patterns of enterprise application architecture) really just need to be in every developer's library. The rest are a collections of books I've read and liked as well as recommendations from developers I like and respect. Keith Casey pointed me in the general direction of a lot of these books.I suspect that some of the Dev Derby people will end up contacting various publishers to solicit swag sometime soon.
In other news about Dev Derby, I think that an application for teams should be available to announce sometime soon. I do know we have a deadline for selection approaching and it's kinda hard to select without people to select from.
GoF design patterns:
* ISBN-10: 0201633612
* ISBN-13: 978-020163361
Patterns of enterprise application architecture:
* ISBN-10: 0321127420
* ISBN-13: 978-0321127426
(continue reading...)
Auth/ACL implementation strategies
by chance on Aug.09, 2010, under development, php, security, theory crafting, zend
I'm going to talk more about ACLs than Auth. Auth is simple, it's the ACL that will trip you up. Since both concepts are coupled together when you're making a login system, I feel it's appropriate to at least touch on Auth. What I want to cover is the ways we can create the ACL object to suit needs based on the scale of the project. I'm going to assume that readers have a passing familiarity with using the Auth and Acl objects and may have even implemented them into projects.
(continue reading...)
Dev Derby
by chance on Jul.30, 2010, under announcement, development, php
This morning I accepted a postion as supreme overlord team leader for the PHP team in The Combine's Dev Derby.
What is Dev Derby?
The Combine (http://thecombine.org) is a tech event in Bloomington, IN going on from Sept. 9th-12th. On Sept. 11 there will be a "Dev Derby". This is a one-day programming event which challenges teams, representing different programming languages, to build a web-based application for use by non-profits. The code will be released as open source, giving it life after the day has ended. There will be 5 teams competing. My suspicions say that there will be a Rails team and a CF team in addition to the PHP team.
I'm not sure how finalized some of the information I have on the details are but here is what I do know:
Announcing Bloomington PHP
by chance on May.28, 2010, under php, user groups

- Image of PHP Community
I'm going to be ganking some of the announcement structure from Jeremy Kendall's Memphis PHP Announcement who apparently ganked stuff from @ramsey.
I'm proud to announce that Bloomington, Indiana now has a PHP user group. We also acknowledge the greater Central Indiana area.
The goal of this organization is to take over the world help out php users, dabblers, students , and professionals in the surrounding area while encouraging an active developer community. So far we've garnered a decent amount of members in our google group.The amount of activity behind the scenes of the group has been awesome. Matt Hottell, a Lecturer at Indiana University for the School of Informatics has promised to shamelessly plug notify his students of the PUG (in retrospect, I could've probably shortened the group name) and @_drogers has created a Bloomington Web Developers google group to include more developers in our area that work with more than just PHP. I hope to see more growth in the future and appreciate the efforts given so far. This is, after all, a community effort and I can not do this without the support of the community.
Origin Story
PHP has always been a community experience for me. From the start of learning PHP in my Informatics classes to the mentorship I received from the Resite Sproutbox team, I've seen just how awesome the PHP Community is. It wasn't until last year's php|tek that I wanted to branch that community out into the area I live in. This year's tekx gave me that final push to put things in motion to achieve that dream. I'd like to thank @caseysoftware and @dragonbe for their help and encouragement that made this a reality.
Details
- Since the current members of the google group already meet every Thursday evening at The Alley Bar, I figure why break with tradition. We'll just meet there until the time and need for selecting a quasi-formal arrangement.
- As of right now, we're just using the google group.
- You can follow @bloomingtondevs for community updates and such
- If you're wondering about the kanji (養) that is used for the user icon, it translates to: foster; bring up; rear; develop; nurture. Edit: The romanji for it is "you", which is pronounced "yo" with a long o.
- If you want to be in the the bloomington php user group twitter list that I've made, let me know.
- We have no hashtag, I'd like feedback. So far I'm thinking #btownphp or #bloomingtondevs
Thank you and welcome to Bloomington PHP.
Related articles by Zemanta
- tek x- closing remarks (phpprotip.com)
Looking for something?
Use the form below to search the site:
Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!
Archives
All entries, chronologically...








![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_a.png?x-id=b6848667-f894-4cf5-8801-a65f32f9f7cf)
