Installing custom PHP with GMP

software development

#1

Hello,

I have had trouble trying to install my own PHP with the GMP library.

I used the script here http://wiki.dreamhost.com/Installing_PHP5 and added the various bits for GMP. But it would always die:

Configuring extensions
[…]
checking for GNU gettext support… no
checking for GNU MP support… yes
configure: error: Unable to locate gmp.h

According to Dreamhost support, it’s not the process watcher killing it off, and… here I am. :confused:

Any ideas?? I can post the script if that’s useful.

thanks in advance!


#2

It’s really quite simple actually, and that error explains it all.
You need to have the GNU MP library (GMP) installed before you can install support for it in PHP. Apparently DH’s servers do not have GMP installed by default, so you’d have to compile it into your user environment first.

Hopefully that helps :wink:


#3

Here is the script I was using. (I cut out everything except GMP and PHP.) Is it not attempting to install GMP first?

==================
#!/bin/sh

Save the code to a file as *.sh

Abort on any errors

set -e

The domain in which to install the PHP CGI script.

export DOMAIN=…

Where do you want all this stuff built? I’d recommend picking a local

filesystem.

Don’t pick a directory that already exists! We clean up after

ourselves at the end!

SRCDIR=${HOME}/source

And where should it be installed?

INSTALLDIR=${HOME}/php5

Set DISTDIR to somewhere persistent, if you plan to muck around with this

script and run it several times!

DISTDIR=${HOME}/dist

Pre-download clean up!!!

rm -fr $SRCDIR $DISTDIR

Update version information here.

PHP5="php-5.2.0"
GMP=“gmp-4.2.1”

What PHP features do you want enabled?

PHPFEATURES="–prefix=${INSTALLDIR}
–with-gmp"

---- end of user-editable bits. Hopefully! ----

Push the install dir’s bin directory into the path

export PATH=${INSTALLDIR}/bin:$PATH

#setup directories
mkdir -p ${SRCDIR}
mkdir -p ${INSTALLDIR}
mkdir -p ${DISTDIR}
cd ${DISTDIR}

Get all the required packages

wget -c http://us3.php.net/distributions/${PHP5}.tar.gz
wget -c http://ftp.sunet.se/pub/gnu/gmp/${GMP}.tar.gz

echo ---------- Unpacking downloaded archives. This process may take
several minutes! ----------

cd ${SRCDIR}

Unpack them all

echo Extracting ${PHP5}…
tar xzf ${DISTDIR}/${PHP5}.tar.gz
echo Done.
echo Extracting ${GMP}…
tar xzf ${DISTDIR}/${GMP}.tar.gz
echo Done.

Build them in the required order to satisfy dependencies.

gmp

cd ${SRCDIR}/${GMP}
./configure --prefix=${INSTALLDIR}

make clean

make
make install

#PHP 5
cd ${SRCDIR}/${PHP5}
./configure ${PHPFEATURES}

make clean

make
make install

#copy config file
mkdir -p ${INSTALLDIR}/etc/php5/${DOMAIN}
cp ${SRCDIR}/${PHP5}/php.ini-dist ${INSTALLDIR}/etc/php5/${DOMAIN}/php.ini

#copy PHP CGI
mkdir -p ${HOME}/${DOMAIN}/cgi-bin
chmod 0755 ${HOME}/${DOMAIN}/cgi-bin
cp ${INSTALLDIR}/bin/php ${HOME}/${DOMAIN}/cgi-bin/php.cgi
rm -fr $SRCDIR $DISTDIR
echo ---------- INSTALL COMPLETE! ----------


#4

Ah, well indeed you are installing GMP, but you have to inform PHP of it’s install location as well.
You can check for all the specific config options by running:

(after you unpack the gmp source that is)

But specifically, you’ll need to either point gmp to the same library location that PHP will be using, or let PHP know where this is when you got to configure it.
For instance, let’s say I installed GMP’s libraries, using the

option. You’d let PHP know the location of GMP’s libraries then by specifying something like this:

This in essence tells PHP where to look for GMP’s libraries.


#5

aha, you are awesome! thanks so much!


#6

No problems :wink:


#7

Just an FYI for future visitors since this comes up top-of-Google for “gmp DreamHost”, the shared hosts now include gmp. All I needed to do was add “extension = gmp.so” to my phprc file.

See http://wiki.dreamhost.com/PHP.ini for those instructions.