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)