Enabling MSSQL for PHP5 On Debian Lenny (testing)

Recently I did an install of Debian Etch 4.0 to prepare it for ispconfig. Knowing I had a website that needed MSSQL support I had to figure out how to accomplish this. There may be an easier way I don't know, but this daunting task worked this way.

 

Step 1:

First thing I did was to use the debian testing repository. To add this repository to your isntallation do the following (I prefer the use of nano but you may use your editor of choice):

nano /etc/apt/sources.list

Add these entries to make your sources.list look like this:

deb http://debian.ludost.net/debian/ testing main contrib non-free
deb-src http://debian.ludost.net/debian/ testing main contrib non-free
deb http://security.debian.org/ testing/updates main contrib
deb-src http://security.debian.org/ testing/updates main contrib

Exit and save.

 

Step 2:

Now run

apt-get update

Now run

apt-get dist-upgrade

Now we are on our way...

 

Step 3:

apt-get install tsdodbc

 

Step 4:

To compile php5-mssql package you will need the full freetds package.

cd /usr/src/
mkdir -p /usr/src/freetds
cd /usr/src/freetds
wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar -zxvf freetds-stable.tgz
cd freetds-0.64
./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld
make
make install

If you receive errors during the install run this:

apt-get install build-essential debhelper

That should do it. After this is done you should have a /usr/local/freetds directory, containing your newly built freetds.

 

Step 5:

Now change to your /usr/src directory so that we can install php5 sources:

cd /usr/src
apt-get source php5

Now we need to get all the dependencies:

apt-get build-dep php5

 

Step 6:

When that completes change dir to php5-5.2.5:

cd php5-5.2.5

Now issue the directive:

nano debian/modulelist

Look for the line that says:

mysql MYSQL

Abov that line type:

mssql MSSQL

Exit and save.

 

Step 7:

nano debian/rules

Look for the line that says:

--with-mysql=shared,/usr

Above that line type:

--with-mssql=shared,/usr/local/freetds \

 

Step 8:

Finally open the file debian/contro and at the end add:

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.

That should be it.

 

Step 9:

Now run the following command:

dpkg-buildpackage

This will take some time to finish. Go get a cup of coffee or grab the paper and catch up on the news.

 

Step 10:

Now when this is done you will have a bunch of .deb files in your /usr/src directory so change to that dir:

cd /usr/src

The package we will need is php5-mssql_5.2.5-3_i386.deb:

dkpg -i php5-mssql_5.2.5-3_i386.deb

 

Step 11:

The very last step is to make sure you have php5-sybase installed.

apt-get install php5-sybase

You can now setup your dns entries in /etc/freetds/freetds.conf and use mssql_ functions in phpo :>)

This guide was found on the net and derived from php.net and the ubuntu forums. I made a few small changes to try to make the guide a little easier to follow. and added the instruction for ISPConfig below:

One note:

If you plan on installing ISPConfig you must edit the config file apache2.conf located in /etc/apache2:

cd /etc/apache2
nano apache2.conf

Find the line that says:

User ${APACHE_RUN_USER}

and

Group ${APACHE_RUN_GROUP}

and change to:

User www-data
   Group www-data

Save and exit.

Share this page:

9 Comment(s)