woh! okie.. this installation is gng to be long a tough.. took me a few days of google crawling and testing before i finally get it to work.
okie, why will u need to install mssql extension on php? possibly becos u need to connect to a ms sql server of ur vendor or something like that. for integration i hope. cos unix works best w php and mysql, ie, installation, it is almost already thr. correct me if i m wrong.
so wad you need?
if your server is jus fresh out of the box or say u had installed whm/cpanel there will be quite a far bit of stuff u will need.
1. Txt2man
2. unixODBC
3. freeTDS
4. PHP mssql.so
if this point if you are wondering if i m using any rpm for installation?
sorry,i m not, cos my server centos installed w whm/cpanel seems to be poorly equipped or configured for rpm installation, too many dependencies required. so jus download all the binary and upload them onto ur server.
Setup 1: Install unixODBC package
Install unixODBC first. Download the software in your home directory or anywhere you like and uncompress and untar the software.
You can do this by using following command
Once it is done, go to the unixODBCxxxx dir and run the configure command.
Note: If you dont use enable-gui option and dont have Qt package, you will get the error. So make sure you use it if no Qt is installed.
After configure is successfully completed, run the make and then make install commands.
Install it
Step 1.1: Installing Txt2man
this step is optional if your server already have txt2man installed.
txt2man is required by freeTDS to man it documentation, i do find this portion pretty useless though.
else jus download the package, and run the make
Install it
Step 2: Install freeTDS package
Download the freeTDS package and untar and uncompress it.
Run the configure.
Run the make
Install it
Step 3: Configuration freeTDS
Start configuration with freeTDS. Look for the freetds.conf file and add the entry for the MS SQL server.
host = MSHOSTNAME
port = 1433
tds version = 8.0
Sql server standard port is the 1433. The tds version for MS SQL server 2000 is 8. You can try 8.0 with new version as well.
Important: the host need to be the same as the declaration. ie
if you have [mssql.hostname.com], ur host will be = mssql.hostname.com
Step 4: Configuration – unixODBC
The unixODBC need two main configuration files called odbcinst.ini and odbc.ini. These files should be in the /etc/ dir.
I. The first file odbcinst.ini contain the definition of ODBC driver.
Description = FreeTDS driver
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsodbc.so
Trace = Yes
TraceFile = /tmp/freetds.log
FileUsage = 1
Note: Before making above entries, make sure libtdsodbc.so exists in the /usr/local/lib dir.
In the above configuration, we have define TDS as driver.
II. The second file is odbc.ini. This file has information about your MS SQL database.
Driver = TDS
Description = MS SQL Test
Trace = Yes
TraceFile = /tmp/mstest.log
Servername = 192.168.1.100
Database = testdb
Port = 1433
You can notice above that the freeTDS driver is the name defined in odbcinst.ini while servername is the one defined in freetds.conf.
Step 5: Test MS SQL connectivity from Linux box
Check if you can connect to MS SQL database using unixODBC tool called isql.
+—————————————+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+—————————————+
SQL> select * from “sysObjects”;
If you see the results, you are connected.
Step 6: Getting your mssql.so file
php.net is not distrubuting the binary version of php package for *nix server, so you will have to create the .so extension file yourself. download the source file for php and upload the folder /ext/mssql/ into your server
then
# phpize
# ./configure
# make
# make install
this commands will automatically create a copy of mssql.so in the installed extension folder.
you can check your extension folder from
?>
Step 7: Enabling the extension
or you can use a texteditor and add that value manually into php.ini
Step 8: Restarting Apache Server!
dependin on version installed and location
and you are done!
do drop me an email should you face any problem at any step!
i know the pain in gettin this extension installed on unix. and considering rpm fails to work in the first place.
i will say, this is the best way to get it installed, cos u have full control over it. and didn’t fail me, of cos, after hell lots of googling around.
Source:
dpacool.com
unixodbc.org
Scott’s Blog
PHP PECL
Tags: freetds, isql, linux, mssql.so, php, php extension, php mssql, php pecl, tsql, txt2man, unix, unixodbc
you are saving my life…
Thank you very much for your documentation…!
[...] Entropy.ch the following instruction is for you, else, you may try my earlier post on installing msSQL extension for php in *nix/Centos Server, largely used by [...]
thanks… at least i’m heading for the right direction…
trying to work with yum/rpm first before getting the tar ball
done. lucky me, my yum/rpm is all okay
(search the freetds for your CentOS)
# yum search freetds
you’ll find freetds*.rpm freetds-devel*.rpm freetds-doc*.rpm
(install with yum)
# yum install freetds-xxx
(or download the rpm with yumdownloader)
# yumdownloader freetds-xxx
the rest is the same with the above article
ialexs! that great to hear. =)
also notes, if it’s on a 64b box (in this case still with Centos),
the freetds installing the lib in /usr/lib64
be sure when do a “configure” in the php source directory to define the “–with-lib” option
Your blog is interesting!
Keep up the good work!
I cannot get passed step 4. For some reason, I cannot find the odbc ini files, both odbc.ini and ocbcinst.ini are missing from the /etc folder. I do have the libtdsodbc.so file though. How do I find the odbc ini files?
Hi Evan, you got the first step right without errors? cos the installation will create those 2 files.
Hi Steven,
yeah the first 3 steps completed fine with no errors. I downloaded and installed everything from the /root folder as root user. However, I forgot where unixODBC was installed after I ran the make install. Is there a way to manually copy the ini files from somewhere?
Evan, you need to find the directory where you installed, cause ODBC is configured to read from those path. u can try this, “vi unix.ini” and then insert the above content, and same for odbcinst.ini
not too sure if this will work tho. let me knw! =)
understood. I created the ini files and cloned the content above. Now on step 5, I am ready to test isql. My firewall admin has not opened port 1433 yet but I have all the settings correct for the ini file. So naturally when doing the isql test connect it will say data source name not found, but it also says no default driver specified.
Will both these errors go away when the port is open or do I still need to do something about the default driver?
whoops, guess what, I found the odbc.ini and odbcinst.ini files in the /usr/local/etc folder. That’s where it was installed by the unixODBC make install. I edited these and removed the ones I made in the /etc folder in the root.
ah ha!!! u get to connect w isql? i think u may need to open the port first.
lol. Of course I may be getting too preemptive here, but I don’t suppose there is an easier way to get step 6 done, I’m having trouble finding the binary mssql.so download. I found an RPM on rpmfind.net but I’m not sure if that’s the right one. Can’t you tell I’m a newbie?
no worries, that actually the easiest after ur first try, go to http://www.php.net/downloads.php to download the complete source for your version, the same major version shld works too actually.. then mssql.so can be found inside.
ack! ok I got the source, tarred and browsed to /root/php-5.2.6/ext/mssql
Did the phpize and then ./configure.
After starting ./configure it halts and says it cannot find freeTDS in known installation directories. Is there a setting I’m missing to maybe change the path to where FreeTDS is? (/usr/local/lib)
I added this to the configure line:
./configure –with-mssql=/usr/local
Now it errors out with /usr/local not being a freetds installation directory.
did u run freetds configure w the following line?
# ./configure -with-tdsver=8.0 -with-unixODBC=/usr/local
you seems to be facing quite a bit of wrong installation directory, on unixodbc too.
mmm, okie i wun say wrong, but non-default or standard folders.
Yeah I did exactly that on the ./configure line. Perhaps fate doesn’t want me to succeed with this. If I can just get the mssql.so file copied to the directory and add extension=mssql.so to the php.ini file, is that all I really need?
evan, yes! get the original php source to produce the mssql.so instead of getting the file itself, better to be done this way.
That’s what I’m trying to do but I can’t get it to work. That’s where I run into the error that #$%# freetds install directory is not valid.
ok I made some progress, the 0.82 version of freetds doesn’t seem to work here so I went back to 0.63, and I was able to make the mssql.so file and it copied to the php extensions directory. Upon adding it to the php.ini file with extension=mssql.so it seemed to have no effect. The phpinfo() does not show MSSQL support and the test page still shows mssql_connect as an undefined function.
ah! u restarted apache?
yes sir! did both versions:
service httpd restart
/etc/inid.d/httpd restart
apache restarted but php did not add the mssql support…
crap. ok I got past that error and now php recognizes mssql support. but I can’t connect to my mssql server. I have to access it by it’s ip address and I already have port 1433 open.
Hey Evan, sorry i was away, so how is it now?
successfully installed?
Hi Steven, no problem, I was away as well and just returned. I was able to get everything working perfectly! The only thing that was left standing in the way was a minor glitch that prevented connection to port 1433 but I got it resolved. Thanks again for all your help!
By the way, I hope people will know that the latest build of FreeTDS (0.82) does not work with these instructions as it does not contain the tds.h file anymore. I had to download the 0.63 version to get it working.
Alright man!
Yep, thanks for the update!
Steven, I ran across your info and it’s been a godsend helping me to do what’s necessary to connect to MSSQL from my SuSE Linux 11.0 system. Your instructions work fine so long as I use the package manager in SuSE to install things. But then, just like Evan, the ./configure command for making mssql.so halts and says “Cannot find FreeTDS in known installation directories”.
Linux rpm’s put php, freetds and others in non-standard locations. For example, UnixODBC config files are in /etc/unixODBC, and lib files are in /usr/lib64/ and /usr/lib64/unixODBC/. Freetds executables are in /usr/bin/, config files are in /etc/ and lib files are in /usr/lib64.
Maybe I can edit the php configure script to look for freetds elsewhere.
I peeked into the script and it appears to be looking for a file called tds.h either in ‘/usr/local/include/’ or
/usr/include/’. I found out that freetds-0.82 no longer writes a file called ‘tds.h’.
One solution I found is to create two files where FreeTDS was installed e.g.:
> $ touch /usr/include/tds.h
> $ touch /usr/lib/libtds.a
I think for me that would mean ‘/usr/lib64/’.
Another solution I found is to edit the configure script (see http://bugs.php.net/bug.php?id=44991)
if test “$PHP_MSSQL” = “yes”; then
for i in /usr/local /usr; do
- if test -f $i/include/sybdb.h; then
+ if test -f $i/include/tds.h; then
FREETDS_INSTALLATION_DIR=$i
FREETDS_INCLUDE_DIR=$i/include
break
- elif test -f $i/include/freetds/sybdb.h; then
+ elif test -f $i/include/freetds/tds.h; then
FREETDS_INSTALLATION_DIR=$i
FREETDS_INCLUDE_DIR=$i/include/freetds
break
@@ -27,10 +27,10 @@
elif test “$PHP_MSSQL” != “no”; then
- if test -f $PHP_MSSQL/include/sybdb.h; then
+ if test -f $PHP_MSSQL/include/tds.h; then
FREETDS_INSTALLATION_DIR=$PHP_MSSQL
FREETDS_INCLUDE_DIR=$PHP_MSSQL/include
- elif test -f $PHP_MSSQL/include/freetds/sybdb.h; then
+ elif test -f $PHP_MSSQL/include/freetds/tds.h; then
FREETDS_INSTALLATION_DIR=$PHP_MSSQL
FREETDS_INCLUDE_DIR=$PHP_MSSQL/include/freetds
else
@@ -38,8 +38,8 @@
fi
fi
- if test ! -r “$FREETDS_INSTALLATION_DIR/$PHP_LIBDIR/libsybdb.a” &&
test ! -r “$FREETDS_INSTALLATION_DIR/$PHP_LIBDIR/libsybdb.so”; then
- AC_MSG_ERROR(Could not find
$FREETDS_INSTALLATION_DIR/$PHP_LIBDIR/libsybdb.[a|so])
+ if test ! -r “$FREETDS_INSTALLATION_DIR/$PHP_LIBDIR/libtds.a” &&
test ! -r “$FREETDS_INSTALLATION_DIR/$PHP_LIBDIR/libtds.so”; then
+ AC_MSG_ERROR(Could not find
$FREETDS_INSTALLATION_DIR/$PHP_LIBDIR/libtds.[a|so])
fi
PHP_ADD_INCLUDE($FREETDS_INCLUDE_DIR)
This link was last dated Jun 13, 2008.
I don’t think this completes the solution for me unless I also change the directory in which the script is looking. And change the file it’s looking for: my installation of freetds doesn’t have ‘ibsybdb.so’. It has ‘ibsybdb.so.5′.
This is a long comment. It may prove useful to others. I’m going to mess around with these ideas and see if they help me.
Hey Brain, definitely useful, i think i am gng to rewrite this documentation after i try doing a new installation on another server w the latest available versions.
of cos, when i have got the time.
yea, installing mssql in linux is one pain in the ass, it took me 2 weeks before i finally concluded on the above. most of the rpm because of versions issues dun really seems to work well with each other, unless u got the specific version that comes together.
Well, I made a few little changes to the configure script so it not barf when it came to locating freetds. I altered the location it was looking in and the file it was looking for and so the ‘./configure’ command was rewarded with “config.status: creating config.h”.
Hoping for the best, I proceeded to the ‘make’ command. It bombed with a laundry list of errors. The first ones were
error: sqlfront.h: No such file or directory
error: sqldb.h: No such file or directory
error: expected specifier-qualifier-list before ‘LOGINREC’
… and 320 more. I’ll start scouring the net for what to do now. Damn!
Steven, I discovered I had to install the ‘freetds-devel’ and ‘python-devel’ (2.5.x) rpm’s to work out those dependencies needed by the configure script. The ‘make’ and ‘make install’ commands then worked fine and the ‘mssql.so’ extension was automatically created in ‘/usr/lib64/php5/extensions’ (where SuSE wants ‘em).
After that I copied and pasted the [MSSQL] section from another ‘php.ini’ (I had on my Mac, where mssql connections already worked) and I created ‘mssql.ini’ in ‘/etc/php5/conf.d/’ (where SuSE wants them) so that the ‘mssql.so’ extension would load. Finally I restarted Apache and my goal was reached.
Thanks a million for putting your solution on the web! It took a lot of searching before I found it. You might be the only person who’s published a solution.
Brian, you are most welcome! btw, what OS and version r u on?
Principal software and versions: OpenSuSE 11.0 x86_64, KDE 4, PHP 5.2.6, Apache 2.2.8, PostgreSQL 8.3.3, running on an 8-core Intel MacPro in a dual-boot configuration
Ah, why didn’t u try Entropy PHP?!
http://www.entropy.ch/software/macosx/php/?phpinfo-version=5.2.5-6
[...] to Brian for the [...]
Hi. I tried to install FreeTDS on a system running a 64bit version of opensuse. I couldn’t get it to work.
I run
# ./configure -with-tdsver=8.0 -with-unixODBC=/usr/local
and
then make.
After that I run make check to see if it worked.
it ends up saying that I failed 10 of 13 tests in the make check.
I was wondering if you ever ran into a problem like this ?
hi Justin, you may want to check the versions? of your tds and unixodbc built.
i know of installation test failure for newer version or either.
help!
after on step 6 i got the following error:
Cannot find config.m4.
Make sure that you run ‘/usr/bin/phpize’ in the top level source directory of the module
i’m very sure that i am in directoy ‘/usr/bin when executing “phpize” sorry i’m new in linux and i don’t know what that means…
eh. really like it