2

I am trying to install the mcrypt PHP extension on my OS X Mountain Lion 10.8 operating system. This OS comes shipped with Apache and PHP already installed. The mcrypt extension however does not come shipped with PHP. I want to install mcrypt into the version of PHP that came shipped with my machine.

I do not want to use Homebrew, Macports, or any similar package manager, and I do not want to install another version of PHP in addition to the one I already have. I just want to plug mcrypt into the PHP that came bunded with my OS. I feel like this makes sense, instead of having multiple versions of the same program installed, yet every tutorial I come across seems to all immediately say to use Homebrew/Macports, and the few that don't teach you how to install a new PHP instead of using the one I already have.

I started following the directions laid out on this page: http://www.coolestguyplanettech.com/how-to-install-mcrypt-for-php-on-mac-osx-lion-10-7-development-server/.

  1. I downloaded libmcrypt-2.5.8.tar.gz from Sourceforge.
  2. I extracted the contents with the following command: tar -zxvf libmcrypt-2.5.8.tar.gz.
  3. I entered the libmcrypt-2.5.8 directory that was created and issued the following commands: ./configure, make, and sudo make install.

Now that tutorial says to go into a directory that was created by a new, non-native version of PHP that the tutorial tells you to install, not the native version that came shipped with OS X. The tutorial says to go into the following directory: cd ../php-5.3.13/ext/mcrypt/ (which is a directory I don't have), and run the phpize command. I can't go into that directory because I'm using the native PHP that came with OS X, so instead I go into the libmcrypt-2.5.8 directory, but when I try to run the phpize command I get an error that says: Cannot find config.m4. Make sure that you run '/usr/bin/phpize' in the top level source directory of the module. I do however have the files acinclude.m4 and aclocal.m4 in this directory. I am not sure if they are related to the config.m4 that phpize is looking for.

I am not sure how to proceed. Maybe I should just cut my losses and install another PHP using Macports or Homebrew, but I'd really prefer to use the native PHP that came bundled with OS X. Can you help me figure out how to do this? It would really help me a lot, and help me understand better how PHP and extensions work. Thank you!

1 Answer 1

1

"I'd really prefer to use the native PHP that came bundled with OS X. Can you help me figure out how to do this? It would really help me a lot, and help me understand better how PHP and extensions work."

The PHP that came bundled with OSX isn't any more "Native" than any other version that you would install.

You don't have that directory because, IIRC, OSX doesn't ship with PHP source, just a compiled binary and apache module.

You can only run phpize on a php extension, which you can get in the PHP source download (including the mcrypt extension). What you downloaded is the C library (which you may also need to install) that the PHP extension will reference (you don't need to worry about how this happens).

If you want to just install that extension:

  1. Download it

  2. Extract and cd into

  3. sudo phpize

  4. sudo ./configure && sudo make && sudo make install

  5. Add extension=mcrypt.so (or whatever is generated) to your php config / php.ini and restart apache

This sounds to me like a good opportunity to learn more about how your computer works. This is some documentation I wrote for myself a few years ago on how to do this:

http://www.calvinfroedge.com/common-php-compile-configuration-options/ (note that the formatting in the blog might not work if you paste it into terminal, for example –with-mysql should be --with-mysql)

Besides, you don't need to get rid of your PHP installation that came with OSX. You can download the PHP source to a brand new directory, compile it, backup the old binary, and either symlink the result of 'which php' to your new installation or add the binaries that get generated after you compile to your source.

Sign up to request clarification or add additional context in comments.

8 Comments

1. Download it - Download what? Apparently the libmcrypt-2.5.8 that I downloaded is the C library... I didn't see a config.m4 in that directory when I extracted the tar.gz archive, which makes phpize fail. So do I need to download a different file for the mcrypt extension?
php.net/downloads.php You want the one that matches your PHP version. The mcrypt extension will be in the ext folder.
Here is a direct link to php mcrypt: github.com/php/php-src/tree/master/ext/mcrypt
Just make sure you get the same version that you've got installed on your system. Pay attention to the messages when you try to install - that will tell you what to do next.
I just installed the PHP source files and cd into the ext/mcrypt directory and ran phpize. A bunch of new files were created but not mcrypt.so. So I executed sudo ./configure which works fine, but sudo make yields an error.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.