There are several things that can prevent you from successfully configuring and building the latest versions of PHP with the libmcrypt libraries. I found this out the hard way, spending several hours working on getting them to play nice. I found bits and pieces of the solution all over, but I couldn't find any unified document that told me how it should be done. I thought it would be nice for other people in a similar situation if I wrote something up to tell you how I finally got it working. So therefore below you will find the sequence of events that led me to successful configuration, compilation, and installation of PHP 4.0.1pl2 with support for the following:
MySQL (by default)
Postgresql 7.0.2 (--with-pgsql)
libmcrypt 2.2.7 (--with-mcrypt)
The full configuration directive is given a little further down. My system configuration was the following:
Linux Mandrake 7.1 (Hydrogen) on an Intel Celeron 400 based system
How to build PHP 4.0.1pl2 with mcrypt support
Created: 3:23 AM 7/7/00 by Jesse Scott (jscott@bmi.net)
Please note: I wrote this up from memory, and it was 3:30 in the morning so I may have made a mistake or 12. If you have trouble, feel free to e-mail me, but remember, I was only trying to be helpful. 🙂
Here is the procedure I followed for success:
If you haven't already, download the source distribution of PHP 4.0.1pl2 from "http://www.php.net/".
Download the source for libmcrypt 2.2.7 from "ftp://argeas.cs-net.gr/pub/unix/mcrypt/".
IMPORTANT! PHP currently will not compile with any other version of libmcrypt! The most recent version is 2.4.x I believe, but these versions will not work without modification to the mcrypt.c file in your PHP source tree. Even then results and function support are unpredictable. USE 2.2.7!!
- Unpack both files ( tar -xvzf filename.tar.gz).
! Everything from here on out was done as the superuser.
Enter the libmcrypt source directory.
Use the following configuration command:
fakeprompt# ./configure --disable-posix-threads
- When configure is done, you are ready to compile and install libmcrypt:
fakeprompt# make
COMPILATION OCCURS HERE
fakeprompt# make install
INSTALLATION OCCURS HERE
Alright, now time for PHP. Leave the libmcrypt source directory and enter the PHP source directory.
Simply add "--with-mcrypt" to your configuration line. Here is the config line I used:
fakeprompt# ./configure --with-pgsql --with-mcrypt --with-apxs=/usr/sbin/apxs
- When configure is done, compile and install PHP:
fakeprompt# make
COMPILATION OCCURS HERE
fakeprompt# make install
INSTALLTION OCCURS HERE
You will probably need to fix your httpd.conf file next. Down at the bottom where PHP added the LoadModule line for PHP4, give it the full path to find the libphp4.so module.
Next we need to put the mcrypt shared objects where PHP mistakenly expects them. The following command should do the trick:
fakeprompt# cp /usr/local/lib/libmcrypt.* /usr/lib
Basically, PHP expects all the .so's in /usr/lib, not in /usr/local/lib. So we just move them. If your distribution's file structure is different this may apply differently to you. Maybe not, but since I only did this in Mandrake (which basically uses Red Hat's file structure), I don't know if it is absolutly the same on other distros.
- Almost done, time to restart Apache. If you have apachectl you can first test the config:
fakeprompt# apachectl configtest
If all is good (or you don't have apachectl), go ahead and restart:
(with apachectl)
fakeprompt# apachectl restart
(without apachectl)
fakeprompt# cd /etc/rc.d/init.d
fakeprompt# ./httpd restart
Hopefully the restart is a success! If not, and you made it through all the other parts without a hitch, the error message that Apache gives you (and especially the line number if it's an httpd.conf problem) should be helpful in debugging the problem.