Install PHP on Windows

Install PHP on Windows

Step by step guide on how to install PHP on Windows for the purpose of PHP Development.

I’ve found myself switching computers and installing new operating systems lately. With each computer change or OS install, I must install a fresh copy of PHP. It happens every couple years so I forget all the steps… A couple months back when I found myself installing it again I made sure to make a couple notes.  Here is how to install PHP on Windows.

Please note this is just PHP, not a full server setup. I use PHP locally for development tasks and utilizing PHP-based dev tools like Composer, PHPUnit, PHPCS, etc. To run a PHP site you would also have to install a web server such as Apache and MySQL would also be handy.

Here we go:

  1. Download a non-thread safe version of PHP for windows from
  2. Unzip it and put it somewhere on your computer. For example at C:/php/.
  3. Setup the .ini file by doing the following:
    1. Rename one of the .ini  files to ‘php.ini’. I generally use the development one: ‘php.ini-development’.
    2. Uncomment and change the ‘extension_dir’ to match the ‘ext’ directory of your install (e.g.: C:\php\ext)
    3. Uncomment the following Windows Extensions.  Others may need to be uncommented depending on what you are running.
      • extension=php_curl.dll
      • extension=php_file_info.dll
      • extension=php_mbstring.dll
      • extension=php_openssl.dll
  4. Setup PHP in your ‘Path’ Environment so you can run PHP globally by adding the path of your PHP install to the end of the Path variable (e.g. add ‘;C:\php’).

Now PHP is ready to go. You can test by opening a Command Prompt window and typing the PHP info commad: php -i. Once PHP is installed, I’d suggest installing a couple other things: PEAR and Composer.

You can install PEAR by downloading the ‘go-pear.phar’ file from and running it in PHP: php go-pear.phar.  Follow prompts, defaults are fine.  Once the install is complete, run the registry update by double clicking the ‘PEAR_ENV.reg’ file that is generated.

To install Composer, download the PEAR file from  Run it with PHP to finish the install: php composer.phar.

Good luck!  Please comment if you noticed anything I forgot to add.

Joining a Subquery to Doctrine QueryBuilder

I was faced with an odd situation the other day and couldn’t find anything on the Internet to point me the right direction… I needed to join a subquery to my query using Doctrine’s QueryBuilder. I saw nothing promising on my searches and nothing in Doctrine’s docs. After some tinkering I discovered that I could slap in a query within join functions. I ended up creating the subquery as a new QueryBuilder instance and spit out the SQL into the a join function.  This should work on all their join functions: join(), innerJoin(), leftJoin(), and rightJoin(). Here’s how it works:

If you look at what the functions are doing it will click.

From the API:

join( string $fromAlias, string $join, string $alias, string $condition = null )

So when you do this: $qb->join(‘t1’, ‘tbl2’, ‘t2’, ‘ =’), Doctrine is doing this behind the scenes: JOIN tbl2 t2 ON =  So instead of adding a table as the $join variable, I dump SQL in there.

Here is a sloppy example for you:

Lets start with the base query…

$qb =$conn->createQueryBuilder();
$qb->select(", emp.first_name, emp.last_name,,")
->from("employeeMain", "emp")
->where($query->expr()->in("empId", $searchIds));

Now our sub query…

$subQuery = dbal()->createQueryBuilder();
$subQuery->select("GROUP_CONCAT(emp.jobTitle) AS jobTitle,  emp.empId")
->from("employeeMeta",  "emp")
->where("emp.locationId = '345'")
->andWhere($query->expr()->in("empId", $searchIds))

Put it all together now!

$query->leftJoin("empMain", "(".$subQuery->getSQL().")", "sub", " = sub.empId")


For more information on the Doctrine Project, check out


The code above does not work… Here is a working example of my example posting in my comment by Moya:

$query = $connection->createQueryBuilder();
$searchIds = array(‘2345′,’A567’);
$query->select(“, empMain.first_name, empMain.last_name,,”)
->from(“employeeMain”, “empMain”)
->where($query->expr()->in(“empId”, $searchIds));

$subQuery = $connection->createQueryBuilder();
$subQuery->select(“GROUP_CONCAT(emp.jobTitle) AS jobTitle, emp.empId”)
->from(“employeeMeta”, “emp”)
->where(“emp.locationId = ‘345’”)
->andWhere($query->expr()->in(“empId”, $searchIds))

$query->leftJoin(“empMain”, “(“.$subQuery->getSQL().”)”, “sub”, “ = sub.empId”)

$sql = $query->getSQL();