Wednesday, October 24, 2012

Catch-all post about solving setup issues with PhpStorm, Composer, and Symfony2

I had to do some preliminary work over the last week or so to create a workable PHP development environment before diving into some moderate-to-heavy work making a small e-commerce site.  I've had a VirtualBox install of Linux Mint 12 on my laptop for a while, but it was never setup quite the way it should've been.  So, I took the time to do it right.  Unfortunately, open source software tends to have shitty documentation, so in order to prevent others from making the same mistakes I did, I'm going to list my problems and my eventual solutions.

PhpStorm:


PhpStorm is an awesome PHP IDE from JetBrains.  .NET programmers will recognize JetBrains from Re-sharper (R#).  It's not quite as all-inclusive as, say, Visual Studio.  Unit Testing and debugging don't come installed as part of the software.  Instead, it's designed to integrate with PHPUnit and one of Xdebug or Zend Debugger.

Setting up PHPUnit is fairly straightforward, but the debugger is another matter.  The (somewhat confusingly written) documentation would lead you to believe that you need to play with IDE tokens and ports and server names and other things.  Not really, at least, not in my case.

PhpStorm's debugger listener is pretty smart.  In a lot of cases it can automatically detect a debugging session.  The steps are ridiculously simple:

1. Install a debugger on your system.  I opted for Xdebug, so it was simply a matter of:

$ sudo apt-get install php5-xdebug

2. Edit your php.ini files (both the web server's and the CLI's) so xdebug.remote_enable is on, and restart your server.

3. Follow the other instructions here: Zero-configuration debugging with Xdebug and PhpStorm 2.0.  Even though PhpStorm is now up to version 5.0.2 as of this writing, the instructions here worked like a charm for me.

Composer:


Composer is a dependency manager for PHP written by Nils Adermann and Jordi Boggiano (with contributions from others).  It's nice and lightweight.  A JSON config file lists the packages you want/need for a project, and it looks at both its package repository (Packagist) and Github for them, installing them in a /current/path/vendors/ directory.

My problem with Composer was that I kept running into connection timeouts.  It wasn't a network error on my end - I have ~12 mbps downstream, so that's not a problem.  After a lot of searching, I found that the issue was caused by Composer being inefficient in its searches/downloads.  Something about it looking at both the distribution version and source version of a package.  To get better performance, a --prefer-dist option was added to the command line.  Unfortunately, that switch is not mentioned anywhere in documentation, nor in the CLI's --help option.

So, to use the option, simply (assuming a global install of Composer):

$ composer update --prefer-dist

Composer now works perfectly for me.

Symfony2:


Symfony is a modular MVC framework from Sensio.  The Standard Edition comes with a demo app, which should be removed before doing your own work.  The Standard Edition's Github README.md describes the process of removing the demo.  Unfortunately, the instructions regarding security.yml are wrong.  Simply removing those listings results in a runtime exception.  No, instead you need to provide default values.  Nice to know now.

So, there you have it, solutions to issues not mentioned in official documentation.  Hopefully I can stop others from getting frustrated.

EDIT: Thanks to Tony Quilkey, a.k.a. trq, a.k.a. thorpe for setting me straight on Composer's lineage.

1 comment:

  1. software development !!! It's a nice plug in !!!! It's very useful to new visitors. thanks for share!

    ReplyDelete