Link to home
Start Free TrialLog in
Avatar of phirschybar
phirschybar

asked on

Installing mhash to use with php

Hello all,

I need to integrate my shopping cart with authorize.net using their SIM (simple integration method). This requires that I use the mhash function which unfortunately is not available in php on my server. Based what what I have gathered from various sources, including here, I need to recompile php with mhash. Is this correct? If so, could anyone please give me a "step-by-step" instruction on how to do this while maintaining the same basic configuration I have now (in other words, just adding the mhash). I am a linux nOOb. :)

I am on a Media Temple server running Red Hat Enterprise 3 and Sw-Soft's Plesk 7.5.2 in an "out of the box" configuration. I have php 4.3.2 installed.

My phpinfo() page: https://o-secure.com/php_test.php

Thanks for anything in advance!!!
Avatar of idmisk
idmisk
Flag of Austria image

1. download one of the rpms  from
http://rpm.pbone.net/index.php3?stat=3&search=php-mhash&srodzaj=3 
or
http://rpmfind.net/linux/rpm2html/search.php?query=php-mhash&submit=Search+...
(not sure that subversion your have)

2. another way is to recompile it:

download libmhash from http://dag.wieers.com/packages/libmhash/ and install it,
as alternative you can build the packge self by downloading the sources and the spec file (only if you know ow to do it).

download php-4.3.2 sources from php.net
as user, not root:
unpack it to some directory
./configure --prefix=/tmp/php-mhash --with-mhash=shared
make
su -
cd php-4.3.2
make install-modules
cd /tmp/php-mhash

some dirs below you will find mhash.so, copy it your extension dir (/usr/lib/php....)

make "updatedb && locate php.d' if no result then open your php.ini and add  
extension=mhash.so

restart apache
Avatar of phirschybar
phirschybar

ASKER

I'm sorry, I am completely new to this. I know how to SSH into my server and use 'su' to act as root but I don;t fully follow your instructiuons.

You said:  1. download one of the rpms...

What do I do with an rpm after downloading it? Where should I download it to? What directory? Does it matter?

You said: download libmhash from http://dag.wieers.com/packages/libmhash/ and install it

I don't know how to install it.

I assume these methods are installing the mhash component and then the rest of your instructions are for essentially re-installing php with mhash?
login into your system and do:
rpm -qa | grep php

please post the output here (need to know what php packages are installed now)
Output:

php-imap-4.3.2-19.ent.swsoft
php-odbc-4.3.2-19.ent.swsoft
php-mysql-4.3.2-19.ent.swsoft
php-ldap-4.3.2-19.ent.swsoft
php-pgsql-4.3.2-19.ent.swsoft
php-4.3.2-19.ent.swsoft
try this:

su - root
cd /tmp
wget http://dag.wieers.com/packages/libmhash/libmhash-0.9.1-1.rhel3.dag.i386.rpm
rpm -iv libmhash-0.9.1-1.rhel3.dag.i386.rpm
wget ftp://rpmfind.net/linux/sourceforge/p/ph/phprpms/php-mhash-4.3.2-19.ent.2.i386.rpm
rpm -iv php-mhash-4.3.2-19.ent.2.i386.rpm

post the output here please
Hmmm.

I downloaded the first file OK. and then I got this error after the rpm command:

warning: libmhash-0.9.1-1.rhel3.dag.i386.rpm: V3 DSA signature: NOKEY, key ID 6b8d79e6
error: cannot get exclusive lock on /var/lib/rpm/Packages
error: cannot open Packages index using db3 - Operation not permitted (1)
error: cannot open Packages database in /var/lib/rpm
wait. sorry, I forgot to su first... one sec.
[root@as tmp]# rpm -iv libmhash-0.9.1-1.rhel3.dag.i386.rpm
warning: libmhash-0.9.1-1.rhel3.dag.i386.rpm: V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing packages for installation...
libmhash-0.9.1-1.rhel3.dag

[root@as tmp]# wget ftp://rpmfind.net/linux/sourceforge/p/ph/phprpms/php-mhash-4.3.2-19.ent.2.i386.rpm
--16:19:05--  ftp://rpmfind.net/linux/sourceforge/p/ph/phprpms/php-mhash-4.3.2-19.ent.2.i386.rpm
           => `php-mhash-4.3.2-19.ent.2.i386.rpm'
Resolving rpmfind.net... done.
Connecting to rpmfind.net[195.220.108.108]:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD /linux/sourceforge/p/ph/phprpms ... done.
==> PASV ... done.    ==> RETR php-mhash-4.3.2-19.ent.2.i386.rpm ... done.
Length: 6,410 (unauthoritative)

100%[================================================>] 6,410         15.05K/s    ETA 00:00

16:19:10 (15.05 KB/s) - `php-mhash-4.3.2-19.ent.2.i386.rpm' saved [6410]

