HOWTO: PHP with MSSQL on Ubuntu 6.06

I recently set up an Ubuntu server that needed to access a MSSQL database. The php5-sybase package sort of worked (the queries appeared to work, but data was missing). So, I set out to build some .deb packages with MSSQL support built in.

First make sure you have the Debian package development tools:

apt-get install build-essential debhelper

(More tools might be needed depending on what you already have installed, but you will tend to get warnings about what is missing)

Then, download the PHP sources:

apt-get source php5

(The current version in the Ubuntu repositories at this time is php5-5.1.2, so adjust for version numbers in the future.)

And you will need all the dependencies for building PHP:

apt-get build-dep php5

Change into the debian build directory for PHP:

cd php5-5.1.2/debian

The first step is to edit the “modulelist� file. Insert a line above the one that says

mysql MySQL

with the contents:

mssql MSSQL

Next, edit the file “rules” and look for the section starting with “configure-apache2-stamp”. You will see a line similar to:

--with-mysql=shared,/usr

Open a line above this with the contents:

--with-mssql=shared,/usr

Make sure not to forget the backslash on the end.Now, we must edit the “control” file in the same directory. Add this to the end of the file:

Package: php5-mssql
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, ${php:Depends}, php5-common (= ${Source-Version})
Description: MSSQL module for php5
This package provides a module for MSSQL using FreeTDS.
.
PHP5 is an HTML-embedded scripting language. Much of its syntax is borrowed
from C, Java and Perl with a couple of unique PHP-specific features thrown
in. The goal of the language is to allow web developers to write
dynamically generated pages quickly.

Move up a directory.

cd ..

Now, run:

dpkg-buildpackage

And go get something to eat. This will do the whole configure/compile for PHP and create debs in the parent directory. When this process is done, move up to the parent directory:

cd ..

And, you will see all of the PHP debs, including the new php5-mssql_[version].deb

Run a dpkg -i on the ones you need, and you should be all set to connect to MSSQL databases.

Share this

Related Posts

Previous
Next Post »