Installing The PHP-MSSQL Module On CentOS 5.0

Want to support HowtoForge? Become a subscriber!
 
Submitted by thim (Contact Author) (Forums) on Fri, 2007-06-08 16:52. :: CentOS | PHP

Installing The PHP-MSSQL Module On CentOS 5.0

Author & Content by Tim Haselaars (http://www.trinix.be)

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): http://dag.wieers.com/rpm/packages/rpmforge-release/

Grab your specific RPM and install it:

wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-*.rpm
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.

wget centos.mirrors.skynet.be/pub/centos/5/os/SRPMS/php-5.1.6-5.el5.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:

phpize
./configure --with-mssql
make
make install

Next look for the mssql.so 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:

extension=mssql.so

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.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by mchaney (not registered) on Fri, 2010-10-29 11:49.

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:

wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-*.rpm
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:

http://www.rpmrepo.org/RPMforge/Using

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:

https://www.centos.org/modules/newbb/viewtopic.php?viewmode=flat&topic_id=27460&forum=38

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

http://www.jasonlitka.com/yum-repository/

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

[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

)

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 http://centos.mirrors.skynet.be/pub/centos/5/os/SRPMS/

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 mssql.so 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 mssql....my 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.
Submitted by ifatreee (not registered) on Mon, 2010-03-22 17:29.
  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. ;)
Submitted by Vikram Ghotgalkar (not registered) on Wed, 2009-07-29 08:59.
1. Install php-mmsql module using yum

yum install php-mssql

2. Add the following line to php.ini

extension=mssql.so

3. Restart Apache

/etc/init.d/httpd restart

 

:)

Submitted by jackocnr (not registered) on Tue, 2010-05-11 18:23.
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!
Submitted by Anonymous (not registered) on Fri, 2009-10-23 17:00.

Vikram,

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

Submitted by camilord (not registered) on Wed, 2009-05-06 07:31.
is it possible both mysql and mssql are in centos 5.x ?
Submitted by Leonardo Bonilla (not registered) on Sun, 2008-11-16 23:53.

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

Regards

 Leonardo

Submitted by Hugh MacMullan (not registered) on Thu, 2009-12-17 17:12.

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!

Submitted by Leonardo (not registered) on Wed, 2011-05-18 02:00.

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.