I had to recently figure how to enable mssql support for php at an instalation i was doing. There isn t an easy way or a simple one. I do not pretend that what i did was the best way, or the pro-way ( im just a noob . ) but anyway here it goes :
I had to recently figure how to enable mssql support for php at an instalation i was doing.
There isn't an easy way or a simple one. I do not pretend that what i did was the best way, or the pro-way ( im just a noob >.> ) but anyway here it goes :
Step 1 :
First i want to clarify that i am using debian testing repository, since i want to avoid troubles
while updating my packages. If you do not want bleeding-edge updates, i advise you to do the same. This is easy, by changing your /etc/apt/sources.list to look like that :
deb http://debian.ludost.net/debian/ testing main contrib non-free
deb-src http://debian.ludost.net/debian/ testing main contrib non-freedeb http://security.debian.org/ testing/updates main contrib
deb-src http://security.debian.org/ testing/updates main contrib
Note that i am using http://debian.ludost.net/debian/ for my mirror, you should change it to your preferred one. If you were running etch till now, you can update with
apt-get update
apt-get dist-upgrade
So far so good.
You need to install tdsodbc package next. Just use aptitude and locate it.
To compile php5-mssql package you will need the full freetds package optainable trough this url :
freetds-latest.tar.gz
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
It might take a while, but not that long :) If you get errors or your system does not have make installed, run :
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 build freetds.
Step 2 :
We get and install the php5 sources :
apt-get source php5
Next we get all the dependancies required to build it :
apt-get build-dep php5
You should get a directory named php5-5.2.3 . Assuming you issued apt-get source php5 from /usr/src directory, it would be placed in /usr/src/php5-5.2.3/ .
Change to that directory and issue :
vim debian/modulelist
Find the line where it says
mysql MySQL
and add above it :
mssql MSSQL
Save and close the file. In vim this is done by pressing :wq ( shift+; then w then q ). Now open debian/rules file :
vim debian/rules
Find
–with-mysql=shared,/usr
And add above it :
--with-mssql=shared,/usr/local/freetds
Finally open debian/control file and add at the end :
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. Make sure you're in /usr/src/php5-5.2.3/ and type :
dpkg-buildpackage
It will take some time. Go get a coffee or eat something :) When this is done, you will have a bunch of .deb files it your /usr/src directory. The one we need is :
php5-mssql_5.2.3-1+lenny1_i386.deb
You can safely run :
dpkg -i php5-mssql_5.2.3-1+lenny1_i386.deb
One thing to note : you will have to have the php5-sybase package installed for things to work. In /etc/php5/conf.d/mssql.ini comment out the extension line, so it looks like that :
# configuration for php MSSQL module
;extension=mssql.so
I dont know why, but apache2 crashes due to sybase not able to find
some shared library if you have this enabled. Anyway, you can now setup your
dns entries in /etc/freetds/freetds.conf and use mssql_ functions in php :)
Note : All of this is based on what i've read on php.net and ubuntuforums.org . Credit goes to
the original authors, whoever they are.