[root@as tmp]# rpm -iv php-mhash-4.3.2-19.ent.2.i386.rpm
Preparing packages for installation...
php-mhash-4.3.2-19.ent.2
Stopping httpd: [  OK  ]
Starting httpd: [  OK  ]
everything should be fine now

check your https://o-secure.com/php_test.php

mhash
MHASH support       Enabled
MHASH API Version       20020524
Thanks so much for walking me through this.

hmm.. Yes, it appears in the php info page. But, on the page that is using the function, it appears to be quitting at the hash functions. Doesn't give an error message though, it just quits. The function it fails on is here:

function hmac ($key, $data){
   return (bin2hex (mhash(MHASH_MD5, $data, $key)));
}

Any ideas? Do we not have support for this?
lets first test if mhash is working. make a test.php file with this content and then access it:

<?php
$input = "some test string";
$hash = mhash (MHASH_MD5, $input);
print "hash is ".bin2hex ($hash)."\n&lt;br>";
$hash = mhash (MHASH_MD5, $input, "Jefe");
print "hmac is ".bin2hex ($hash)."\n&lt;br>";
?>

second clue: open /var/log/httpd/error_log and check what was one of the last entries.
hmm. ok with the test script I get this asa output:

hash is 00000000000000000000000000000000 <br>hmac is 00000000000000000000000000000000 <br>

And in the error_log there are a bunch of lines like this:

[Tue Jun 07 18:10:54 2005] [notice] child pid 8131 exit signal Segmentation fault (11)
[Tue Jun 07 18:11:35 2005] [notice] child pid 7840 exit signal Segmentation fault (11)
[Tue Jun 07 18:11:39 2005] [notice] child pid 4469 exit signal Segmentation fault (11)
this is bad, then this mean the module is not working

let's see if this mhash will help
cd /tmp
wget http://heanet.dl.sourceforge.net/sourceforge/phprpms/mhash-0.9.1-2.i386.rpm
rpm -iv mhash-0.9.1-2.i386.rpm

if it fails

rpm -e libmhash
rpm -iv mhash-0.9.1-2.i386.rpm
Removing it appears to have failed:

# rpm -e libmhash
error: Failed dependencies:
        libmhash.so.2 is needed by (installed) php-mhash-4.3.2-19.ent.2
ok, then:

cd /tmp
rpm -e php-mhash
rpm -e libmhash
rpm -iv mhash-0.9.1-2.i386.rpm
rpm -iv php-mhash-4.3.2-19.ent.2.i386.rpm

and then try again test.php
Same output:

hash is 00000000000000000000000000000000 <br>hmac is 00000000000000000000000000000000 <br>
Thanks for hanging with me on this. I will need to be leaving in 15 minutres but will be back an houror so later. Will you still be around in an hour and a half? What time zone are you in?
ok. they only way now is to rebuild it. are you able to install additional software on your system?

gmt +1 :)

so in one hour i am sleeping ... no i think earlier ... in 15 minutes
I beleive so, it a Virtual Dedicated Server and I have root access so i don't see why not. Are we diving into something very comprehensive? Also, I don't want to risk much downtime on the system, is that possible?
ok.. I gotta run. Thanks again. Please leave any additional instructions. Will you be around tomorrow? I will up and running at 6am (GMT -5). THANKS!!!
we need to compile it, so compiler and libraries are required. we will not destroy anything, because most of the step are done as user not root.
before we proceed i suggest to do following now:

the main problem is that you are using php release from plesk company
so go to http://forum.sw-soft.com/ and search for mhash
if your dont find anything ask there if someone already has a package (provide the output of rpm -qa ....)

there is also another way, but i dont like to do it, cause i don't know what problems it may cause.
the second solution: drop php from sw-soft and install it from scratch. again: not a good idea.
OK.

I did some research on mhash on Plesk. Apparently this guy at http://www.atomicrocketturtle.com/ is making all of the RPMs to work with Plesk.

His packages are explained here:
http://www.atomicrocketturtle.com/modules.php?op=modload&name=Sections&file=index&req=viewarticle&artid=7&page=1

And the listings here:
http://3es.atomicrocketturtle.com/packages/

I see mhash available here! However, I am not sure if this means I need php 4.3.9+ for this to work?

I figured I would attempt to install the RPMs like we did above but I decided to see what you had to say about it first. I don't know if this package will work with my setup...

I will be back around Noon your time. Thanks again for your help! Can I give you more than 500 points for all this? :)
> I will be back around Noon your time.
took a bit longer, had to complete some exams first.

> Apparently this guy at http://www.atomicrocketturtle.com/ is making all of the RPMs to work with Plesk.
here is the same problem - recompilation is required. then i found only source rpm's (.srpm). have i missed something?

i still suggest to compile only this mhash module and not touch anything what is already installed.
can you please check if your provider provided you some sources where you can get additional redhat EL packages.

lets try it, please do all steps as some user, not root:
cd /tmp
wget http://museum.php.net/php4/php-4.3.2.tar.gz
tar xzf php-4.3.2.tar.gz
./configure --prefix=/tmp/php-mhash --with-mhash=shared

