PHP and Mac OS X Leopard—A Warning

October 27th, 2007

I have just upgraded my Mac PowerBook G4 laptop to Mac OS X 10.5 (Leopard). The installation went fine, but there are a couple of issues you need to be aware of if you use your Mac to develop PHP, as they could affect your decision to upgrade—at least for the time being.

Leopard installs Apache 2.2.6 instead of the Apache 1.3 series that was used in all previous versions of Mac OS X. As a result, when you restart your computer for the first time, web sharing will be disabled. Turning it on is exactly the same as described in all my books. However, if you use the Mac OS X PHP package from Marc Liyanage, it won’t work.

Although Marc offers an Apache 2 version on his site, that won’t work on Leopard, either. According to a post from Marc on 26 October in this thread in his forum, he needs to figure out how to integrate it all, but is currently very busy at work. The same thread discusses using the version of PHP preinstalled in Leopard. Apple has inexplicably decided to install PHP 4, even though it comes to the end of its support life in just over two months’ time. [Updated 28 Oct 2007] As Dan Brown points out below, PHP 5 is, indeed, preinstalled in Leopard. The confusion is caused by Apache being in a new location. I suspect that the old versions of Apache and PHP were left on my machines because they were upgraded from OS X 10.4, and that a completely fresh install of Leopard would have only Apache 2.2.6 and PHP 5.2.4.

Following Dan’s instructions below will get PHP 5 up and running in Leopard. However, the default installation of PHP doesn’t read php.ini. You need to create that yourself. I’ll try to get some instructions up on my site in the next day or two.

I have no idea how long it will take Marc Liyanage to work his usual wonders with his PHP package, but if you want to use Mac OS X to develop PHP sites, either delay upgrading to Leopard follow Dan’s instructions below or use the all-in-one package from MAMP. I have never used MAMP, but it has a good reputation. Perhaps it’s time for me to give it a try.

[Added 28 Oct 2007] MAMP seems to work without problem on Leopard, and is definitely worth considering if the idea of working in Terminal sends cold shivers up your spine. After downloading it, simply copy the MAMP folder to Applications, and then double-click the MAMP icon inside the MAMP folder. I suggest that you select Preferences > Ports, and click “Set to default Apache and MySQL ports”. If you do this, it’s important not to switch on Web Sharing in System Preferences. You must also close down any existing MySQL server. It’s also important to realize that the Apache and MySQL versions installed by MAMP are completely independent. The site root and MySQL data store are in different locations. Any databases created in a previous installation of MySQL must be exported, and reimported into the MAMP version of MySQL. The need to move things around detracts from the attraction of MAMP if you already have several databases stored in an existing installation of MySQL.

Entry Filed under: Books, PHP

