OpenSSL support in PHP under MAMP

I recently started using a Mac for web development (I don't love it but that's another story). At the recommendation of several friends I'm using MAMP instead of the native Apache, PHP, and MySQL; they said it was much easier to set up. Yesterday, I discovered that MAMP's PHP install does not come with the OpenSSL extension so, for example, you cannot visit HTTPS sites from within PHP. Searching the web revealed several posts from people with the same problem but no solutions. I have no idea why MAMP does not ship with the openssl extension but, it turns out, it is very easy to create yourself. Here's how:

1. Build the PHP openssl extension (or, if you are really lazy, just download the one I built).

Download PHP from php.net. I'm using MAMP 1.6 (haven't bothered to upgrade) which uses PHP 5.2.1 which, it turns out, does not build properly on MacOS X 10.5 Leopard. So I used PHP 5.2.5 instead which works fine; this is also the version that MAMP 1.7 uses. Newer versions of 5.2 would probably also work.

Using Terminal, extract, configure, and build PHP, specifically requesting a *shared* openssl library:

% tar -xzf php-5.2.5.tar.gz
% cd php-5.2.5
% ./configure --with-openssl=shared
% make

2. Install the PHP openssl extension

From the same directory in which you ran make:

cp modules/openssl.so /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922/

The date in the final directory name will depend on which version of MAMP/PHP you have installed.

3. Edit /Applications/MAMP/conf/php5/php5.ini.

Search for lines that contain "extension=" and add the line

extension=openssl.so

That's it!

AttachmentSize
openssl.so80.46 KB

Comments

Actually you do not need to

Actually you do not need to build all of PHP to install any new PHP extensions into MAMP.

Just make sure that the following is in your path before /usr/bin "/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php5/bin" which can be done by

export PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php5/bin:$PATH

and then you can just cd to ext/openssl and then just do the following

phpize
./configure
make
make install

Just make sure that you are running the MAMP version of phpize which is in the MAMP directory and not the OS X one.

Gordon

You may want to check if

You may want to check if version 1.7 has ssl support. I'm using MAMP Pro, which does have the ssl module pre-installed, but it did cost approx $70. (I use it often enough to want to throw a little love towards MAMP's developers)

I suppose it is easier to set up MAMP, but if you're comfortable enough to be rolling your own modules, there are plenty of sites that would walk you through setting up a development environment. I stopped doing it once I got tired of installing newer versions of PHP and MySQL then what Apple provided... or overwrote... For me, using MAMP Pro was more about having a stable development environment that was easy to back up or move. And, easier management of virtual hosts...

Your mileage may vary... ;-)

This is the same technique

This is the same technique to use if you want to use memcache and MAMP as well. Only in that case, as it is a PEAR extension, you need to run phpize first, but otherwise it's to the letter the same.

Hey Barry, folks have been

Hey Barry, folks have been advising me to turn to a Mac for development purposes. I've honestly only ever used Windows PCs, so I'd be interested to know why you don't love. If you don't want to get into that on this post, I'd understand. I can try to catch you elsewhere. : )

Good to hear that you're

Good to hear that you're enjoying MAMP on the Mac.

I was considering using MAMP on my own laptop, but I didn't like the fact that it was crippleware. You might also consider looking at XAMPP for OS X - it includes SSL out of the box, and its control panel lets you start and stop SSL as one of its services, along with MySQL, PHP and FTP.

You can check it out at http://www.apachefriends.org/en/xampp-macosx.html .

-- Steven 'Sven' Merrill

APC, or any other pear/pecl

APC, or any other pear/pecl extension, will behave the same way too. So this is a pretty useful technique for building a local environment to mirror many of your production elements.

Personally, I think MAMP is

Personally, I think MAMP is a mess. I highly recommend MacPorts which brings Linux style package management to the mac.

sudo port install apache2 && sudo port install php5 +mysql5 +ssl

Great and very helpful

Great and very helpful post.

For IMAP support, in case anyone reading this has a need for it, check out this page: http://developers.sugarcrm.com/wordpress/2008/08/26/enabling-imap-suppor... (and my comment at the bottom, should be comment number 5)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <i> <h1> <h2> <h3> <blockquote>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Site-relative links such as <a href="node/123"> will work correctly.

More information about formatting options