please post 3-5 last lines of the output
I just got:

./configure: No such file or directory

With the configure command.
Can someone please help to finish this off? I need to get mhash running properly for a project... havent heard back from idmisk even though he has been EXTREMELY helpful (thanks idmisk!!). Seems we just have a few steps to go... I will split points with whoever helps finish this.
still here :) sorry i am a bit busy atm.

here again (now without missing line):
cd /tmp
wget http://museum.php.net/php4/php-4.3.2.tar.gz
tar xzf php-4.3.2.tar.gz
cd php-4.3.2
./configure --prefix=/tmp/php-mhash --with-mhash=shared

please post last 3-5 lines

----- ignore below this line for now
make
su -
cd /tmp/php-4.3.2
make install-modules
cd /tmp/php-mhash
output from above:

# ./configure --prefix=/tmp/php-mhash --with-mhash=shared
creating cache ./config.cache
checking host system type... i686-pc-linux-gnu
Updated main/php_version.h
checking for gcc... no
checking for cc... no
configure: error: no acceptable cc found in $PATH
do you already know where you can get additionl packages for your installation? do you provider provides some update service or can you install packages with up2date?

to test do:
up2date gcc
Output:

up2date: command not found

hmm...
Sorry if I am a bonehead, I simply don't know this stuff...

Someone on the Plesk forum indicated that I can install the ART RPM's. Please see this thread:
http://forum.sw-soft.com/showthread.php?s=&threadid=24635&highlight=mhash

ASKER CERTIFIED SOLUTION
Avatar of idmisk
idmisk
Flag of Austria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
idmisk,

thanks for your continued support. If I could give you 5000 points for the help I would.

It seems that people vouch for the ART RPMS. Even a Plesk administrator advised that we do this. So I think we should go with #2.
wget http://linux.duke.edu/projects/yum/download/2.0/yum-2.0.8-1.noarch.rpm
rpm -ihv yum-2.0.8-1.noarch.rpm

open /etc/yum.conf and add following lines:

[atomic]
name=Atomic Rocket Turtle - $releasever - Atomic PSA-Compatible RPMS
baseurl=http://3es.atomicrocketturtle.com/atomic/art/$releasever/
baseurl=http://www.atomicrocketturtle.com/atomic/art/$releasever/

[psa-7.5]
name=Atomic Rocket Turtle - $releasever - SW-Soft PSA 7.5 RPMS
baseurl=http://3es.atomicrocketturtle.com/atomic/psa-7.5/$releasever/
baseurl=http://www.atomicrocketturtle.com/atomic/psa-7.5/$releasever/

comment/delete these lines:

[base]
name=Red Hat Linux $releasever - $basearch - Base
baseurl=http://mirror.dulug.duke.edu/pub/yum-repository/redhat/$releasever/$basearch/

[updates]
name=Red Hat Linux $releasever - Updates
baseurl=http://mirror.dulug.duke.edu/pub/yum-repository/redhat/updates/$releasever/


then

yum install php php-mysql php-imap


Output:

# rpm -ihv yum-2.0.8-1.noarch.rpm
warning: yum-2.0.8-1.noarch.rpm: V3 DSA signature: NOKEY, key ID 69886cc7
error: Failed dependencies:
        libxml2-python is needed by yum-2.0.8-1
        rpm-python is needed by yum-2.0.8-1
alright.

- I installed libxml2-python
- I then tried to install rpm-python but it said I needed: 4.2.3-21_nonptl
- So I downloaded 4.2.3-21_nonptl and tried installing but it said I needed: popt = 1.8.2
- So I downloaded popt = 1.8.2 and tried installing but I got this output:

file /usr/include/popt.h from install of popt-1.8.2-21_nonptl conflicts with file from package popt-1.8-0.69.9.swsoft
file /usr/lib/libpopt.a from install of popt-1.8.2-21_nonptl conflicts with file from package popt-1.8-0.69.9.swsoft
file /usr/lib/libpopt.la from install of popt-1.8.2-21_nonptl conflicts with file from package popt-1.8-0.69.9.swsoft
file /usr/lib/libpopt.so.0.0.0 from install of popt-1.8.2-21_nonptl conflicts with file from package popt-1.8-0.69.9.swsoft

So, it seems that I am running myself into a corner.
install with
rpm -Fhv popt-......
rpm -Uhv popt-.....
no go. I got:

# rpm -Uhv popt-1.8.2-21_nonptl.i386.rpm
error: Failed dependencies:
popt = 1.8 is needed by (installed) rpm-4.2-0.69.9.swsoft

same with rpm -Fhv
this is better suited for someone at SW-Soft (Plesk) because of how they have this all set up. Thanks for all your help idmisk!!!
i hope they are able to help you. please post here again if they are not. good luck!
FYI --

It turned out that mhash was conflicting with the ldap library (?). So, removing that cleared up the issue.