Install the MSSQL module for PHP on CentOS 5

Posted in PHP -

Unfortunately there is no pre-built module/extension for MSSQL for PHP in the Yum repositories for CentOS 5, so you need to build it yourself. It's a reasonably simple process, but you do need to have gcc and php-devel packages already installed (and a whole bunch of others which I'll list at the end of this post).

I'm not going to bother rehashing someone else's guide for installing the MSSQL extension for PHP here, but will instead point you to the HowtoForge article which has the installation process which I followed myself. I will however point out a couple of points and a minor error in the howto guide below...

RPMForge custom repository file

The howto says to do this:

wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-*.rpm

but you don't actually want to run that command. You need to substitute the rpmforge-release-*.rpm part for the actual file. So go to http://dag.wieers.com/rpm/packages/rpmforge-release/ and look for the correct file for your version of CentOS and platform. For, example, I wanted the x86-64 one for CentOS 5, so I downloaded:

wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

Howto Forge Error

When I followed the Howto Forge installation guide to install the MSSQL module for PHP, linked to above, I got the following error message:

error: line XYZ: Package does not exist: %description mssql

The reason for getting this error is because of a minor error in the guide. The section in the guide that tells you to add some text to the php.spec file is missing this %package mssql so the whole block of text should actually look like this (I have bolded the text that is missing from the guide):

%package mssql
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.

Dependencies Issue

That fixed the "package does not exist" error, but I had package dependency issues instead as follows:

rpmbuild -bb ./php.spec
error: Failed build dependencies:
        bzip2-devel is needed by php-5.1.6-5.x86_64
        curl-devel >= 7.9 is needed by php-5.1.6-5.x86_64
        gmp-devel is needed by php-5.1.6-5.x86_64
        aspell-devel >= 0.50.0 is needed by php-5.1.6-5.x86_64
        libjpeg-devel is needed by php-5.1.6-5.x86_64
        libpng-devel is needed by php-5.1.6-5.x86_64
        pam-devel is needed by php-5.1.6-5.x86_64
        openssl-devel is needed by php-5.1.6-5.x86_64
        sqlite-devel >= 3.0.0 is needed by php-5.1.6-5.x86_64
        zlib-devel is needed by php-5.1.6-5.x86_64
        pcre-devel >= 4.5 is needed by php-5.1.6-5.x86_64
        krb5-devel is needed by php-5.1.6-5.x86_64
        libc-client-devel is needed by php-5.1.6-5.x86_64
        mysql-devel >= 4.1.0 is needed by php-5.1.6-5.x86_64
        postgresql-devel is needed by php-5.1.6-5.x86_64
        unixODBC-devel is needed by php-5.1.6-5.x86_64
        libxml2-devel is needed by php-5.1.6-5.x86_64
        net-snmp-devel is needed by php-5.1.6-5.x86_64
        libxslt-devel >= 1.0.18-1 is needed by php-5.1.6-5.x86_64
        libxml2-devel >= 2.4.14-1 is needed by php-5.1.6-5.x86_64
        ncurses-devel is needed by php-5.1.6-5.x86_64
        gd-devel is needed by php-5.1.6-5.x86_64
        freetype-devel is needed by php-5.1.6-5.x86_64

As you can see there are a number of packages that are required to compile the MSSQL extension for PHP, some of which are a little surprising. Depending on what you do or don't have already installed on your machine, and whether it's 32 bit, 64 bit or other, the list of packages missing will vary. It's simply a matter of copying the missing package names from the list and using yum to install them. In my example above I needed to do this:

yum install bzip2-devel curl-devel gmp-devel aspell-devel libjpeg-devel libpng-devel \
  pam-devel openssl-devel sqlite-devel zlib-devel pcre-devel krb5-devel libc-client-devel \
  mysql-devel postgresql-devel unixODBC-devel libxml2-devel net-snmp-devel libxslt-devel \
  libxml2-devel ncurses-devel gd-devel freetype-devel

64 bit FreeTDS libraries location

The one final error I encountered when installing the MSSQL module for PHP on CentOS5 was to do with the file locations of the FreeTDS libraries. I was installing this onto a 64 bit machine, and the installer was looking in the wrong location for the libraries. When running

./configure --with-mssql

I got the following error message:

checking for MSSQL support via FreeTDS... yes, shared
configure: error: Could not find /usr/lib/libtds.a|so

A quick updatedb and locate libtds.so revealed this:

/usr/lib64/libtds.so
/usr/lib64/libtds.so.5
/usr/lib64/libtds.so.5.0.0

The installer was expecting these files to be at /usr/lib and not /usr/lib64. I'm sure there may have been another way to change the configuration of where it was expecting these files to be, but I decided the quickest and easiest way was to just set up symbolic links from the real location to where the installer was expecting to find them like so:

cd /usr/lib
ln -s /usr/lib64/libtds.so
ln -s /usr/lib64/libtds.so.5
ln -s /usr/lib64/libtds.so.5.0.0

I was now able to install the MSSQL module no problems:

$ make install
Installing shared extensions:     /usr/lib64/php/modules/

$ ls -l /usr/lib64/php/modules/
total 3332
-rwxr-xr-x 1 root root  153904 Sep 21 02:07 dom.so
-rwxr-xr-x 1 root root  337544 Sep 21 02:07 gd.so
-rwxr-xr-x 1 root root  100792 Sep 21 02:07 imap.so
-rwxr-xr-x 1 root root 1863664 Sep 21 02:07 mbstring.so
-rwxr-xr-x 1 root root   37456 Jul 21 20:59 mcrypt.so
-rwxr-xr-x 1 root root  147707 Oct  3 12:43 mssql.so
-rwxr-xr-x 1 root root  117488 Sep 21 02:07 mysqli.so
-rwxr-xr-x 1 root root   53008 Sep 21 02:07 mysql.so
-rwxr-xr-x 1 root root   28296 Sep 21 02:07 pdo_mysql.so
-rwxr-xr-x 1 root root   92464 Sep 21 02:07 pdo.so
-rwxr-xr-x 1 root root   24232 Sep 21 02:07 pdo_sqlite.so
-rwxr-xr-x 1 root root  299280 Sep 21 02:07 soap.so
-rwxr-xr-x 1 root root   26096 Sep 21 02:07 xmlreader.so
-rwxr-xr-x 1 root root   38512 Sep 21 02:07 xmlwriter.so
-rwxr-xr-x 1 root root   28560 Sep 21 02:07 xsl.so



Comments