Installing The PHP-MSSQL Module On CentOS 5.0

Author & Content by Tim Haselaars (

As you might have noticed on Centos 5.0, there is no PHP-MSSQL module/extension available in the default yum repositories. So if you want to use it you can alter the PHP binary or you can compile an mssql module/extension. In this article I will explain how to compile the mssql module/extension.

You need to activate the RPMForge custom repository (formely known as Dag Wieers):

Grab your specific RPM and install it:

rpm --install rpmforge-release-*.rpm

Next step is to install freetds, freetds-devel, php-devel, and the Development tools.

yum groupinstall ‘Development Tools’

yum install freetds freetds-devel --enablerepo=rpmforge
yum install php-devel

Next we alter the php.spec file, which contains the php configuration for compiling.

vi /usr/src/redhat/SPECS/php.spec

If you don't have the php.spec file, you can download the php src rpm.


and next

rpm –install php-5.1.6-5.el5.src.rpm

And then do an updatedb and locate php.spec.

Edit the CFLAGS= line (~line 310) of the php.spec file - remove -Wno-pointer-sign. Then add the following piece of code to it:

Group: Development/Languages
Requires: php = %{version}-%{release}, php-pdo
Summary: A module for PHP applications that use the MSSQL database.
provides: php_database
BuildRequires: freetds-devel

%description mssql
The MSSQL package contains a dynamic shared object that will add
support for accessing MSSQL databases to php.

Start building your php rpm:

rpmbuild -bb ./php.spec

If you are asked for some dependencies, just yum install them.

cd /usr/src/redhat/BUILD/php-5.1.6/ext/mssql/

Now we are going to make the mssql module without having to rewrite the php binary:

./configure --with-mssql
make install

Next look for the file and make sure it is in the module directory specified in your php.ini. Copy it to the specified location if needed.

Final Step

vi /etc/php.ini

Add this line to your php.ini:

Save the php.ini and restart Apache:

/etc/init.d/httpd restart

Et voilà you have just made your mssql module/extension without having to change anything in the base CentOS 5 HTTPD/PHP setup.

Share this page:

9 Comment(s)

Add comment


From: camilord at: 2009-05-06 06:31:03

is it possible both mysql and mssql are in centos 5.x ?

From: Leonardo Bonilla at: 2008-11-16 22:53:13

Salutes form Colombia

When I have to make the modification to "php.spec" file i see that you have a missing at the begining of the text 1 line

"%package mssql" 

I just add this to your info and all works, y have Centos 5.1 and PHP 5.1.6-20



From: Vikram Ghotgalkar at: 2009-07-29 07:59:48

1. Install php-mmsql module using yum

yum install php-mssql

2. Add the following line to php.ini

3. Restart Apache

/etc/init.d/httpd restart



From: Hugh MacMullan at: 2009-12-17 16:12:53

I concur with Leonardo (the missing '%package mssql' bit).

After that works great on Red Hat EL 5.4 with AppStack and PHP 5.2.10.  Nice!

From: Anonymous at: 2009-10-23 16:00:43


 You do realize that the entire point of this article is that php-mssql is not available in the default yum repositories?

From: ifatreee at: 2010-03-22 16:29:08

  I've had to use your instructions a couple of times now (thanks, BTW!) and this is the one-liner I keep rewriting to do the rpmbuild dependencies.


"If you are asked for some dependencies, just yum install them":


rpmbuild -bb ./php.spec 2>&1|grep 'is needed'|awk '{print $1}'|while read n; do yum -y install $n; done


 Hopefully someone else will find that useful when they're presented with a list of 25 things to install. ;)

From: jackocnr at: 2010-05-11 17:23:40

Not sure if the article is useful for some other reason - some other constrained set of circumstances, but this quick solution worked for me, thanks!

From: mchaney at: 2010-10-29 10:49:26

Ok, I have had/Still having some issues with the guide and thought I would add my comments and changes:.

1.) # Grab your specific RPM and install it:

rpm --install rpmforge-release-*.rpm

Failed for me with a 404 cant find error.

What I actually had to do was to install the actual correct package. I got this from:

Once I had downloaded the correct release and it installed I could proceed.

2.) # yum install php-devel

Failed for me due to dependancy. What it actually turned out was that I had a non standard centos installation of PHP. I then found this forum:

And followed the link and the guide that can be found at :

(Basically create a file /etc/yum.repos.d/utterramblings.repo and in it put:

name=Jason's Utter Ramblings Repo


This then installed/yum installed the php-devel ok.

3.) # If you don't have the php.spec file, you can download the php src rpm.

vi /usr/src/redhat/SPECS/php.spec

I dont have that php.spec file and the link for the wget fails with a 404 error.

Instead I took off the file extension and went to

And found the php.src file that way instead. I then did the rpm install (note its not -install but --install (two dashes)). My php.spec file then appeared.

4.) # Start building your php rpm:

rpmbuild -bb ./php.spec

Failed because I didnt read the comment about adding %package mssql.

5.)  # If you are asked for some dependencies, just yum install them.

make sure you do the

rpmbuild -bb ./php.spec 2>&1|grep 'is needed'|awk '{print $1}'|while read n; do yum -y install $n; done


from the comment as there are loads of dependancies.


However I then had to build the php.spec file again with

rpmbuild -bb ./php.spec

6.) My modules for are in usr/lib/php/modules. My php.ini is in etc/php.ini.


I restarted my apaches server and went to phpinfo and...........................


It now supports code no longer says invalid function/unknown function


Ok, it cant actually connect to the db or server yet, but one step at a time.

From: Leonardo at: 2011-05-18 01:00:54

Hi, I have problem in this line:

rpmbuild -bb ./php.spec

 Show me this error:

Bad exit status from /var/tmp/rpm-tmp.60284 (%build)

Each time that I execute this command rpm... The number error is diferent.