Recompile php with mcrypt

From SlackWiki
Revision as of 21:33, 6 June 2009 by Erik (talk | contribs) (Copy from old, had no category, placed in Tutorials)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PhpMyAdmin (available at SlackBuilds.org) works well when you compile PHP with the mcrypt extension. After installing PhpMyAdmin, you may see a warning that it cannot find the mcrypt extension. Unfortunately the official Slackware package does not include this extension. Recompiling PHP is necessary, as is enabling the mcrypt.so extension in /etc/httpd/php.ini. The first step is a little tricky, since compiling PHP requires a little trick: you must compile alpine during the PHP build. It is fairly simple once you have things in place, but this tripped me up when I first tried to recompile PHP.

Install mcrypt and libmcrypt

mcrypt is available from SlackBuilds.org. First build and install mcrypt and libmcrypt before compiling PHP.

Recompile PHP

Go to a Slackware mirror and download Pat's Slackbuild directory for php from the source/n directory. I used

wget --mirror <mirror>/n/php

to download the whole directory. You will also need to download the alpine/ directory into the parent of the newly-created php/. In other words, you should have a parent directory with both php and alpine. For example, mine is ~/SlackBuilds/n, where I have two subdirectories: one for alpine/ and one for php/.

Be sure to chmod +x both the alpine and php SlackBuilds before attempting to build. If you don't, things may go for quite a while depending on the speed of the machine you're building on before you get an error (and you will get an error).

Edit php.SlackBuild

You will need to add a "--with-mcrypt=" flag to the configure command in php.SlackBuild. Since you already have mcrypt installed, you can use

--with-mcrypt=`which mcrypt`

Remember to add the slash at the end of the line. I positioned this flag second to the bottom. The position of the flag only matters for your ability to find it next time, order will not affect the build process. SlackBuilds customarily have the "--build=" flag at the bottom, so I left it where it was.

Upgrade PHP

Install the new package with upgradepkg. Keep in mind that you will need to repeat this process whenever there is a security alert for php. In that case, download the new source, update the VERSION variable, recompile and upgrade. For this reason, I've kept ~/SlackBuilds/n the way it is with alpine and php subdirectories.

Configure PHP

Configuring PHP to use mcrypt is easy: add the line

extension=mcrypt.so

to /etc/httpd/php.ini and then restart apache. Now when you log in to PhpMyAdmin, you should no longer see the warning about mcrypt.