Backtrack:  
 
by lunarg on March 26th 2007, at 20:08

Apparently, there's no package for MS-SQL support in Debian or Ubuntu. Why this is, is not very known, in particular since there is MS-SQL support in PHP4 and PHP5.
I found the following steps somewhere on the internet.

The following was tested on a Ubuntu 6.10 Edgy, but will probably work on others as well.
Also, whenever I refer to php5, it could well be replaced with php4, which I've tested as well.

First of, make sure the necessary build tools are installed:

# apt-get install build-essential debhelper

It's possible more tools are needed, depending on which ones have already been installed, but basically, if you can compile other packages from source, you should be good to go.

Next up, download the PHP sources:

# apt-get source php5

Note that downloaded sources will be put and extracted in the current directory, so move to a clean folder if you want to have an easier cleanup.

After that, install all the dependencies needed to build PHP:

# apt-get build-dep php5

Cd into the debian subfolder of the build directory:

# cd php-version-numbers/debian

Edit the file modulelist, and insert a line right above:

mysql MySQL

which says:

mssql MSSQL

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

-with-mysql=shared,/usr

Open a line right above with content:

-with-mssql=shared,/usr

Important is not to forget the trailing backslash!

Finally, add the following to the control 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.

Now, we're ready to build. Move up a directory:

cd ..

And fire up the build process:

dpkg-buildpackage

This may take some time, so go take a breather.
When it's done, move up a directory again, and you'll notice a whole bunch of Debian packages.

Now, if you've already installed half of php5, you only need to install the mssql package like so:

dpkg -i php5-mssql-version.deb

This should do the trick. It's possible you might need to edit the php.ini file and add the extension=mssql.so in order to get it running with PHP. If you're using Apache, don't forget to restart.

If anyone has tested the following on Debian, please let me know whether it worked, and if not, what needed to be done in order to get it working. Thanks.