Adding a PHP Extension

Ryan Schmidt ryandesign at macports.org
Sat Jan 1 18:38:40 PST 2011


On Dec 27, 2010, at 18:05, Tim Roberts wrote:

> Caveat: I'm not a unix guru.  Barely a server admin.  We use Mac OS X Server because it 'just works'.  I manage the server via the Server Admin GUI.

Then the following may be a lot of information for you, and not what you want to hear...


> We hired a contractor to build a new website for us using Expression Engine.  The site is complete and running on the developer's server.  It is time to transfer it to our server - Mac OS X Server 10.6.4. The developer hit a snag because the mcrypt php extension is non-existant.
> 
> My goal is to add the mcrypt extension to php so we can complete the installation.
> 
> After a bunch of Google research, I learned that mcrypt is not bundled with the default Mac OS X server build of php.  I gather that I need to rebuild php (gulp!)  I also learned that MacPorts was a tool that I could use to simplify this process.  So...

MacPorts is designed to be self-contained and not interfere with nor make use of software provided by Apple as part of Mac OS X.

You can install php5's apache2 server module using MacPorts, but it is only designed to be used with the apache2 that is installed by MacPorts, not the apache2 that is provided as part of Mac OS X or Mac OS X Server.

To use MacPorts apache2, you'll be starting, stopping and configuring it manually, or at least, not using any of the graphical server administration tools provided by Apple in Mac OS X Server. So this may not be what you want.


> Last night, I installed MacPorts.  Using MacPorts, I subsequently installed mcrypt.  That process installed libmcrypt and mhash.  Stopped and restarted Apache.  Loaded info.php via a browser.  Still no mcrypt.

Understandable, since you only installed the mcrypt library, and not the php5 mcrypt module that would make that library available to php5.


> Today, I used MacPorts to install php5-mcrypt.  That installed a bunch of things including apache2 (which, of course, I already have).  Scary.  Stopped and restarted apache.  Still no mcrypt.

Ok, now you've installed MacPorts apache2, php5, and the php5 mcrypt module, but when you say you "stopped and restarted apache" I imagine you're talking about the apache2 provided by Mac OS X Server, which of course doesn't know anything about the modules installed by MacPorts for use with MacPorts apache2.


> I'm enclosing what was displayed in the terminal window from today's episode.
> 
> The following two notes are bothering me:
> Note: apache2 installs files outside the common directory structure.
> Note: php5 installs files outside the common directory structure.
> 
> Does this mean that I have somehow polluted the default apache and php installations?

It means that these ports install files outside the common directory structure prescribed for by MacPorts ports to use, and that the ports intend to do that. The apache2 port installs its files into /opt/local/apache2; this is a non-standard location, therefore the warning. php5 +apache2 must also install into that location, because that is where MacPorts apache2 looks for modules.


> What does this mean:

It means exactly what it says. It's telling you some steps you may need to perform in order to set up your MacPorts php5 for use with your MacPorts apache2 server for the first time.

> To customize php, copy /opt/local/etc/php5/php.ini-development (if this is a development server) or /opt/local/etc/php5/php.ini-production (if this is a production server) to /opt/local/etc/php5/php.ini and then make changes.

php.ini is php5's settings file. There are hundreds of options that you can specify. They are well documented within that file and on the php web site. You can either do nothing -- create no php.ini file -- and let php5 use its built-in defaults. Or you can copy one of the provided template php.ini files -- the development or the production template, depending on which is closest to your needs -- and then modify the copy as desired. Or you can create a php.ini completely from scratch if you prefer.

> If this is your first install, you need to activate PHP in your web server.
> To enable PHP in Apache, run cd /opt/local/apache2/modules /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so


This is one command you may need to run to tell your MacPorts apache2 that it should load your MacPorts php5 module. You may also need to edit your httpd.conf in ways not specified by the above messages. You may wish to consult the relevant section of the MAMP how-to wiki page for further information if in fact you do wish to switch to using MacPorts apache2.

https://trac.macports.org/wiki/howto/MAMP

These instructions are written for Mac OS X users; users of Mac OS X Server may need to make some adjustments. They also tell you about setting up MacPorts mysql5; if you don't use MySQL, you can ignore this; if you're using Mac OS X Server's included MySQL server, there may be differences again.


> I don't understand the big picture.  It appears everything that MacPorts does is contained in the /opt directory?  I'm obviously missing something that would be obvious to a "guru".   I would appreciate any insight.


The big picture is that MacPorts is designed to be separate from other software already on your Mac, so your desire to integrate MacPorts-installed software (php5 and its mcrypt module) with something already on your machine (apache2 as provided by Mac OS X Server) is problematic.

Yes, MacPorts is by default mostly contained within the /opt/local directory.

You can try what others have recommended -- copying the MacPorts-generated php5 Apache module into the place where Mac OS X's Apache looks for modules -- but this is not a supported configuration and is not guaranteed to work.

A request to provide an option in the php5 port to let it compile directly for the apache2 provided by Mac OS X Server would probably fall under this existing ticket:

https://trac.macports.org/ticket/14001

But I haven't yet done anything about that.




More information about the macports-users mailing list