Enabling MSSQL for PHP5 On Debian Lenny (testing)

Want to support HowtoForge? Become a subscriber!
 
Submitted by thedoc (Contact Author) (Forums) on Tue, 2008-03-11 12:46. :: Debian | PHP

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.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Thu, 2010-10-21 19:12.
dpkg-buildpackage does not work: "could not resolve path to ltmain""
Submitted by Anonymous (not registered) on Thu, 2010-10-21 18:19.
apt-get install tsdodbc -> package not found...
Submitted by Darwick (not registered) on Fri, 2009-05-22 12:05.
Guys, on debian etch or upper, there is no php5-mssql package. That is included into php5-sybase package, just install it and there is the mssql support. :) Refer: http://packages.debian.org/search?keywords=php5-sybase
Submitted by TMB (not registered) on Wed, 2009-06-03 12:09.
Very good dude! thx....
Submitted by Thomas (not registered) on Mon, 2008-12-29 17:53.

Hi, 

I have error when dpkg-buildpackage used:

make[1]: *** [ext/imap/php_imap.lo] Błąd 1 
make[1]: Opuszczenie katalogu `/usr/src/php5-5.2.6/apache2-build' 
make: *** [build-apache2-stamp] Błąd 2 
dpkg-buildpackage: niepowodzenie: debian/rules build zwrócił status błędu 2

translation: dpkg-buildpackage: failure: debian/rules binary gave error exit status 2

debian/rules is set as in tutorial:

..."--with-mysql=shared,/usr \
  --with-mssql=shared,/usr/local/freetds \
  --with-mysqli=shared,/usr/bin/mysql_config \"...

What I am doing bad?






Submitted by Arturo (not registered) on Mon, 2008-12-08 19:24.

I am currently using "PHP 5.2.7-0.dotdeb.1" and when I try to run apt-get build-dep php5 the following is returned:

    apt-get build-dep php5
    Reading package lists... Done
    Building dependency tree... Done
    Package libmysqlclient14-dev is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    However the following packages replace it:
    libalps-heap1-dev
    E: Package libmysqlclient14-dev has no installation candidate
    E: Failed to satisfy Build-Depends dependency for php5: libmysqlclient14-dev

 I have removed libmysqlclient14-dev with --purge switch. I have installed libalps-heap1-dev. I have found some older deb sources to see if the dependency can be built from those. I have tried apt-get --fix-broken
apt-get --ignore-missing

Can someone help and let me know how to ignore the dependency or use the alternative libalps-heap1-dev to build-dep.

Thank You.

Submitted by sh1ny (registered user) on Tue, 2008-04-15 06:27.

Atleast give proper credit next time. I posted my howto on my site for everyone to use, and i dont mind seeing 90% of it here ( with slight mods ), but atleast include a link or say thanks or whatever.

http://shiny.ma3x.net/2007/11/28/enabling-mssql-for-php5-under-debian-lenny-testing

Have a nice day :)
Submitted by megansmith (registered user) on Wed, 2008-06-04 15:18.

I wanted to enable myssql too on one of my older website and i have to say that the tutorial is very clear and easy to follow. I did get a few weird errors, but by typing: apt-get install build-essential debhelper like you said, it worked perfecly! I just want to say thanks :)

Megan from credit card live!

Submitted by Nacho (not registered) on Mon, 2009-06-29 09:38.

Hi!

Thanks for this great tutorial, it served well to my purpose in Debian Etch with a very few changes: It also helped me to understand better how the debian source packages can be easily modified.

 In my case, I had to do this:

  1.  In the debian/control file, erase the field "(= ${Source-Version})" that comes after "php-common" in the "Depends:" line for php5-sybase and php5-mssql.
  2.  Instead of installing the default php5-sybase package from the official repo, just install the compiled one along the new customized php5-mssql package.
  3.  Reboot/Reload your Apache2 et voilà!

Of course you could just use the php5-sybase package, but if you cannot miss some features and you cannot upgrade to Lenny, it's fine.

 Hope it helps.