kunal@localhost$

Connecting MSSQL Server with Zend Framework on Linux

Posted in Linux, PHP, Zend Framework by kunalbharati on June 19th, 2008

Few days ago we completed a project which used Zend framework and the database was MS Sql Server 2005. We had tough time deploying the project on Linux. Initially we started with Ubuntu but in Ubuntu php-mssql package is missing. We tried to compile it but didnt work. Then we decided to use Fedora which has php-mssql package. So the following steps should work for any distro with php-mssql package in it.

With PHP already installed we started with installing following packages:

  • php-mssql
  • php-pear
  • freetds

Now we need pear mbd2 driver for mssql. You can install it using following steps:

First install mdb2 driver:

$ pear install mdb2

Now install mdb2 fro mssql:

$ pear install mdb2_driver_mssql

Zend framework uses PHP Data Objects (PDO) for connecting to databases. Though there is a way to connect to databases without PDO. On Linux we will use pdo_dblib driver for connecting to MS Sql Server. You can download pdo_dblib package from http://pecl.php.net/package/PDO_DBLIB (We have used version 1.0).

After downloading now we need to compile the package:

Untar the package:

 $ tar zxvf pdo_dblib.tgz

Now we use pecl command which will build the package and generate the configure script:

$ pecl build package.xml

Change to directory and run configure and make:


$ ./configure
$ make

Copy pdo_dblib to php’s modules directory :


$ cp modules/pdo_dblib.so /usr/lib/php/modules
$ vi /etc/php.d/pdo_dblib.ini

Write the following line in the file:

extension=pdo_dblib.so

Next step is to configure freetds to connect MS Sql Server:

$ vi /etc/freetds.conf

And write these lines in the file:


[SERVER_NAME]
host = <IP Address>
port = <Port Number>
tds version = 8.0

Finally set the pdo_type you specified in you project to dblib. We used a separate config.ini file, you can also do that in bootstrap.php:

pdoType = dblib

The project is deployed finally :) I hope I havent missed a step. All’s well that end’s well :)

Tagged with: , , ,

4 Responses to 'Connecting MSSQL Server with Zend Framework on Linux'

Subscribe to comments with RSS or TrackBack to 'Connecting MSSQL Server with Zend Framework on Linux'.

  1. Aamod said, on June 19th, 2008 at 7:06 pm

    Everything is fine.. What’s connection between you and vi? :-)

  2. kunalbharati said, on June 20th, 2008 at 5:14 am

    Its because emacs was not installed :)

  3. Lukas said, on August 6th, 2008 at 6:11 am

    How is the combo PHP on *nix plus SQL Server 2005 working out for you?

  4. kunalbharati said, on August 6th, 2008 at 7:27 am

    We had problems with the initial setup. We generally work on PHP and MySql projects. This was our first PHP-MsSql project.

    After the complete setup the first thing we discovered was theres no support for utf-8 in MsSql Server.

    PHP’s “mb_convert_encoding” helped us to deal with the problem.

    Currently the project is deployed and successfully :)

Leave a Reply