Connect to MSSQL from Linux Ubuntu with Symfony and Doctrine


  1. Install the php5-sybase package
    This will install on Ubuntu the drivers required to connect to a Microsoft SQL Server.
  2. Test connection from PHP
    We want to make sure PHP is working before moving on to Doctrine. See below for a sample test PHP script.
  3. Install the leaseweb/doctrine-pdo-dblib bundle
    Doctrine out of the box does not support connecting to a MSSQL server from Linux. This bundle “forces” Doctrine to do it.

Sample test PHP script

Here’s a short PHP script that you can run from the command line to test that the connection to MSSQL is working fine.

$dbh = new PDO ("dblib:host=;dbname=mydatabase","user","password");
$stmt = $dbh->prepare("SELECT * FROM products");
while ($row = $stmt->fetch()) {


Install and enable WKHTMLTOPDF 0.12 on Ubuntu Server 14.04

WKHTMLTOPDF is a very handy binary tool to create PDF from HTML. I used it already in many projects and I am very happy with the results.

But the initial setup could be a little tricky if you don’t know your way around a Linux server. The following procedure works for me with WKHTMLTOPDF v.0.12.3 on Ubuntu Server 14.04:

Continue reading Install and enable WKHTMLTOPDF 0.12 on Ubuntu Server 14.04

Symfony template locations: questioning the best practice

A while ago the Symfony project published a “Best Practices” book.

This is a source of excellent suggestions and it’s written by the people who wrote Symfony in the first place, so we decided to stick to it as much as possible, even in those few cases where the benefits where not immediately clear.

But after a few more Symfony projects, there is one best practice that I definitely want to question: the location of the templates.

Continue reading Symfony template locations: questioning the best practice

Symfony and Monolog: define a custom logger file at runtime

I had the need to write to  a custom log file, but with the additional constraint that the file name was not known until runtime (UUID for a new entity).

On the Symfony Cookbook there is already a recipe about using different log files but it relies on a configuration made before the execution.

After a little experimenting, here’s the simple solution I implemented:

use Symfony\Bridge\Monolog\Logger;
use Monolog\Handler\StreamHandler;
// ...
$logger = new Logger('import');
$logger->pushHandler(new StreamHandler($kernelRootDir . '/logs/' . $runtimeGeneratedId.'.import.log', Logger::DEBUG));