I had a need to connect to MSSQL using PHP version 5 from a CentOS 5 server. To do this I needed FreeTDS and the module mssql in PHP. After a diligent search I found that there was no quick and easy way to install the mssql module, like “up2date install php-gd” to get GD to work from PHP.
I found a few places that had ideas and hints to make this work, but finally used the directions I found at http://www.howtoforge.com/installing_php_mssql_centos5.0 (slightly altered to fit my means) and will duplicate here so I can easily find it later.
At first I thought I needed to recompile PHP, but as it turned out I only needed to pre-compile it so that I could fetch the mssql.so, and then manually edit the php.ini to use it.
NOTE-1: You should be running as SuperUser or using sudo to perform these tasks.
NOTE-2: RPMForge was installed and running on my system, so I didn’t need to do the next couple of steps.
1. First you need to activate the RPMForge custom repository (formely known as Dag Wieers):
http://dag.wieers.com/rpm/packages/rpmforge-release/
2. Grab your specific RPM and install it:
wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-*.rpm
rpm --install rpmforge-release-*.rpm
3. 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
4. Next we alter the php.spec file, which contains the php configuration for compiling.
vi /usr/src/redhat/SPECS/php.spec
5. If you don’t have the php.spec file, you can download the php src rpm.
wget centos.mirrors.skynet.be/pub/centos/5/os/SRPMS/php-5.1.6-5.el5.src.rpm
rpm –install php-5.1.6-5.el5.src.rpm
6. And then do an updatedb and locate php.spec.
7. Edit the CFLAGS= line (~line 363) 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.
8. Start building your php rpm:
rpmbuild -bb ./php.spec
NOTE: If you are asked for some dependencies, just yum install them. I was asked for the following list of dependencies:
bzip2-devel, curl-devel, db4-devel, expat-devel, gmp-devel, aspell-devel, httpd-devel, libjpeg-devel, libpng-devel, pam-devel, openssl-devel, sqlite-devel, zlib-devel, pcre-devel, krb5-devel, libc-client-devel, cyrus-sasl-devel, openldap-devel, mysql-devel, postgresql-devel, unixODBC-devel, libxml2-devel, net-snmp-devel, libxslt-devel, libxml2-devel, ncurses-devel, gd-devel, freetype-devel, freetds-devel
9. Now you need to go to the place where the build is kept.
cd /usr/src/redhat/BUILD/php-5.1.6/ext/mssql/
10. Now we are going to make the mssql module without having to rewrite the php binary: (This takes a few minutes, relax.)
phpize
./configure --with-mssql
make
make install
11. Next look for the mssql.so file to make sure it is in the module directory “/usr/lib/php/modules/”, and specified in your php.ini. Or copy it to the specified location if needed.
12. Final Steps
vi /etc/php.ini
13. Add the following to the php.ini
extension=mssql.so
14. Save the php.ini using “:w!” or “Ctrl+ZZ” and restart Apache:
/etc/init.d/httpd restart
All should work now.
Comments
One response to “Adding mssql capability to PHP5 on CentOS”