31 Comments Add your own

  • 1. Dan Brown  |  October 27th, 2007 at 11:56 pm

    I ran into the same problem when I upgraded to Leopard, but with some hunting around I found that php5.2.4 is installed with Leopard…the key is where to find how to enable it.

    Leopard provides 2 dirs (actually 3) for the locations of the httpd.conf files for apache. One is /private/etc/httpd (this is for apache 1.3 and will call this dir1) and the other is /private/etc/apache2 (this is for apache 2, will call this one dir2).

    If you go to dir2 and edit the httpd.conf file, so that the line #LoadModule php5_module libexec/apache2/libphp5.so is uncommented (remove the #).

    Another issue (not being able to access your personal web page http://localhost/~your-name) can be solved by copy the your-name.conf file from dir1/users to dir2/other. For example:
    1. launch the Terminal app
    2. cd /private/etc/apache2/other
    3. sudo cp /private/etc/httpd/users/*.conf .
    For some reason apple launches apache2 when you use web sharing, but the location of the your-name.conf file is in the wrong location.

    Hope this helps.

  • 2. David  |  October 28th, 2007 at 8:03 am

    Thanks very much, Dan. A discussion in the Dreamweaver forum led me in the right direction to find the preinstalled version of PHP 5.2.4 last night, but I hadn’t worked out the solution to the personal web page issue.

    One other little glitch in using the preinstalled version of PHP is that it doesn’t read php.ini. You need to make a copy of /private/etc/php.ini.default and rename it php.ini in the same location. Then make any changes to suit your requirements.

    I notice that the preinstalled version of PHP has support for mysql, mysqli, and pdo-sqlite, but not for pdo-mysql. Otherwise, it seems to have a reasonably well featured version of PHP.

  • 3. Dan Brown  |  October 28th, 2007 at 3:38 pm

    Hi David -
    If you find out how to re-build (make) the preinstalled version of php5.4.2, please post the info! The one item in php that is use is the soap functionality that is build into php5, which is not enabled in the version on Leopard.
    I tried downloading the tar file from php.net, building it and installing…but apache wasn’t too happy. I’ll keep on trying and let you know the results.

  • 4. Dan Brown  |  October 28th, 2007 at 4:18 pm

    I understand wanting to stay away from using Terminal. Most of the people that I see using a Mac do so because of the user interface, and not having to deal with the underlying BSD Unix operating system.

    If you feel that it will help, I can create an application (most likely in Cocoa) that will 1) Setup the personal web server correctly, 2) enable php 5, 3) rename the php.ini.default to php.ini, as well as allow the editing of the file in a user friendly editor. Each of the items above can be toggled on/off, etc.
    Also, if I can figure out a way to rebuild the installed php5, I’ll allow the user of the app to select which options to enable / disable. (anything I’m missing?)

  • 5. David  |  October 28th, 2007 at 4:59 pm

    It would be marvellous if there were an easy way of upgrading PHP on a Mac, but it seems to require considerable knowledge of the underlying OS. I have succeeded only once in compiling PHP from source on a Mac. The next time I tried it, something went wrong - probably a missing dependency or incompatible third-party library.

    I have spent several hours struggling with php.ini. It appears that you need to enable the Mac root user to be able to copy or edit it. Using sudo doesn’t give you sufficient administrative privileges. Enabling root doesn’t worry me, but I fear that a lot of Mac users will have problems. I just don’t understand why Apple have made what should be a very simple operation into something rather complex. :(

    Must have been something wrong with my setup. I have just reset my password and rebooted. I can now copy and edit php.ini.default. Weird.

  • 6. Dan Brown  |  October 29th, 2007 at 3:12 am

    Hi David -
    I read your tutorial on this subject. Excellent work and thank you for the recognition!
    Dan

  • 7. Steve  |  October 31st, 2007 at 9:40 am

    It’s seems that the Leopard build of PHP from Apple doesn’t have PostgreSQL support compiled in.

    Steve

  • 8. David  |  October 31st, 2007 at 9:47 am

    It doesn’t have support for PDO-MySQL either. In fact, there are a lot of things missing from the preinstalled version. It seems as though Marc Liyanage’s version is the one to wait for. For basic tasks, though, the preinstalled version is better than nothing.

  • 9. Dogzilla  |  November 1st, 2007 at 3:06 am

    One could argue that connecting to Mysql or Postgres *is* a basic task for a php-based application. I can’t really find much use for it without one of these two.

  • 10. David  |  November 1st, 2007 at 8:03 am

    You can connect to MySQL, as the preinstalled version does support both the original MySQL extension and MySQL Improved. I have never advocated the use of the preinstalled version of PHP in Mac OS X because it has always been out of date and poorly featured. The reason I posted instructions for how to enable it in Leopard was for the simple reason that the excellent package created by Marc Liyanage is incompatible with Leopard.

    Marc is working on building a PHP 5 package for Leopard, but the architecture of Mac OS X 10.5 is presenting difficulties. Not only does he need to create a package compatible with Apache 2.2.6, Leopard needs a four-way Universal binary to work with Intel and PPC 32-bit and 64-bit systems. You can read the gory details in his blog.

  • 11. Brian Lokker  |  November 2nd, 2007 at 2:11 pm

    Hi David. I’ve followed all the instructions in the tutorial (Enabling PHP on Mac OS X Leopard). I get the Apache screen when I click on the “Your Computer’s Website” link in Web Sharing (it’s http://new-host.home/), but when I try to access http://localhost/ instead, I get an error message saying that Safari can’t connect to the server. Any ideas why that would be?

    (All this is a precursor to trying to reinstall the virtual hosts that I set up per your instructions in Foundation PHP for Dreamweaver 8 - and which were working flawlessly in Dreamweaver CS3 - until I upgraded to Leopard.)

    Thanks.

    Brian

  • 12. James  |  November 8th, 2007 at 8:48 pm

    Many thanks David for the excellent Apache/PHP on Leopard tutorial. It worked perfectly for me and it’s much appreciated.
    - James

  • 13. Eric Fields  |  November 13th, 2007 at 4:59 pm

    Thanks for the instructions on getting PHP working in OSX. That didn’t completely solve my problems, but it at least gave me proper errors.

    I couldn’t get PHP to talk to MySQL, so a quick google with my error and ‘leopard’ brought me to http://dev.mysql.com/doc/refman/5.0/en/mac-os-x-installation.html#c9026

    Thanks!

  • 14. Stephen Ashton  |  November 22nd, 2007 at 5:28 am

    Hi David,
    I am trying to start working with PHP with MBP on 10.4.11.
    When I try to test the Apache server on my mac (Apache version 1.3.33 installed with OS X - ) and get
    “Forbidden
    You don’t have permission to access /~steveashton/index.php on this server.

    Apache/1.3.33 Server at steve-ashtons-mbp.local Port 80″
    I know you have worked to solve this problem, but I am at a loss. Please tell me what steps to take to correct this so I can install PHP and start working with it.
    Thanks so much,
    Stephen

  • 15. Kevin Nigbur  |  December 3rd, 2007 at 7:41 pm

    Following the instructions of sudo cp php.ini.default php.ini and then attempting to find the file in the same directory as the default file… there is nothing there. Am I missing something?

  • 16. Sonya  |  December 6th, 2007 at 12:56 am

    David,
    Thank you so much for your detailed and very clear instructions. I am a new mac user as well as a new developer in PHP and mySQL, and I found your tutorial just before I was ready to toss my MacBook out the window!! LOL.
    I do have one issue that is still outstanding.
    I followed steps 14 & 15 (creating the test.php file) and when I load the URL into Safari, all I get is the code that I entered into the file. I see any PHP configuration screen. Do you have any suggestions?
    Once again, thanks so much for your help.

  • 17. Mark  |  December 7th, 2007 at 4:12 pm

    Thank you everyone for the helpful directions. I had already installed the Marc Liyanage php, and I made the tweeks to the files as indicated on the installing php on leopard post. But while my test.php page displayed correctly and snyced up with the book nicely, I couldn’t locate the GD extension the Essentials Guide says I should have. Does anyone know anything about this? I would really appreciate the help.

  • 18. David  |  December 14th, 2007 at 2:11 pm

    Kevin, sorry to be so long in replying. I don’t know what the problem might be, but take a look at comment 5 (from me) above. I spent ages not being able to copy php.ini.default. However, restarting the computer solved the problem.

  • 19. David  |  December 14th, 2007 at 2:34 pm

    Mark, I’m afraid that what you see is what you get with Leopard. The way Apple has configured PHP leaves out a couple of very useful extensions, one of which is gd. Marc Liyanage is working on a Leopard package that includes gd and many other features. He has a version that can be manually installed, but I haven’t tried it myself. If you’re interested in experimenting, there’s an extremely long thread in Marc’s forum. The instructions for installation are in a post by “jimhu” on the page I have just linked to.

  • 20. Mark  |  December 28th, 2007 at 1:03 am

    I don’t know if this is going to sound crazy to anyone, but I was wondering if anyone had encountered this. I installed php fine on my leopard upgraded ibook g4 and everything seemed to work, including my php test page. When I started developing with Dreamweaver I began to have an issue. I read and tried to figure it out, but couldn’t. And my iMac worked just fine no issues. Then I realized my HD was renamed for my name instead of the usual ‘Macintosh HD’ which is how it was on my iMac. I changed this and everything seemed to work fine. Has anyone ever encountered this or might know a reason why it happened?

  • 21. joe  |  January 5th, 2008 at 1:53 am

    I had to add the line
    mysql.default_socket = /private/tmp/mysql.sock
    to php.ini.

    (actually, I left out the /private.)

    I got this hint from http://www.456bereastreet.com/archive/200711/virtual_hosts_php_and_mysql_on_mac_os_x_105_leopard/

  • 22. chester  |  January 13th, 2008 at 1:56 am

    i agree.. im pissed with leopard that it is NOT VERY EASY to add extensions of php. ive been googling since afternoon yesterday how to add soap to php in leopard. no matter how i compile it with –enable-soap and linking the usr/bin/php to my new php compiled directory, it still doesnt work. freaking zend always overrides it. has anyone solved this one?

    i even tried to manually set the extension_dir and extension=soap.so but it says (null) in unknown line 0 something

  • 23. David G  |  January 16th, 2008 at 9:50 am

    Hello

    I’m having the problem whit “not being able to access your personal web page http://localhost/~your-name” as described in comment 1.

    I have not upgraded, but done a new installation of Leopard. The solution you are talking about is to copy from the “your-name.conf” file from the apache 1.3 folder. The problem is that I, because i didn’t do an upgrade installation, don’t have that folder. And I already have a “your-name.conf” in “/private/etc/apache2/users”.

    So it seems that I have the same problem but because of another reason? Do someone have an idea of what my problem can be?

    This is whats in my “your-name.conf” file if that helps:

    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all

    /David G

  • 24. David  |  January 16th, 2008 at 10:05 am

    Hi, David G. The location and contents of your-name.conf are fine. I experienced the same problem as you with one site, and it had me scratching my head for ages. I had copied and pasted the pages from elsewhere, and it turned out that the permissions were wrong. Select the folder in Finder, press Cmd+I to bring up a Get Info dialog box, and set the permissions to Read & Write for yourself, and Read Only for the two other user groups.

  • 25. David G  |  January 18th, 2008 at 10:00 am

    Thanks David for the help!

    It was my user folder who was set to only allow me to se the contents and therefore the sites folder was locked too because it is inside the user folder. Now it seems to work. Thanks!

  • 26. Henrik  |  May 19th, 2008 at 12:20 pm

    I’ve tried building a soap module for the stock php in leopard as well, without success. I really cannot figure out why it should be all that difficult. My struggles are documented here:

    http://www.entropy.ch/phpbb2/viewtopic.php?t=2956
    http://discussions.apple.com/thread.jspa?messageID=7046696&#7046696

    Has anyone gotten any further?

  • 27. Andre  |  May 27th, 2008 at 4:47 pm

    Solution

    1. Download & install XAMPP
    http://www.apachefriends.org/en/xampp.html

    2. Backup /usr/bin/php
    cp /usr/bin/php /usr/bin/php.backup

    3. Create a symbolic link to the XAMPP version
    ln -s /Applications/xampp/xamppfiles/bin/php /usr/bin/php

  • 28. David Powers  |  May 27th, 2008 at 5:38 pm

    @Andre: I presume you have been running XAMPP on a Mac without problems, but the XAMPP site still has this message on its front page concerning the Mac version: “WARNING: This version of XAMPP is still in the first steps of development. Use at you own risk!”

    I wonder if that’s an old message that hasn’t been updated?

  • 29. Whisller  |  June 15th, 2008 at 1:31 pm

    Yeah Leopard has a php 5.2.5 but it doesn’t support PostgreSQL, so if you want use it you must re-compile whole php.
    So I don’t see why they added PHP, so you must re-compile it if you want have extensions what you need.

    Better will be not adding apache and php. Then you can compile it by yourself with configuration what you need.

  • 30. David Powers  |  June 15th, 2008 at 1:39 pm

    Sure, but compiling PHP on a Mac isn’t easy. If you have the skill to do it, fine. But I suspect that most Mac users don’t. It would have been better if Apple had compiled a more fully featured version and made it part of the software update options when a new version of PHP is released.

  • 31. Marc Poirier  |  June 23rd, 2008 at 5:24 pm

    Hi.. After reading the posts I saw that Sonya had the same problem as I have, in the way that my test.php page only show the code, not the php page… Was this problem addressed? any clues?

    thanks

    Marc.

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

October 2007
M T W T F S S
« Sep   Dec »
1234567
891011121314
15161718192021
22232425262728
293031  

Most Recent Posts