Installing PHP on Mac OS X

If you want to install PHP on Leopard please read these new instructions on my DIYMacServer.com blog which explains the differences in the installation procedures for Tiger and Leopard.

PHP logoTo install PHP on Mac OS X there are, just as with Apache, several options one could use. I’ve chosen the most simple setup that will get most PHP based applications running that we need for the mailserver and such.

You can start by downloading the source archive from www.php.net. I’ve used PHP version 5.1.4 for this compilation exercise. Extract the source archive into a directory and use the Terminal to execute the following commands. Please note the difference when having an Intel or PowerPC based Mac:

Note: Please remind yourself if you installed MySQL or Apache in a different manner than described in the previous pages compare the file paths in the configure command line to your paths.

For Intel:

CFLAGS="-arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk" \
./configure --prefix=/Library/PHP5 \
  --mandir=/usr/share/man \
  --infodir=/usr/share/info \
  --sysconfdir=/etc \
  --with-zlib \
  --with-xml \
  --with-zlib-dir=/usr \
  --with-openssl \
  --enable-exif \
  --enable-ftp \
  --enable-mbstring \
  --enable-mbregex \
  --enable-sockets \
  --with-mysql=/usr/local/mysql \
  --with-mysqli=/usr/local/mysql/bin/mysql_config \
  --with-apxs2=/Library/Apache2/bin/apxs

For PowerPC:

CFLAGS="-arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk" \
./configure --prefix=/Library/PHP5 \
  --mandir=/usr/share/man \
  --infodir=/usr/share/info \
  --sysconfdir=/etc \
  --with-zlib \
  --with-xml \
  --with-zlib-dir=/usr \
  --with-openssl \
  --enable-exif \
  --enable-ftp \
  --enable-mbstring \
  --enable-mbregex \
  --enable-sockets \
  --with-mysql=/usr/local/mysql \
  --with-mysqli=/usr/local/mysql/bin/mysql_config \
  --with-apxs2=/Library/Apache2/bin/apxs

For both:

make

sudo make install

If the install fails because of a PEAR error like:
[PEAR] Archive_Tar: commit failed
[PEAR] Console_Getopt: upgrade to a newer version (1.2 is not newer than 1.2)
warning: pear/PEAR dependency package “pear/Archive_Tar” installed version 1.1 is not the recommended version 1.3.1
[PEAR] PEAR: commit failed

You’ll need to upgrade the PEAR package on your machine. Save the script at http://go-pear.org/ to your desktop as go-pear.php and execute ’sudo php go-pear.php’. Just answer the questions when needed, most can be answered by just pressing the enter button. The most important one is to change the installation prefix from ‘/usr’ to ‘/Library/PHP5′ and that is it. Try to rerun the ’sudo make install’ in the PHP source directory and it should work.

After installation, please check if the your ‘httpd.conf’ has been updated for the PHP extension and if the module is being loaded. Your ‘httpd.conf’ file should have the following lines:

LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

Restart Apache and your ready to go.

As you might have seen from the ‘./configure’ settings, your ‘php.ini’ file will be located in ‘/etc’.

73 Responses to “Installing PHP on Mac OS X”

  1. Paul Magrath Says:

    ” –with-png-dir=/usr/local \” should be ” –with-png-dir=/usr/local \”.

    Also PEAR installation is failing during PHP5. It complains that Archive_Tar’s version & Console_gOut’s version are not greater than they are and aborts.

    Tried running “pear upgrade Archive_Tar” and was told that I was already running the most current version.

    Tried running “pear upgrade PEAR” and was told that “could not extract package.xml”

    But, it is working as you can see on my site so the errors aren’t a huge problem.

  2. Markis Says:

    I don’t know if you purposely left out “–enable-magic-quotes”, “–with-mcrypt=/Library/PHP5″, “–with-mhash=/Library/PHP5″, “–enable-soap”, “–enable-calendar”, “–with-pspell=/Library/PHP5″; but I think some of my programs won’t work without them. I also like to use the ming (Flash) and pdf modules to have the server create documents on the fly. I think some people would also like the IMAP modules. I’d like to see in the future some sort of caching engine like turck mmcache.

    Thanks for all your work on this.

  3. Jan Lehnardt Says:

    Hey,
    nice writeup!
    You might want to drop the libexpat dependency though. In PHP 5 everything XML is (supposed to be) handled by libxml2. The usage of other extensions for XML support in PHP 5 is sort of deprecated. The SAX API expat implemented in PHP 4 is now implemented by libxml2.

    Also, you might want to consider some configure options. –with-yp is usually not really needed. And, of course, the other options depend on the mini’s environment. As a rule of thumb: The less extensions are enabled, the smaller is the resulting binary and in turn the faster your mini can handle requests because it can stuff more processes into memory. (This is a bogus argument, if you don’t handle _A_LOT_ of requests, but then, it’s good practice to only run what is really needed).

    Keep it up and good luck with the mini :-)

    Jan

    Richard5: I agree with Jan so everything is adjusted accordingly.

  4. Paul Magrath Says:

    Great work! That tip about pear worked like a dream. I am however getting the following rather strange warning message in phpMyAdmin:

    “The mbstring PHP extension was not found and you seem to be using a multibyte charset. Without the mbstring extension phpMyAdmin is unable to split strings correctly and it may result in unexpected results.”

    Any ideas?

    Richard5: Just made a minor correction to the ./configure command, I added the line –enable-mbstring to it to make phpmyadmin work.

  5. Mark Says:

    Richard,

    I applaud your sharing your experiences. I started setting up HOWTOS for apps I use for the same reason you mentioned in “about me”. If I didn’t document what I did I couldn’t duplicate it later. One thing you might want to consider is joining the DarwinPorts team. DP is a package manager that builds from source. Using a package manager, you can push some of the instructions you write into the scripts of the Portfiles, thereby documenting and scripting your apps at the same time. And you also isolate your open source apps from the rest of the OS so you needn’t reformat your HD after installing a jillion apps if things get strange. Just blow out the package tree and quickly reinstall the open source apps quickly and easily.

    I use an app that requires SNMP support in PHP5. I just added the additional switches as “variants” (options) within the PHP portfile and it worked fine. Which is good because I’ve never complied PHP from scratch and don’t want to. You could also tweak the port for your own needs and submit the patch to the port maintainer for inclusion so the whole community can use it. Here is my patch for SNMP that is awaiting approval. http://bugzilla.opendarwin.org/attachment.cgi?id=9600&action=view

    Keep up the good work!

    Mark

  6. Paul Says:

    Any reason for the duplicate

    –enable-ftp \
    –enable-ftp \

    in your configure commands?

    Richard5: Nope, stupid mistake and is corrected. Thanks…

  7. Stefan Says:

    re the last tip to check on LoadModule… php5…, suggest you remind the user that the httpd.conf file in question is in /Library/Apache2/conf, not the usual /etc/httpd. Out of habit, I went to the latter and was sorely confused for a while.

  8. Charles Babour Says:

    So I downloaded the PHP source for 5.1.6. I tried to instal it last night. The make worked fine but when I tried to do the sudo make install it errored out. I didn’t wrote the error dowwn unfortunately.

    I redownloaded the source, put it into a new directory, tried to run the above procedure and nothing happens. When I try to run the make, nothing happens. It says no makefile found. Nothing to make.

    Any help or suggestions?

  9. DarrylM Says:

    Excellent install guides. I have gone through all the basic installation but having a problem testing the PHP installation. Checked the http.conf file and it looked like it was missing the 2 AddType statements ,added them to the end of the file but to no avail.
    When I run a test file called test.php located in the htdocs, the screen only returns the code ‘.

    Any ideas where I could have screwed up? Thank you for the guides.

  10. MartinM Says:

    I wish I had found your web site long long ago. My issue now is that I’m trying to follow your instructions with little positive results, but I have a feeling its my fault.

    The issue is that I migrated all files and settings over from an iBook to this new MacBook Pro. The iBook had both Complete Apache and Complete PHP from Server Logistics on it.

    Now once I upgraded to Xcode 2.4 I got Apache to compile and run perfectly with your instructions. With the excitement that had from that success I tried to install PHP (Note: I used the package installer for MySQL 5.0.24).

    I have altered the configure command that you have provided above to point to the correct path where the MySQL package installer put everything … /usr/local/mysql-max-5.0.24a-osx10.4-i686

    However I am getting a long list of error messages and I was hoping that you might be able to take a look at it and tell me what I need to alter to get it to compile. I’m desperate because I cannot get back to developing in PHP without it. Help?

    Richard5: Please install MySQL as I have described usign the binary and source installer. There is an issue with the MySQL install package which comes without shared libraries.

  11. Gavin Stokes Says:

    Well, I followed the instructions and things seemed to go well. But when I try to start Apache, it fails with

    Syntax error on line 241 of /etc/httpd/httpd.conf:
    Cannot load /usr/modules/libphp5.so into server: (reason unknown)
    /usr/sbin/apachectl start: httpd could not be started

    And indeed, there is no /usr/modules directory. Nor can I find libphp5.so on the computer. But doing a “make” again returns “build complete”.

  12. Gavin Stokes Says:

    Thanks for the guide.

    Unfortunately, “make install” fails with

    Installing PEAR environment: /Library/PHP5/lib/php/
    [PEAR] Archive_Tar: upgrade to a newer version (1.3.1 is not newer than 1.3.1)
    [PEAR] Console_Getopt: upgrade to a newer version (1.2 is not newer than 1.2)
    php(1250) malloc: *** vm_allocate(size=3825205248) failed (error code=3)
    php(1250) malloc: *** error: can’t allocate region
    php(1250) malloc: *** set a breakpoint in szone_error to debug
    make[1]: *** [install-pear-installer] Segmentation fault
    make: *** [install-pear] Error 2

    But I have used go-pear to update PEAR to 1.4.1, and have verified the version with “pear -V”. Put I still get this same error.

    There’s also a problem compiling PHP5 on OS X 10.4.8 on PowerPC with multibyte support. It fails, complaining about the use of vararg.h. I filed a bug against PHP5 (as have others), but they insist that it’s a Mac development-environment problem. I have filed a bug against Xcode for it.

  13. William Kanoff Says:

    I have a Quicksilver 2002 800 MHz with 10.4.8 installed, and I have tried the instructions with no success. I get mysql to install fine ( 5.0.27), but when I try to install PHP 5.1.6 it gives me an error message about _KRYPTO_LOCK. I have looked on the web and have found out that there is a problem between mysql and openssl since version 5.0.22. I was woundering how you got around the problem? It might just be a problem with the PowerPC version of mysql and not the Intel one. When I use an older version of mysql everything works perfect. Nice instructions.

  14. Michael Says:

    I had a tough time with this one until I figured out that nothing had added the handler to the httpd.conf:

    I found this site (http://dan.drydog.com/apache2php.html)
    which had the config items I needed.

    # Add index.php to your DirectoryIndex line:
    DirectoryIndex index.html index.php

    AddType text/html php

    # PHP Syntax Coloring
    # (optional but useful for reading PHP source for debugging):
    AddType application/x-httpd-php-source phps

    Otherwise, I have to echo the comment on another page that it’s a good idea to start on a clean OSX 10.4.8 box. I failed to build Apache2 and MySQL before I flattened a hard drive and started over.

    Richard, Thanks, this is a very useful resource. I’m using it to migrate from an OS 9 mailserver to something a littler newer. :)

  15. Michael Says:

    hmm. stripped them out of my comment. You may want to get them from dan’s page, it’s item #11.

  16. Richard5 Says:

    Micheal, I’ll add it to the description above asap. Thanks for pointing it out.

  17. Andrew Smith / Web design, graphic artistry, and assorted silliness / Personality Says:

    [...] While attempting to install PHP on my Mac, I got a rather interesting warning message from the Terminal. [...]

  18. sadponyguerillaboy Says:

    Get this problem.

    /usr/local/mysql/lib/libmysqlclient.a(libtaocrypt_la-misc.o) definition of _CRYPTO_lock in section (__TEXT,__text)
    collect2: ld returned 1 exit status
    make: *** [libs/libphp5.bundle] Error 1

  19. sadponyguerillaboy Says:

    Solved my own problem i posted above. I neglected to read you posting about mysql and how you need to install from the source afterwards to get the shared libraries.

    thnx for all you work, was enjoyable to go thorough.

  20. dan Says:

    i don’t understand the paths to install! the unzipped php-5.2.0 is on my hard drive(jynk) so what do i need to change
    CFLAGS=”-arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk” \
    ./configure –prefix=/Library/PHP5 \
    to?
    i get this error..
    tcsh: CFLAGS=-arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk: Command not found.

  21. mushu Says:

    these are some of the most complicated instructions for installing php on the web, how about a rewrite and keep it simple for us non-terminal geeks

    Richard5: If you want a simple install just use Marc Liyanage’s binary PHP package. These instructions were meant to give you full control of how and what to install and to be indendent of anyone else.

  22. Keith Says:

    Hello

    I get the same “CFLAGS=-arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk: Command not found.” error that dan ran into.

    The rest of the process seems to go - with the exception of a few problems that have arisen due to my lack of attention to detail.

    I’d really like to know the issue behind the CFLAGS… command failure though.

    I am not a unix geek, but I have really learned quite a bit about the system by working through this process - thank you for the obvious effort that went into this very well done project. While not everyone may appreciate a more technical approach, when one is installing the tools of an isp, presumably, one wants to understand what is happening - and what kind of understanding comes from watching an unknown process move through a progress bar?

    Anyway - I appreciate the good work

  23. david Says:

    Hi,

    thanks for providing this useful set of instructions. I built php 5.2.0 with your instructions with success, however the php.ini file in the /etc dir doesn’t seem to be working.

    I’ve been trying to change the error reporting, however after restarting apache, it does not respond to any changes in the php.ini file.

  24. raphael Says:

    dan and keith re: CFLAGS error.

    Use the Bourne shell, /bin/sh, instead of tcsh

  25. raphael Says:

    david: re php.ini file

    When using ./configure command replace directive
    –sysconfdir=/etc
    with
    –with-config-file-path=/etc

    Otherwise, the default location of the php.ini file is /Library/PHP5/lib/

  26. Matt Says:

    I’ve got Apache2 and MySQL 5.0.27 working as described here - great tutorials. However, when I try to get PHP5 working, the ./configure fails. Here are the last 6 lines of the output:

    checking for MySQL support… yes
    checking for specified location of the MySQL UNIX socket… no
    checking for MySQL UNIX socket location… no
    checking for mysql_close in -lmysqlclient… no
    checking for mysql_error in -lmysqlclient… no
    configure: error: mysql configure failed. Please check config.log for more information.

    The make command results in “No targets specified and no makefile found.”

    Any thoughts?

  27. CoachBayhylle Says:

    I’m having the same problem as above. I was able to compile php5 a couple of weeks ago. Now when I try to recompile with ldap support I get the mysql error.

  28. Richard5 Says:

    Matt & Coach: Please install MySQL using my instructions. You need the shared libraries in MySQL to be able to compile PHP with MySQL support !

  29. rich Says:

    I’ve had to recompile and install php on a previously working instal using your instructions.

    This was to try and combine the GD, JPEG and PNG libraries to support Drupal’s requirements for image manipulation.

    I’m finding now that PHP will just not update. It won’t reinstall the module, whether i remove it physically or not, and will not update httpd.conf with the line to add a module (at the start of the install it states its installing as CGI).

    Not quite sure whats going wrong here.

    Here’s my process for recompile and install:

    1. Shutdown Apache

    2. Remove Loadmodule for php from httpd.conf as well as all php related lines.

    3. Delete php folder from its location on disk to uninstall.

    4. Configure with:

    CFLAGS=”-arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk” \
    sudo ./configure –prefix=/usr/local/apache2/php \
    –mandir=/usr/share/man \
    –infodir=/usr/share/info \
    –sysconfdir=/etc \
    –with-gd \
    –with-zlib \
    –with-jpeg \
    –with-jpeg-dir=/usr \
    –with-png \
    –with-png-dir=/usr \
    –with-xml \
    –with-gd-dir=/usr \
    –with-zlib-dir=/usr \
    –with-openssl \
    –enable-exif \
    –enable-ftp \
    –enable-mbstring \
    –enable-mbregex \
    –enable-sockets \
    –with-mysql-dir=/usr/local/mysql \
    –with-mysqli=/usr/local/mysql/bin/mysql_config

    5. Make and install.

    Any idea what could be going wrong here? Am at a loss :)

    Thanks R

  30. Greg Combs Says:

    Trying to compile the latest php on OSX Server 10.4.8 … I recently (this morning) got the latest Apache up and running successfully (I added –with-included-apr).

    I can successfully configure PHP, and the compile goes well for the most part … it dies when trying to link libphp5.so with various libraries, even though they’re in /usr/lib as it’s expecting…

    libaprutil-1
    libexpat
    libapr-1

    It dies with /usr/bin/ld: can’t locate file for: -libaprutil-1

    If I run my own gcc command starting with:

    gcc -bundle -bundle_loader /usr/sbin/httpd -L/usr/lib -L/usr/lib -L/usr/lib -laprutil-1 -lldap -llber -lsqlite3 -lexpat -liconv -L/usr/lib -lapr-1 -lpthread -I/usr/include -arch i686 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -L/usr/local/mysql/lib -L/usr/local/lib

    I can successfully append .dylib or .la to “laprutil-1″ and it works, at least temporarily, then dies on lexpat …, omitting lexpat means it then dies on lapr-1 (.la or .dylib doesn’t work for anything else)

    an ‘ls /usr/lib/libapr*’ shows:
    /usr/lib/libapr-1.0.2.8.dylib /usr/lib/libaprutil-1.0.2.8.dylib
    /usr/lib/libapr-1.0.dylib /usr/lib/libaprutil-1.0.dylib
    /usr/lib/libapr-1.dylib /usr/lib/libaprutil-1.dylib
    /usr/lib/libapr-1.la /usr/lib/libaprutil-1.la

    and there’s also:
    /usr/lib/libexpat.0.1.0.dylib /usr/lib/libexpat.dylib
    /usr/lib/libexpat.0.dylib /usr/lib/libexpat.la

    Anyone have any ideas what the heck is going on? Do I need to go back and rebuild Apache?

  31. Greg Combs Says:

    OK, I believe I answered my own questions…

    I had to download apr-1.2.8, and apr-util-1.2.8 from apache.org.

    I compiled and installed apr.
    I configured apr-util pointing to the installed apr, plus I had to add information for ldap’s headers and library.

    I recompiled/installed Apache, pointing it towards my new apr and apr-util installation.

    I recompiled php5

    This got rid of the apr and expat business as seen earlier.

    I then saw a link error regarding mysql … further searching says that building php5 is incompatible with mysql5 … need to temporarily downgrade to mysql4 during the build process.

    So I changed the symbolic link /usr/local/mysql over to a temporary installation of mysql-max-4.1-something

    then rebuilt php (make sure to rerun configure, and make clean first)

  32. aprince Says:

    First off thanks for the great website and really appreciate the instructions.
    I’ve compiled mysql and apache2 using your set, and those went very well. I’m now running into errors during the configuration portion:
    config.log ends with this:

    configure:105668: gcc -o conftest -I/usr/include -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -no-cpp-precomp conftest.c 1>&5
    configure:105859: checking for c++
    configure:105891: checking whether the C++ compiler (c++ ) works
    configure:105907: c++ -o conftest -no-cpp-precomp conftest.C 1>&5
    In file included from configure:105902:
    confdefs.h:347:2: error: too many decimal points in number
    confdefs.h:347:30: error: too many decimal points in number
    confdefs.h:347:75: error: too many decimal points in number
    In file included from configure:105902:
    confdefs.h:347: error: missing terminating ” character
    confdefs.h:347: error: expected unqualified-id before numeric constant
    confdefs.h:347: error: invalid function declaration
    configure: failed program was:

    #line 105902 “configure”
    #include “confdefs.h”

    int main(){return(0);}

    as best as I can tell, it doesn’t like the PHP_UNAME variable.

    Thanks for any help

    AP

  33. Dennis Says:

    the MAKE for PHP returns an error. Any idea?

    /usr/bin/ld: multiple definitions of symbol _CRYPTO_lock
    /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/libcrypto.dylib(cryptlib.o) definition of _CRYPTO_lock
    /usr/local/mysql/lib/libmysqlclient.a(libtaocrypt_la-misc.o) definition of _CRYPTO_lock in section (__TEXT,__text)
    collect2: ld returned 1 exit status
    make: *** [libs/libphp5.bundle] Error 1

  34. Bill Cole Says:

    PHP 5.2.1 build breaks if you have used Fink, have /sw/bin in your $PATH, and have installed more recent versions of OpenSSL and (maybe) libxml2 than exist in /usr. The PHP configure finds the dpkg infrastructure under /sw and uses it to sniff out things it should not, resulting in an ld ‘undefined symbol’ failure late in the make. (looks like the final link of the php binary)

    I have not nailed down a solid analysis, but doing a ‘make clean’ then removing /sw/bin from $PATH and then

    mv /sw /sw-hide
    chmod 000 /sw-hide

    Then re-running the configure and make yields success.

    Afterwards, of course:

    mv /sw-hide /sw
    chmod 755 /sw

  35. Dennis Says:

    All seems to have gone fine up to this point. A new httpd.conf file was created in /library/apache2/conf, however it only contains the first line you say to look for. The two addtype lines are missing.

    Any suggestions?

  36. Richard5 Says:

    If the lines aren’t there you can add them yourself.

  37. Marc Says:

    So everything has installed fine; Apache, MySql, and PHP. My only problem is, when trying to access the files, PHP does not seem to parse them. I see the source code for the php file and that’s it.

    I’ve reviewed my httpd.conf file over a million times, and reinstalled PHP at least 5 times. Everything seems to be in order.

    A simple “HEAD / HTTP/1.0″ gives this when connected to the new server (apache2):

    HTTP/1.1 200 OK
    Date: Sat, 10 Mar 2007 05:35:35 GMT
    Server: Apache/2.2.4 (Unix) mod_ssl/2.2.4 OpenSSL/0.9.7l DAV/2 SVN/1.4.3 PHP/5.2.1
    Last-Modified: Sat, 10 Mar 2007 03:54:34 GMT
    ETag: “261966-13-7f877280″
    Accept-Ranges: bytes
    Content-Length: 19
    Connection: close
    Content-Type: text/plain

    Any thing I’m missing?

    Any help would be appreciated. Thanks.

  38. Boaz Says:

    I keep getting an error message that said:

    /usr/bin/ld: can’t locate file for: -laprutil-1
    collect2: ld returned 1 exit status
    make: *** [libs/libphp5.bundle] Error 1

    … I admit, I installed apache with the “Darwin” layout (the default for OS X Client)… still, I don’t really understand what has gone wrong?

    Still, for all else, I’ve had loads of fun with the project :-)

    … so… thank you.

  39. jeff Says:

    I am fairly new to using the terminal, etc.

    I am having the same problem as comment #4 :

    //////////////////

    “The mbstring PHP extension was not found and you seem to be using a multibyte charset. Without the mbstring extension phpMyAdmin is unable to split strings correctly and it may result in unexpected results.”

    Any ideas?

    Richard5: Just made a minor correction to the ./configure command, I added the line –enable-mbstring to it to make phpmyadmin work.

    /////////////////

    I can see that the line of code enables mbstring, but I am not sure how to apply this information to an already installed php on my machine. Can anyone provide simple detailed instructions? I am hoping it does not require uninstalling, compiling, installing, etc. Is it possible to get this working with a few terminal commands.

    Thanks

  40. Richard5 Says:

    Sorry if you’ve got the same error you will have to recompile PHP or download a binary from another source (there are many).

    How to compile and install is documented on this page.

  41. Jacob Says:

    Hey all,

    get the follow error message when trying to install PHP. Can anyone help out at all??

    dyld: Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib
    Referenced from: /volumes/Macintosh_HD/users/Jacob/php_install/sapi/cli/php
    Reason: image not found
    make[1]: *** [install-pear-installer] Trace/BPT trap
    make: *** [install-pear] Error 2

    Cheers!

    Jacob

  42. Zach Moazeni Says:

    I’m also getting the same error as Jacob. Running Intel Mac. Installed MySQL 5.0.41 from the Mac Package. Compiled and installed Apache 2.2.4, and trying to compile PHP 5.2.3 with these configuration options


    CFLAGS="-arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk"
    ./configure --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib --with-gd=/opt/local/

    I get this error message when trying to run “sudo make test”


    dyld: Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib
    Referenced from: /Users/zach/downloads/httpd/php-5.2.3/sapi/cli/php
    Reason: image not found
    make: [test] Error 133 (ignored)

    -Zach

  43. Zach Moazeni Says:

    Looking at another article here http://switch.richard5.net/isp-in-a-box-v2/installing-mysql-on-mac-os-x/#comment-10038

    I think John found the solution.

    This seemed to be a quick fix


    cd /usr/local/mysql/lib
    sudo mkdir mysql
    cd mysql
    sudo ln -s ../*

    Thanks John, and thanks Richard for the help.

  44. Tim Says:

    Hi Richard, thanks for all the tutorials on compiling all these tools on mac.

    I ran into the same issue as Dennis (comment #33)… that’d be great if you could help me figure out what I did wrong…

    Thanks - Tim

    collect2: ld returned 1 exit status
    make: *** [libs/libphp5.bundle] Error 1

  45. 7stud Says:

    1) I installed Apache 2.2.4 and Mysql 5.0.41(and source 5.0.45) according to your instructions. Then I installed php 5.2.2. Is the following normal output for the php install:

    ——-
    $ sudo make install
    Password:
    Installing PHP SAPI module: apache2handler
    /Library/Apache2/build/instdso.sh SH_LIBTOOL=’/Library/Apache2/build/libtool’ libs/libphp5.so /Library/Apache2/modules
    /Library/Apache2/build/libtool –mode=install cp libs/libphp5.so /Library/Apache2/modules/
    cp libs/libphp5.so /Library/Apache2/modules/libphp5.so
    Warning! dlname not found in /Library/Apache2/modules/libphp5.so.
    Assuming installing a .so rather than a libtool archive.
    chmod 755 /Library/Apache2/modules/libphp5.so
    [activating module `php5' in /Library/Apache2/conf/httpd.conf]
    Installing PHP CLI binary: /Library/PHP5/bin/
    Installing PHP CLI man page: /usr/share/man/man1/
    Installing build environment: /Library/PHP5/lib/php/build/
    Installing header files: /Library/PHP5/include/php/
    Installing helper programs: /Library/PHP5/bin/
    program: phpize
    program: php-config
    Installing man pages: /usr/share/man/man1/
    page: phpize.1
    page: php-config.1
    Installing PEAR environment: /Library/PHP5/lib/php/

    Warning: Cannot use a scalar value as an array in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 740

    Warning: array_merge(): Argument #2 is not an array in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 766

    Notice: Undefined index: pearinstaller in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 777

    Warning: Cannot use a scalar value as an array in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 720

    Warning: Cannot use a scalar value as an array in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 720

    Warning: Cannot use a scalar value as an array in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 720

    Warning: Cannot use a scalar value as an array in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 720

    Warning: Cannot use a scalar value as an array in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 720

    Warning: Cannot use a scalar value as an array in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 740

    Warning: Invalid argument supplied for foreach() in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 1207

    Warning: Invalid argument supplied for foreach() in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 1207

    Warning: Invalid argument supplied for foreach() in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 1207

    Notice: Undefined variable: ret in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 1269

    Warning: Invalid argument supplied for foreach() in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 1207

    Warning: Invalid argument supplied for foreach() in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 1207

    Notice: Undefined variable: ret in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 1269

    Warning: Cannot use a scalar value as an array in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 757

    Warning: Cannot use a scalar value as an array in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 720

    Warning: Invalid argument supplied for foreach() in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 1207

    Notice: Undefined variable: ret in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 1269

    Warning: Cannot use a scalar value as an array in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 757

    Warning: array_merge(): Argument #2 is not an array in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 766

    Notice: Undefined index: pearinstaller in phar://install-pear-nozlib.phar/PEAR/PackageFile/Generator/v1.php on line 777
    [PEAR] Console_Getopt - installed: 1.2.2
    [PEAR] Archive_Tar - installed: 1.3.2
    [PEAR] Structures_Graph- installed: 1.0.2
    [PEAR] PEAR - installed: 1.5.4
    Wrote PEAR system config file at: /etc/pear.conf
    You may want to add: /Library/PHP5/lib/php to your php.ini include_path
    Installing PDO headers: /Library/PHP5/include/php/ext/pdo/
    —————–

    2) In my httpd.conf file, I found the first line:

    LoadModule php5_module modules/libphp5.so
    AddType application/x-httpd-php .php .phtml
    AddType application/x-httpd-php-source .phps

    but not the second two lines. Should I add the second two lines right under the LoadModule line or in another section?

    Thanks

  46. 7stud Says:

    Oops! The php version I installed was 5.2.3.

  47. Richard5 Says:

    @Tim, you need to compile MySQL from source first ! Its shared library issue !

  48. Kim Walker Says:

    During execution of sudo make install, I get the following error:

    Installing PEAR environment: /Library/PHP5/lib/php/
    warning: pear/pear dependency package “pear/Console_Getopt” downloaded version 1.2.2 is not the recommended version 1.2.3
    [PEAR] Console_Getopt: upgrade to a newer version (1.2.2 is not newer than 1.2.3)
    [PEAR] Archive_Tar: upgrade to a newer version (1.3.2 is not newer than 1.3.2)
    [PEAR] Structures_Graph: upgrade to a newer version (1.0.2 is not newer than 1.0.2)
    warning: pear/pear_frontend_web requires package “pear/PEAR” (version >= 1.6.1), downloaded version is 1.5.4
    pear/PEAR can optionally use package “pear/XML_RPC” (version >= 1.4.0)
    [PEAR] PEAR: upgrade to a newer version (1.5.4 is not newer than 1.6.1)

    During the execution of go-pear.php, I get the following error:

    Downloading and installing package: PEAR_Frontend_Gtk2…….pear/PEAR_Frontend_Gtk2 requires PHP (version >= 5.1, version = 2.0.0dev)
    pear/Gtk2_EntryDialog requires PHP (version >= 5.1, version = 2.0.0dev)
    pear/Gtk2_FileDrop requires PHP (version >= 5.1, version = 2.0.0dev)
    No valid packages found
    Package: MDB2………………………………. already installed … ok

    ******************************************************************************
    WARNING! The include_path defined in the currently used php.ini does not
    contain the PEAR PHP directory you just specified:

    If the specified directory is also not in the include_path used by
    your scripts, you will have problems getting any PEAR packages working.

    Current include path : .:
    Configured directory : /Library/PHP5/PEAR
    Currently used php.ini (guess) :

  49. Kim Walker Says:

    Here’s the go-pear error again with entities:

    Downloading and installing package: PEAR_Frontend_Gtk2…….pear/PEAR_Frontend_Gtk2 requires PHP (version >= 5.1, version <= 6.0.0), installed version is 4.4.4
    pear/PEAR_Frontend_Gtk2 requires PHP extension “php-gtk” (version >= 2.0.0dev)
    pear/Gtk2_EntryDialog requires PHP (version >= 5.1, version <= 6.0.0), installed version is 4.4.4
    pear/Gtk2_EntryDialog requires PHP extension “php-gtk” (version >= 2.0.0dev)
    pear/Gtk2_FileDrop requires PHP (version >= 5.1, version <= 5.999.999), installed version is 4.4.4
    pear/Gtk2_FileDrop requires PHP extension “php-gtk” (version >= 2.0.0dev)
    No valid packages found
    Package: MDB2………………………………. already installed … ok

    ******************************************************************************
    WARNING! The include_path defined in the currently used php.ini does not
    contain the PEAR PHP directory you just specified:
    </Library/PHP5/PEAR>
    If the specified directory is also not in the include_path used by
    your scripts, you will have problems getting any PEAR packages working.

    Current include path : .:
    Configured directory : /Library/PHP5/PEAR
    Currently used php.ini (guess) :

  50. mikehal Says:

    Your php5.2.3 install guide worked perfectly for my 10.4.x intel setup (mySQL, Apache2 the whole bit) however I realized after the fact that GD is not configured in.

    I’ve since tried to build and install libjpeg et al. libraries but I’ve run into possible fink issues or static vs shared issues not sure which or both at this point -

    So I’m stuck w/o GD. The nice folks at Entropy.ch have 5.2.2 as an installable package for Apache2 and it includes GD [somehow]. I’d drop it in right now except it calls for a /usr/local install of Apache2 vs. the /Library install here.

    Fearing a complete mess, I beg for guidance per either straightening out the GD lib stuff (preferred) or how I might work entropy’s stuff into the mix

  51. mikehal Says:

    update on the GD stuff: entropy.ch has a tidy php 5.2.2 that installed w/o a hitch on my 10.4.10 intel imac and it comes GD enabled. I edited httpd.conf to pickup the entropy php5 module in /usr/local/php5 vs /Library/PHP5.

    Love to know what I messed up on with 5.2.3 and GD

  52. Keith Bloom Says:

    Great work Richard. A few bumps of my own accord but you instruction have MySQL and Apache2 running smoothly on my MBPro. I am trying to follow the full suite upgrade with your install of PHP5.2.3 and using your CFLAGS script:
    Keith-Blooms-MacBook-Pro:~/Desktop/php-5.2.3 keithbloom$ CFLAGS=”-arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk” \
    > ./configure –prefix=/Library/PHP5 \
    > –mandir=/usr/share/man \
    > –infodir=/usr/share/info \
    > –sysconfdir=/etc \
    > –with-zlib \
    > –with-xml \
    > –with-zlib-dir=/usr \
    > –with-openssl \
    > –enable-exif \
    > –enable-ftp \
    > –enable-mbstring \
    > –enable-mbregex \
    > –enable-sockets \
    > –with-mysql=/usr/local/mysql \
    > –with-mysqli=/usr/local/mysql/bin/mysql_config \
    > –with-apxs2=/Library/Apache2/bin/apxs

    returns the following error:

    ./configure: line 2060: ./config.log: Permission denied

    I had a similar issue with Apache2 install and ended up running chown on configure in unpacked tar ball.

    The chown on configure within unpacked PHP tar ball does not solve the ./config.log issue. Any suggestions?

  53. Keith Bloom Says:

    Nevermind. Noob here. Re-downloaded and unpacked as myself instead of sudo tar -zxvf and it worked.

    Keep up the great how-tos. Congrats on your newest family member as well.

  54. Stefano Says:

    I think configure must be expanded as is:
    ./configure –prefix=/usr/local/php5 –with-apxs –with-config-file-scan-dir=/usr/local/php5/php.d –with-iconv –with-openssl=/usr –with-zlib=/usr –with-gd –with-zlib-dir=/usr –with-ldap –with-xmlrpc –with-iconv-dir=/usr –with-snmp=/usr –enable-exif –enable-wddx –enable-soap –enable-sqlite-utf8 –enable-ftp –enable-sockets –enable-dbx –enable-dbase –enable-mbstring –enable-calendar –enable-bcmath –with-bz2=/usr –enable-fastcgi –enable-cgi –enable-memory-limit –enable-zip –enable-pcntl –with-curl=shared,/usr/local/php5 –with-mysql=shared,/usr/local/php5 –with-mysqli=shared,/usr/local/php5/bin/mysql_config –with-pdo-mysql=shared,/usr/local/php5 –with-libxml-dir=shared,/usr/local/php5 –with-xsl=shared,/usr/local/php5 –with-pdflib=shared,/usr/local/php5 –with-oci8=shared,instantclient,/usr/local/php5/oracle –with-pdo-oci=shared,instantclient,/usr/local/php5/oracle,10.1.0.3 –with-imap=../imap-2004g –with-kerberos=/usr –with-imap-ssl=/usr –with-jpeg-dir=/usr/local/php5 –with-png-dir=/usr/local/php5 –enable-gd-native-ttf –with-freetype-dir=/usr/local/php5 –with-iodbc=shared,/usr –with-pgsql=shared,/usr/local/php5 –with-pdo-pgsql=shared,/usr/local/php5 –with-t1lib=/usr/local/php5 –with-gettext=shared,/usr/local/php5 –with-ming=shared,/usr/local/php5 –with-mcrypt=shared,/usr/local/php5 –with-mhash=shared,/usr/local/php5 –with-mssql=shared,/usr/local/php5 –with-fbsql=shared,/Users/liyanage/svn/entropy/universalbuild/src/FBDeveloperLibraries/Library/FrontBase –with-json=shared –enable-memcache –enable-openbase_module

  55. Jamieson Teo Says:

    Thanks for the excellent post. It went pretty well for me. When i run a phpinfo in the webbrowser, it would show that PHP is version 5 but if I go to terminal and do a php -v it shows as PHP4….

    Any ideas?

  56. Kiran Says:

    @Jamieson: in terminal, “php -v” will run “/usr/bin/php -v” (the OS X installed PHP4). To run your newly installed PHP5 use “/Library/PHP5/bin/php -v” instead.

  57. Tim Says:

    Ok, I have spent the past few hours trawling google search results and reading through various blogs and the such to discover the solution to my problem. I’ll be quite frank here, I am a noob when it comes to compiling applications. I suppose I fit nicly into the catagory of ‘Do what Im told by the guide’.
    That said I have followed your instructions thus far without incident. I have MySQL installed, secured and running, the same with Apache 2 (a first for me under OS X). My issue is with php, as you may have guessed. When I run the config command; “CFLAGS=”-arch i686 -isysroot /Developer/SDKs/MacOSX10.4u.sdk” ./configure….(shortened for sake of space)” I get the following error;

    checking whether the C compiler (gcc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk ) works… no
    configure: error: installation or configuration problem: C compiler cannot create executables.

    I am pretty much stuck now so any help would be welcomed :)

  58. Johan Says:

    That link from http://go-pear.org/ doesn’t work anymore. How do I update my computer now?

  59. Shawn Says:

    Before I mention my error I must say “Thank You” for taking the time to share your knowledge with ALL of us. I have found this site to be VERY useful over the course of this year. Keep up the great work.

    Now, to my issue.

    I am trying to install the latest version of PHP5 (php.5.2.4). After executing the first command for Intel builds I get the following notice.

    Notice: Following unknown configure options were used:

    –with-xml

    Check ‘./configure –help’ for available options

    Any idea why this is happening? I have successfully installed earlier releases of PHP5 on my Intel MAC but seem to be experiencing some odd occurrences.

    Any help would be greatly appreciated.

  60. Richard5 Says:

    Shawn,

    It’s not an error, just a warning. The –with-xml is depreciated.

    Just run make and sudo make install.

  61. Will Says:

    I am trying to install a mediawiki. When I configure the wiki it told me that php’s session directory was not set. When I finished the configuration the main index would not load/was blank. So I edited php.ini (I had to move it from /etc to /Library/PHP5/lib to get it to load) and set the session save directory to /Library/PHP5/session (I created this directory myself php.ini said it would not auto create). Now mediawiki says the the directory is invalid or not writeable and fails.

    The really galling part is php is not generating error logs(or I cant find them). I have enabled error logging, set the log file as /Library/Apache2/logs/php_errors and even created a blank file with pico and still no logs.

    And by the way, great tutorials. They are really helping me get my head around all this server stuff.

  62. Richard5 Says:

    Will, is the session directory writeable for the user running Apache (most likely ‘www’)

  63. Will Says:

    I think that the session directory’s permissions were wrong. I set them to 777 (I figure this is a horrible security problem, but I am not sure how to find out what apache is running under and set the permissions correctly) now mediawiki says the session path is OK. However mediawiki’s index page still won’t load.

    I also found the logs for php. They were in apache’s error log. Every time I try to access mediawiki’s index page apache generates:

    dyld: lazy symbol binding failed: Symbol not found: _deflateInit2_
    Referenced from: /Library/Apache2/modules/libphp5.so
    Expected in: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib

    dyld: Symbol not found: _deflateInit2_
    Referenced from: /Library/Apache2/modules/libphp5.so
    Expected in: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib

    [Mon Nov 12 11:12:12 2007] [notice] child pid 306 exit signal Trace/BPT trap (5)

    I think this has to do with zlib but I’m not sure what to do about it.

  64. Richard5 Says:

    If you want to find out what user apache is running under just do a ‘ps -aux | grep httpd’ or look in your httpd.conf (it is configured there)

    The other error depends on your PHP, MySQL installtion. How did you do that? All according to my instructions ?

  65. Will Says:

    No. I could not get the Mysql to compile so I looked at several other tutorials and finally compiled with:
    CFLAGS=”-arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk” \
    ./configure –prefix=/usr/local/mysql \
    –with-unix-socket-path=/usr/local/mysql/run/mysql_socket \
    –with-mysqld-user=mysql –with-comment –with-debug \
    –localstatedir=/usr/local/mysql/data \
    –libexecdir=/usr/local/mysql/bin \
    –libdir=/usr/local/mysql/lib \
    –enable-thread-safe-client \
    –enable-local-infile \
    –enable-shared \
    –with-big-tables \
    –without-bench

    Then I had a problem with apache finding the mysql socket so I created a link

    sudo mkdir /var/mysql
    sudo ln -s /usr/local/mysql/run/mysql_socket /var/mysql/mysql.sock

    PHP was installed per your instructions:
    CFLAGS=”-arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk” \
    ./configure –prefix=/Library/PHP5 \
    –mandir=/usr/share/man \
    –infodir=/usr/share/info \
    –sysconfdir=/etc \
    –with-zlib \
    –with-xml \
    –with-zlib-dir=/usr \
    –with-openssl \
    –enable-exif \
    –enable-ftp \
    –enable-mbstring \
    –enable-mbregex \
    –enable-sockets \
    –with-mysql=/usr/local/mysql \
    –with-mysqli=/usr/local/mysql/bin/mysql_config \
    –with-apxs2=/Library/Apache2/bin/apxs

    What I tried to do was remove all of the flags from the Mysql compile that seemed to duplicate the default settings, but I don’t understand all of them so I prolly messed something up there.

  66. Richard5 Says:

    The thing might be that php and MySQL might be using different zlib libraries and that they are conflicting. Could you try to use the MySQL option ‘–with-zlib-dir=bundled’ and see if that helps? Please also recompile PHP as well.

  67. Will Says:

    I followed your instructions more exactly and now it works. I flattened my HD and started from scratch since I had no idea what I was doing the first time around. The only addiontional step I had to take was setting the session directory in php.ini. Thank you very much for your help. I would still be lost in terminal land without your help.

  68. Richard5 Says:

    No problem and good luck with your setup!

  69. Nick Says:

    First off, thanks for the article!

    I’ve been working on this for a while and have been getting the same problems as Matt and Coach (26 and 27)
    “checking for MySQL UNIX socket location… no
    checking for mysql_close in -lmysqlclient… no
    checking for mysql_error in -lmysqlclient… no
    configure: error: mysql configure failed.”

    So I reinstalled mysql with the latest version, 5.0.51a, and then, per your advice, from source again, to make sure the shared libraries were included, but the error persists.

    Is there a way to check that these libraries are included? Any ideas on other dependencies?

    Thanks

  70. MAtttty Says:

    Hi,

    when i finished the ./configure things i want to do ‘make’ but i get this messeage “Nothing to be Done for make” what should i do ???

  71. Richard5 Says:

    If you have used make before and changed something in the ./configure statement sometimes the changes aren’t noted. Please use ‘make clean’ before you do a ./configure if you have run make before.

  72. Andrew Heiss Says:

    Great tutorials! I’ve done them all and pretty much everything works except the PHP, and I didn’t realize it until just now when I added the gd library and recompiled from scratch. According to phpinfo, my Apache is using the precompiled Leopard PHP 5 rather than my compiled one (i.e. the build date is before I bought the computer and none of the configuration options match my ./configure flags). How do I tell Apache to use my PHP instead of the built in one?

    Thanks!

  73. Andrew Heiss Says:

    Never mind! I just needed to add “/usr/local/php5/lib/php” to my include_path in etc/php.ini and everything works now! I guess I had to tell PHP which version of PHP to use, not Apache. Weird…

Leave a Reply