Professional PHP

PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.
« Keywords and Language Simplicity
The Endpoints of the Scale of Stupidity on Video »

Working with PHP 5 in Mac OS X 10.5 (Leopard)

October 28th, 2007

PHPMac OS X is a great development platform for working with PHP. Leopard comes with Apache, PHP and many other development tools, such as subversion already installed. Leopard brings a much needed upgrade from Tiger's tired PHP 4 to a very modern version of PHP 5.2.4. This is a guide for setting up a PHP development environment under 10.5 using the version of PHP that ships with leopard.

You may prefer to use one of the 3rd party distributions of PHP, such as MAMP, XAMPP or Marc Liyanage. This is a guide to using the version of PHP that comes with 10.5.

Enable Developer Tools

These steps may not be strictly necessary for this process, but I find it useful to do them.
First, enable your root password.
You may also want to install XCode Tools from your Leopard disk (or grab the latest from Apple developer tools). The tools are required is you are going to compile any extensions for PHP.

Editing Configuration Files

We will have to edit several configuration files that exist as part of the unixy underpinnings of OS X. I'm going to recommend the free text editor, TextWrangler for this purpose. Normally, the finder hides the configuration files from view. However, in the finder, you can use the "Goto Folder..." option under the "Go" menu to view these files. This option if available via command-shift-G. Actually, this option is available in any file open dialog in OS X via command-shift-G. In addition, Text Wrangler will allow you to browse these files with its "open hidden..." option. But, the much easier option is selecting "Open file by name..." (command-D) and just typing the full path and filename. To save many of these files, you will need to enter your root password. Be Careful.

Enabling PHP

PHP is installed in Mac OS X by default, but not enabled. To enable it, we must edit the apache 2 configuration file, which is located at /etc/apache2/httpd.conf. Find the line which loads the PHP 5 module, which looks like this:

#LoadModule php5_module libexec/apache2/libphp5.so

The line is currently commented out. All we have to do is remove the comment symbol, #, so the line looks like this:

LoadModule php5_module libexec/apache2/libphp5.so

Save.

Starting Apache

Go to the sharing panel in system preferences and enable "Web Sharing." This will start the apache server.
Sharing Panel
Another way to do this is to type the following in the Terminal application:

sudo apachectl start

You will be prompted to enter your root password. After that, your apache server should now be running. If you need to restart the server from the terminal, you can type this:

sudo apachectl restart

If you find this tedious to type, there is a script that you can download to do this later in this post.

Visiting our Web Site

Now, lets check our work. In the sharing panel, you can click on the URL under "Your computer's website." Alternatively, in the web browser, go to the url http://localhost/. localhost is a special name that means "My computer." If your web server is working, you should see a page titled "Test Page for Apache Installation." If you go to http://localhost/manual/, you can read an Apache 2.2 manual, hosted from your own server. But, this don't tell you that PHP is working.
For that, we'll have to create a very simple php program. Create a new file in TextWrangler and type the following:

 
< ?php phpinfo(); ?>
 

(Don't just copy and paste this. Note that there should be no space between the < and the ?php. The WordPress software I use for this blog inserts an extra space.)
Save this using the file name info.php in the /Library/WebServer/Documents/ directory. (start from the top level directory of your hard drive, not the library directory in your home directory. Now you should be able to visit the PHP page you just created by visiting http://localhost/info.php. You should see the PHP logo and a big table of configuration information.

Showing the World

For security purposes, you should consider that anything you put in your WebServer/Documents folder will be available across the web. If you have information that you want to keep private, think twice about putting it there, unless you know how to protect it.
But, if you want people to see the pages that you are sharing, there can be a few obstacles. You can give out the URL that is listed in the sharing control panel under "Your computer's website." However, if you are behind a NAT router, such as I am, this IP address based url will only work for other computers on your network and not for the internet as a whole. You may have to configure network router or firewall in order to discover your true ip address and to route web server requests to that IP to your computer. Doing this is beyond the scope of this tutorial.
Additionally, IP address based urls don't make good urls to share. IP addresses can change. If you plan to host a permanent web site, you may want to purchase a domain name and point it to your Mac. This also, is beyond the scope of this tutorial.
Perhaps the best option is to purchase both a domain name and professional hosting. Apache based PHP Hosting is widely available and cheap. You can get support from a good host on uploading your files to the remote server. I'm going to presume that you will use one of the many excellent PHP hosting options and are only configuring PHP on your own machine for education, testing or development purposes.

Enabling a Personal Website

If you clicked on the URL under "Your Personal Website," you might have gotten a page that says forbidden. This is because in the default configuration in Leopard, unlike in Tiger, does not allow Apache to serve documents from home directories. If you want to enable this feature, you have to create a new Configuration file.
Create a new file with the following contents and save it to /etc/apache2/users/jeff.conf.

 
<directory "/Users/jeff/Sites">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</directory>
 

Replace "jeff" with your user name, which is also the name of your home directory. Exact capitalization is imporant. This tells the Apache server that it is ok to serve web content out of the ~jeff directory. You will have to restart Apache for this to take effect.
You may also have to create a Sites folder in your home directory to hold the files you want to serve. Leopard will automatically bless this folder with a special Icon.

Virtual Hosting

If you want to experiment with or work on more than one site at a time, the single directory in WebServer Documents and the Personal Websites configuration don't work well. Projects collide and files outside of your home directory can be harder to work with. The answer to this is to setup virtual hosting. Lets turn our Personal Website sharing solution into a virtual hosting solution that allows us to work with multiple websites as subdirectories of our Sites folder.
So, lets create a sample site, called mysite. We'll create a folder called "mysite" as a sub folder of our Sites folder. Capitalization is important.
Now, we are going to want to access our site with an easy to use domain name, so that our url is http://mysite/. There is an easy way to create new domain names that are only for personal use. To do this, we can add it to our /etc/hosts file. Add the following lines at the end of this file:

# My local aliases
127.0.0.1 mysite

127.0.0.1 is a special IP address designation that never changes and corresponds to localhost to mean this computer. We are telling our Mac that the name mysite is hosted on the local computer. This rule is only in effect on the same machine. If you go to a different machine, you cannot use the http://mysite/ url.
Now we need to configure apache for virtual hosting. We are going to have to edit our /etc/apache2/users/jeff.conf file. Change the contents of this file to the following:

 
<directory "/Users/jeff/Sites/*/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</directory>
 
NameVirtualHost *:80
 
<virtualhost *:80>
    DocumentRoot /Users/jeff/Sites/mysite
    ServerName mysite
</virtualhost>
 

Remember to replace "jeff" with your user name. Place your info.php test file into the mysite directory and rename it to index.php. Now, restart your apache server. When you visit http://mysite/, you should now see the familiar php logo and information page.
If you want to add another site, just add a second line in your hosts file, another subdirectory of Sites and append the following to your apache configuration file:
 
<virtualhost *:80>
    DocumentRoot /Users/jeff/Sites/myothersite
    ServerName myothersite
</virtualhost>
 

Sharing with the World, Part II

Sharing your virtual hosted sites with the world is more complicated if you don't have a domain name setup. You can, however, add your hosts files entries to other computers that you want to share with. However, you have to change the 127.0.0.1 IP address to the IP address of your computer, taking into account any NAT.
There is a special case of this. If you are using parallels, perhaps for test viewing your pages in internet explorer, you may want your virtual hosted sites to be available. The good news is that Windows also supports a hosts file. Here is how to edit your windows hosts file. The big problem is knowing what IP address to use. You can't use 127.0.0.1 on the windows side because that is the virtual windows machine, not your Mac's address. You can use the IP address shown on your network system preferences panel, 192.168.1.100 for me. But, this number is subject to change and you will have to re-edit your hosts file on the windows side.
If you are using Parellels, be sure to upgrade to the new beta version for Leopard, build 5540. Once you've done that, if you visit the network panel in system preferences and select the "Parallels Host-Guest" network, you will see the IP address that parallels assigns to your host machine. (assuming you are using Shared Networking.) You can then use this IP address in your windows hosts file. You may also be able to change "Using DHCP" to "Using DHCP with Manual address" and re-entering this number if you have a problem with the number changing. Here, my number is 10.37.129.3:

Network Preferences panel

Installing MySQL

MySQL has a binary distribution for Mac OS X. They also have reasonably good documentation on installing MySQL on Mac OS X for their distribution. Note that Leopard specific packages for MySQL have not been created yet.

Starting MySQL

So far, the MySQL preferences panel from the Tiger release is broken and does not correctly start and stop MySQL (bug report. You can do this from the terminal window with

sudo /usr/local/mysql/support-files/mysql.server start

To shutdown the server type:

sudo /usr/local/mysql/support-files/mysql.server stop

If you find this tedious to type, you can download WebDevCP, which is a small AppleScript application that I made. Launching WebDevCP launches both Apache and MySQL. Quitting the application shuts them both down. usually. Launching and quitting requires a password. No warranty on this thing. It was just something I was using personally and figured others might find useful.

Bring the mysql.sock to PHP

One problem that has come about with MySQL and Leopard is the location of the mysql.sock file. Previously, the default location for this file was in the /tmp directory. That location has now moved to the /var/mysql directory. PHP will look for it there. Unfortunately, the default location from the MySQL will still place it in the old location. We can fix this by creating a my.cnf configuration file in the /etc directory. Save a file with the following contents to /etc/my.cnf:

[client]
socket = /var/mysql/mysql.sock

[mysqld]
socket = /var/mysql/mysql.sock

In the terminal window, type the following commands to create the directory for the sock file:

sudo mkdir /var/mysql
sudo chown _mysql /var/mysql

One drawback to this is that if you have installed the MySQL GUI tools, they will look for the mysql.sock file at the old location. You can enter the new socket in the connection dialog under More Options, there is a box labeled "connect using socket." Just enter /var/mysql/mysql.sock.
Another solution is to change the php.ini file to expect the socket in a different location. I'm going with the my.cnf option because I expect the MySQL will have a Leopard version out in a few days that changes the default location.

Where is PEAR?

OS X has traditionally had problems with PEAR. Many point updates would overwrite the included version of PEAR with an older, and perhaps insecure version. Sadly, Apple has fixed this by not including PEAR at all in their OS. This is a big inconvenience for people wanting to use Apple's default version of PHP, versus a third party distribution. So, lets get PEAR installed. Type the following in the terminal window to download the PEAR installer:

curl http://pear.php.net/go-pear > go-pear.php

after that, type

sudo php -q go-pear.php

To run it. Hit enter to select the default locations. PEAR will be installed, but it won't be ready to use until we modify our php.ini file.

PHP .ini configuration

Now we need to make some changes to our php configuration file. Leopard has an empty configuration file by default, but provides a file which you can use as a template. From the terminal window, type:

sudo cp /etc/php.ini.default /etc/php.ini

Now, edit the /etc/php.ini file. Find the include_path setting:

;include_path = ".:/php/includes"

And change it to

include_path = ".:/usr/share/pear"

This enables our PEAR installation. You may also want to make some changes which will improve your ability to debug PHP. FInd the line that says

log_errors = Off

and change it to

log_errors = On

You have to then restart Apache for these PHP changes to go into effect.

Errors and Omissions

Thats all there is to using the version of PHP delivered with OS X. If you find this confusing, you are probably better off with something like XAMPP or MAMP. I'll probably end up compiling my own versions of PHP, but that is a different blog post. I've already had problems with this configuration when I tried to install XDebug via PECL. One last thing, if you run into problems, you can check the apache2 error_log file using the Console application.

For support, try the Sitepoint forums or Apple's Discussion Forums.

categories PHP, Mac
tags apache, mysql, php 5

Related Posts

  • Evolution not Revolution
  • Status of WACT
  • PHP first impressions from a J2EE programmer
  • PHP Framework Consolidation?
  • Delphi for PHP
You can leave a response, or trackback from your own site.

122 Responses to “Working with PHP 5 in Mac OS X 10.5 (Leopard)”

  1. #1 MonkeyT responds...
    October 28th, 2007 at 7:33 pm

    A very good walkthrough, covering every stumbling block I found while playing with Leopard this weekend except one. Apple's default install uses PDO, but only includes drivers for SQLite and SQLite2 - no PDO_MySQL, despite having both the MySQL and MySQLi extensions. I ran into the aforementioned pecl trouble, so I haven't gotten the pdo_mysql driver installed yet. My time's up for playing with 10.5 for a few days, but If you find a working patch for this, that may be a good thing to add to your tutorial. I'm sure it will be a common problem.

  2. #2 maetl responds...
    October 28th, 2007 at 10:40 pm

    I had various problems with the /etc/hosts file on OS X 10.4, but as it turns out there is an alternative less traditional way Apple does (did?) things, using the netinfo manager.

  3. #3 Ralph Martin responds...
    October 29th, 2007 at 4:37 am

    Because of the PDO MYSQL issue above, I tried to build my own version of PHP5, but ended up with a missing symbol to do with the XML library. Has anyone managed to build PHP5 successfully for Leopard? If so, care to share the trick?

  4. PHPDeveloper.org trackbacked on October 29th, 2007 at 6:19 am
  5. #5 MonkeyT responds...
    October 29th, 2007 at 6:28 am

    @maeti said: I had various problems with the /etc/hosts file on OS X 10.4, but as it turns out there is an alternative less traditional way Apple does (did?) things, using the netinfo manager.

    Yep, Tiger could use netinfo, but apparently Leopard has deprecated netinfo and the netinfo manager is no longer installed.

  6. #6 Mickey79 responds...
    October 29th, 2007 at 8:25 am

    I would like to add the "dbase" extension to the PHP installation on Leopard. Can I do that if I follow this method? If yes, How?

  7. #7 Acrobatic responds...
    October 29th, 2007 at 9:42 am

    Great post--this bugged me all weekend after my Leopard upgrade broke my Virtual Hosts... I miss NetInfo. The only tweak I'd recommend is to let people know to change their permissions on the example. I had to use

    chmod 755 mysite and
    chmod 755 * (inside the mysite directory)

    to get my sample page to show.

    Thanks for the instructions, this has been a big help

  8. #8 MonkeyT responds...
    October 29th, 2007 at 10:01 am

    upgrade broke my Virtual Hosts

    This is widely reported. During the upgrade process, apparently Apple's scripts don't properly account for the fact that /private/etc/httpd/users/ has now become /private/etc/apache2/users/ and fail to move the old user accounts to the new location. Simple fix, drag the files to their new home. Editing the accounts might trigger new file builds as well. New installs of Leopard don't have this trouble.

  9. developercast.com » Jeff Moore’s Blog: Working with PHP 5 in Mac OS X 10.5 pingbacked on October 29th, 2007 at 10:07 am
  10. Team BKWLD » Leopard Upgrade Breaks MySQL [READ: DON’T UPGRADE] pingbacked on October 29th, 2007 at 12:49 pm
  11. #11 wb responds...
    October 29th, 2007 at 1:17 pm

    Thanks for this! Quick lifesaver.

  12. #12 Karsten responds...
    October 29th, 2007 at 1:30 pm

    Thanks for all this instruction.

    Do you know what happened to pear DB? Previous to installing Leopard it was in /usr/lib/php/DB.php, now ??? The pear installation above doesn't seem to include DB - just MDB2.

    Please forgive my ignorance.

  13. #13 Karsten responds...
    October 29th, 2007 at 1:45 pm

    I just saw that DB is suspended. I will install the package for my older projects... Thanks.

  14. andare.ch - Blog » Blog Archive » Apache, PHP und MySQL unter Leopard (MAMP on Leopard) pingbacked on October 29th, 2007 at 2:17 pm
  15. #15 Lonnie Olson responds...
    October 29th, 2007 at 2:57 pm

    Your article is really good. Except for two small problems.

    1. Enable root password. This is completely unnecessary. It is not required to ever enable the root password. In fact, enabling the root account only further exposes your computer to security risks. Use sudo instead.
    2. Enabling a Personal Website. You said that personal websites is not configured by default. This is not true! See /etc/apache2/extra/httpd-userdir.conf. Also a specific /etc/apache2/users/username.conf is created for every user you create on the machine.
  16. #16 Jeff responds...
    October 29th, 2007 at 3:54 pm

    I'm glad this post is proving useful.

    Lonnie, I've updated the post to correct some typos and incorporate your two problems.

    Additionally, I've updated the Section on Parallels networking on how to discover the IP address of your Mac.

    In a couple days, I'll probably have a post on how to compile PHP from scratch under Leopard and add extensions such as XDebug.

  17. #17 Stan responds...
    October 29th, 2007 at 9:38 pm

    Looking forward to your directions for compiling, I've not had any luck due to problems with the mysql bindings.

  18. How to enable PHP 5 in OS X 10.5 Leopard pingbacked on October 30th, 2007 at 7:06 am
  19. #19 Stan responds...
    October 30th, 2007 at 7:41 am

    In order to get PHP to compile and run on OS X 10.5 you will need to do a couple of thin gs...

    First, if you want mysql support in your build - install the binary from mysql's website and then do the following:
    sudo mkdir /usr/local/mysql/lib/musql
    sudo ln -s /usr/local/mysql/lib/libmysqlclient.15.0.0.dylib /usr/local/mysql/lib/mysql/libmysqlclient.15.0.0.dylib
    sudo ln -s /usr/local/mysql/lib/libmysqlclient.15.dylib /usr/local/mysql/lib/mysql/libmysqlclient.15.0.0.dylib
    sudo ln -s /usr/local/mysql/lib/libmysqlclient.dylib /usr/local/mysql/lib/mysql/libmysqlclient.15.0.0.dylib

    Then, you will need to download the apache2 source. Apache2 needs to be recompiled because of an architectural error when compiling php. I've been unable to resolve this error by compiling PHP as a universal binary, so rather then waste anymore time apache is easy enough to compile we'll go ahead and just do that.
    ./configure --enable-layout=Darwin --enable-mods-shared=all && make && sudo make install

    Note, this install overwrites the existing 10.5 install. The upside of this is that it can be controlled via the Sharing Preferences.

    Then you should be able to compile PHP with apache2 just fine. If you want the newly compiled php to overwrite the existing one be sure to set --prefix=/usr otherwise set --prefix=/usr/local

    If you have any questions or want to know about compiling PHP with gd support feel free to drop me a line.

    Pax.

  20. #20 Nick responds...
    October 30th, 2007 at 10:40 am

    Is it possible to add postgresql support to the apple version of php? I'm about ready to give up on trying and just install my own copy of php and apache.

  21. #21 interfete evoluate responds...
    October 30th, 2007 at 4:29 pm

    Great post! I love programming with my mac. It's so much faster, and php is great to be programmed on a mac.

  22. #22 Rainer responds...
    October 30th, 2007 at 6:59 pm

    Very nice page.

    But unfortunately I ran into a problem when trying to install pear.

    (1)$ sudo php -q go-pear.php
    dyld: NSLinkModule() error
    dyld: Symbol not found: __zval_ptr_dtor
    Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20060613/libpdf_php.so
    Expected in: flat namespace

    Trace/BPT trap

    What might I have done wrong?

  23. #23 Keith responds...
    October 31st, 2007 at 9:31 am

    After upgrading to Leopard on the weekend I was madly searching the internet to get info on how to get my testing environment functional again.

    There are lots of sights with pieces of info, but this is far and away the best resource I found for getting your Apache, PHP and MySQL functional after upgrading to Leopard.

    Thanks for your detailed work!

  24. #24 Noel responds...
    October 31st, 2007 at 1:26 pm

    Thanks for the walkthrough! Saved me hours of stumbling around... :)

  25. Upgraded to Leopard | NSLog(); pingbacked on October 31st, 2007 at 2:50 pm
  26. Superfunkomatic - Observations of the Socially Inept » Blog Archive » holy frickin' updates batman pingbacked on October 31st, 2007 at 4:39 pm
  27. #27 superfunkomatic responds...
    October 31st, 2007 at 4:40 pm

    thanx so much for posting this. what a lifesaver! went through created the user conf files, changed the path to wordpress blogs and bob is your uncle - everything work like a charm. back in business.

    many thanx for sharing this information. sending you a virtual beer!

  28. #28 Josh responds...
    October 31st, 2007 at 6:26 pm

    @Rainer

    It isn't a problem with the go-pear script, it's a problem with the libpdf_php.so module. I've tried to install XDebug & pdo_mysql and I get similar errors. even doing php -v on the command line will give you the same error. Weird thing is that running a simple script like

     
     phpinfo();
     

    will run just fine and show the installed modules, but any semi complex script, or anything on the cli will fail, even if it doesn't actually call the custom module.
    For now if you comment out the libpdf_php.so module in your php.ini, pear should work.

    Hopefully someone will figure out the trick to compiling modules soon.

  29. Playing With Wire » Installing symfony on OS X Leopard pingbacked on October 31st, 2007 at 10:25 pm
  30. Glagla Dot Org » Blog Archive » Léopard est livré avec PHP5 pingbacked on November 1st, 2007 at 3:24 am
  31. Installer une plate-forme de développement PHP sur Leopard pingbacked on November 1st, 2007 at 2:28 pm
  32. Installer une plate-forme de développement PHP sur Leopard pingbacked on November 1st, 2007 at 2:28 pm
  33. kobak pont org » links for 2007-11-02 pingbacked on November 1st, 2007 at 6:27 pm
  34. #34 Joannou Ng responds...
    November 1st, 2007 at 9:52 pm

    This will be helpful to some folks:
    Migrating MySQL 5.0.45 to Mac OS X 10 .5 Leopard http://blog.tomatocheese.com/archives/2007/11/1/migrating_mysql_to_mac_os_x_leopard/

  35. #35 james responds...
    November 1st, 2007 at 10:48 pm

    Ran into the problem of trying to recompile PHP on OSX 10.5 Server when trying to add pdo-mysql. I too couldn't resolve the arch type errors. Thought about going with the recompile of apache2 route, and even got as far as ./configure && make, but didn't do the make install because I noticed that the configure script identified the system as i386.

    ... Now I know one of the big deals about 10.5 is that most (or all) of it is 64bit from the ground up. Including things like apache2 and mysql. I was able to muck around with the Makefile and get it to target i686, but how can be sure that it's compiling apache2 as a 64bit binary?

    I'm slightly less concerned about replacing apache2 with a 32bit binary on my MacBook Pro... but on a Xserve with apache2 being used for all the iCal CalDAV and wiki and webmail stuff, I'm a little more hesitant.

  36. ye.hu » leopard és web development pingbacked on November 2nd, 2007 at 3:25 am
  37. StringFoo :: Web Development Resources» Blog Archive » Leopard Upgrade Hell: Web Developers Hold Off pingbacked on November 2nd, 2007 at 4:45 am
  38. PHP auf Mac OS X Leopard | IT.CappuccinoNet.com Blog pingbacked on November 2nd, 2007 at 5:21 am
  39. #39 John Wooten, Ph.D. responds...
    November 2nd, 2007 at 1:42 pm

    Thanks for your advice. With some diddling around, starting and stopping, etc. I got my personal web server working again and my Mantis problem tracker going as well as the cvs viewer again. I am still having problems with getting a perl script that used to run under cgi-bin working. Obviously there is more to fix.

    Thanks.

  40. Outside the Box » Blog Archive » Spotted cat pingbacked on November 2nd, 2007 at 3:21 pm
  41. #41 Gabriel U. responds...
    November 2nd, 2007 at 9:16 pm

    These instructions are great and helped me get my development coding environment back on track. I thought I was going to have to spend weeks trying to get my computer to run Apache, PHP, and MySQL the way I had them running with Mac OS X 10.4 but I was able to get things running in a couple of hours with these instructions.

    Much appreciation goes to the person whom wrote and/or gathered all of this information.

  42. #42 Luke responds...
    November 2nd, 2007 at 9:43 pm

    Thank-you so much for posting these solutions!!
    I am very new to PHP, MySql and Apache and this page was a great help. I couldn't find any other information on how to get things working in Leopard.

  43. #43 Josh responds...
    November 4th, 2007 at 12:36 pm

    Looks Like we can't compile extensions under the Apple-supplied PHP:

    http://netevil.org/blog/2007/11/php-objective-c-bridge

    Hopefully Marc over at entropy.ch will get the Quad-binary thing solved soon...

  44. #44 bert responds...
    November 4th, 2007 at 1:44 pm

    Thanks, has helped to transfer to leopard...

    One remaining problem is that i can not access the virtual hosts from parallels. Windows always goes to the localhost directory location on the mac.

    My virtual hosts do not specify a port number, just a name and a different directory location. Works on the mac site, not on the pc site... I set all virtual server names to point to Parallels Host-Guest ip the in the windows host file...

  45. #45 Lee Cooper responds...
    November 4th, 2007 at 4:05 pm

    Just a quick note...I've spent the weekend trying to get this to work...obviously I'm not as technically adept as most of you guys, and as a recent Mac convert, not as familiar with the Mac yet either.

    Here's how I was able to get parallels to work so I could test my sites in IE. I installed Bonjour for Windows in my VM, then I could access my webserver running on my mac by using the URL http://macleemo.local (my mac is MacLeemo). I was then able to see my Joomla sites in both my Mac and parallels!

    Thanks for the great tutorial!

  46. #46 discoliam responds...
    November 4th, 2007 at 5:20 pm

    Just wanted to say, this was uber helpful. Annoying how Leopard doesn't allow Apache to serve documents from home folders. Its been buging me for days.

    Cheers.

  47. All adders are puffs… at Disco Liam pingbacked on November 4th, 2007 at 5:47 pm
  48. #48 Chris responds...
    November 5th, 2007 at 2:04 am

    Do you know how to add the GD libraries to PHP under OS X.5 leopard??

    I used to use Mark Lyanages packages for years and they came complete with that. Easy one-step installation which even restarted Apache when installing. . . . but I dont know enough about Compiling it myself to add GD image library support to PHP under Apache 2.

    Any detailed info would be GREATLY appreciated.

    THanks!

  49. #49 Nick Jennings responds...
    November 5th, 2007 at 4:03 am

    I stumbled across this article, and I'm glad I did.

    I always knew that apache was built into OS X, but I never knew that PHP was too. Up until now I've been using MAMP for all my development, but I reckon I will try and get rid of it now if I can MySQL to install and play nice!

    Thanks a lot.

  50. Enabling PHP 5 on Mac OS X Leopard at DavidCramer.net pingbacked on November 5th, 2007 at 10:52 am
  51. #51 John Grogan responds...
    November 5th, 2007 at 11:04 am

    Thanks! this post was a lifesaver

  52. Useless Nexus » Blog Archive » links for 2007-11-06 pingbacked on November 5th, 2007 at 9:30 pm
  53. PHP5 en Mac OS X 10.5 (Leopard) « Abraham Estrada - Abe Blog pingbacked on November 5th, 2007 at 11:06 pm
  54. Apple Leopard - Probleme mit apache , php und mysql at stephanhahn.ch pingbacked on November 6th, 2007 at 1:04 am
  55. #55 Daniel Haus responds...
    November 6th, 2007 at 11:13 am

    As for the pdo_mysql issue, that is nagging me too, if found this message here: http://discussions.apple.com/thread.jspa?messageID=5669164&#5669164

    Haven't tried it yet, but this seems to be the easiest and fastest way.

  56. #56 Leo Studer responds...
    November 7th, 2007 at 4:12 am

    Jeff, thank you for this clear instruction. Where are you with rebuilding PHP? Do you also have to rebuild Apache and Mysql? I am waiting for this new instructions, especially about XDebug...
    ...

  57. Enabling Your Personal Web Site on Leopard : Laran Evans pingbacked on November 7th, 2007 at 10:04 am
  58. Daniel’s Weblog » Blog Archive » Does anyone know how to get pdo_mysql working on Leopard? pingbacked on November 8th, 2007 at 4:57 pm
  59. #59 Marc responds...
    November 11th, 2007 at 5:56 am

    Hello, your topic is very interesting, and I have now a complete installation on my os 10.5, BUT, it is absolutely impossible to install a GD2 library, necessary for my business (building websites with Spip) ...

    I have download the php5 Liyanage package, but I dont know to enable this, Apple's Apache2 is always reading his own php5 ...

    If you have a solution, I will be very happy ... and excuse my english, I am writing from Paris (France) :-)

    Thanks a lot ... Marc

  60. Macpro.se - PHP 5 i Leopard pingbacked on November 11th, 2007 at 6:42 am
  61. #61 Jeff responds...
    November 11th, 2007 at 7:24 am

    I haven't done my from-scratch compilation of PHP on leopard yet, but it looks like that is the way to go if you want to use certain extensions. Meanwhile, I ran into a post on building mysql for os x.

  62. #62 Adam responds...
    November 13th, 2007 at 6:32 am

    Why does it appear to be so difficult to use PHP on Mac OS X? Is there no such program like MAMP for Mac? Like there's LAMP for Linux and WAMP for Windows.

    Friends at TalkPHP.com!

  63. #63 bugugly responds...
    November 13th, 2007 at 11:12 am

    @Rainer

    probably your /usr/bin/php is hosed
    If like me, you have installed Entropy or Zend or both, try the complete path on the command line.
    # /usr/local/php5/bin/php -v
    or
    # /usr/local/Zend/Core/bin/php -v

    When you decide which you want:
    # cd /usr/bin
    # ln -s php

    I linked both php and php-config to my entropy php and it is working so far. My pear was broken also and is now working again.

    Pretty sure this is not the best way, like if Apple updates your default php the links should get overwritten, but it works for now.

  64. #64 bugugly responds...
    November 13th, 2007 at 11:16 am

    Sorry

    #ln ---one you want--- -s php

    I used XHTML tags to mark the text after ln on the earlier post, and of course the text and tags disappeared.

  65. Buggy-Net.de - » Apache2, php, MySQL beim Leopard Mac OS X 10.5 pingbacked on November 14th, 2007 at 4:28 pm
  66. the scampo side » leopard LAMP dev environment, yeah! pingbacked on November 21st, 2007 at 11:25 am
  67. #67 Best PHP Books responds...
    November 22nd, 2007 at 6:27 pm

    I have many trouble installing PHP on my MAC. I have given up. I'm gonan give this tutorial shot and see what happens. Thanks for the tutorial thou.

  68. Get PHP working on Leopard (Mac OS X) » Datanomics pingbacked on November 23rd, 2007 at 8:49 pm
  69. #69 Joshua Adrian responds...
    November 26th, 2007 at 6:47 pm

    Anyone know how to get phpmyadmin up and running in combination with this tutorial.... i keep getting an "access denied for user 'root' @ 'localhost' (using password: NO) message.... have no idea what to do from here.... i have php and mysql running fine... this is the last piece i need

  70. #70 Miles Muri responds...
    November 27th, 2007 at 8:03 am

    @ Joshua

    You need to go into the phpMyAdmin directory and rename (make a copy) the config.sample.inc.php to config.inc.php. In the First Server section, fill in the required settings:

     
    $cfg['blowfish_secret'] = '**@@secret_blowfish_pass@@**'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
     
    /* 
     * Servers configuration
     */
    $i = 0;
     
    /* 
     * First server
     */
    $i++;
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    /* Server parameters */
    $cfg['Servers'][$i]['host'] = 'localhost';
    $cfg['Servers'][$i]['connect_type'] = 'socket';
    $cfg['Servers'][$i]['socket'] = '/var/mysql/mysql.sock';
    $cfg['Servers'][$i]['compress'] = false;
    /* Select mysqli if your server has it */
    $cfg['Servers'][$i]['extension'] = 'mysql';
    /* User for advanced features */
    // you can use root here if your computer if you are comfortable with that or create a special user 
    $cfg['Servers'][$i]['controluser'] = 'someuser'; 
    $cfg['Servers'][$i]['controlpass'] = 'somepass';
     

    Works for me so far...

    Miles

  71. lucashansendotcom » PHP5 on Leopard pingbacked on November 28th, 2007 at 10:18 pm
  72. #72 Chris responds...
    December 4th, 2007 at 4:00 pm

    Thanks to the authors for putting this tutorial together. It was very helpful in getting me up and running with Apache 2 and PHP 5 on Mac OS X Leopard. One thing that I did not find in this tutorial that I had to do was to edit the "Document Root" and "Directory" commands in Apache's httpd.conf file to point to my Sites directory. A mention of this would be nice.

  73. #73 Erik responds...
    December 13th, 2007 at 9:21 am

    I have successfully got apache and php running on Leopard, however I'm having an issue with mySql. I get the following error in the terminal when running:

    sudo mysql_secure_installation

    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
    SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

    In order to log into MySQL to secure it, we'll need the current
    password for the root user. If you've just installed MySQL, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.

    Enter current password for root (enter for none):
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

  74. #74 Robert Nyman responds...
    December 13th, 2007 at 1:44 pm

    Great and very useful article! Thank you!

  75. #75 caruso_g responds...
    December 16th, 2007 at 4:07 pm

    Hi, first of all thanks for this great tutorial. Everything works great!
    Except for Rails. Going, through terminal to create class instances into the database tables, it puts out this error message:

    >> story = Story.new
    Errno::ENOENT: No such file or directory - /tmp/mysql.sock

    It goes looking for the mysql.sock to the default location, but having changed it to the var directory it doesn't find it.
    How can we solve it?

    Thanks anyone for the help.

  76. #76 Andy responds...
    December 16th, 2007 at 9:03 pm

    what do I do once I've installed go Pear? I don't know how to list the available packages. Could someone give me the next step. The last thing I did (from above instructions) was change:
    include_path = ".:/usr/share/pear"

    If I look in /usr/share there is no pear folder in there.

  77. #77 Moreno responds...
    December 19th, 2007 at 2:27 am

    Thanks a lot buddy. Worked very well. Just perfect.

  78. Null is Love » Blog Archive » Taming Leopard for PHP pingbacked on December 19th, 2007 at 12:10 pm
  79. Tuaregue » Apache no Leopard pingbacked on December 22nd, 2007 at 4:18 pm
  80. One Thousand Words » Blog Archive » PHP, MySQL and Leopard pingbacked on December 27th, 2007 at 8:43 am
  81. #81 screenmates responds...
    December 29th, 2007 at 1:16 am

    You can install a completely different set of LAMP on OS X using Mac Ports.

  82. #82 tomtom responds...
    January 8th, 2008 at 8:30 pm

    Thanks a bunch for your time on this - helped my a great deal, everything fell into place as described. Muchos!

  83. Waffle With Meaning » Installing PHP, MySQL and phpMyAdmin on OS X 10.5 (Leopard) pingbacked on January 9th, 2008 at 5:27 pm
  84. #84 Stifo responds...
    January 22nd, 2008 at 6:20 pm

    Another solution for mysql.sock, that works for me:

    sudo mkdir /var/mysql
    sudo chown _mysql /var/mysql
    sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

  85. #85 Stifo responds...
    January 22nd, 2008 at 6:23 pm

    Another solution for mysql.sock that works for me:

    sudo mkdir /var/mysql
    sudo chown _mysql /var/mysql
    sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

  86. Demiurgic Design» Blog Archive » Pear and pdo_mysql in Apache2 on Leopard pingbacked on January 25th, 2008 at 8:13 am
  87. PolyMicro Systems » Blog Archive » Working with PHP 5 in Mac OS X 10.5 (Leopard) - Professional PHP pingbacked on February 8th, 2008 at 5:23 pm
  88. #88 wobbie responds...
    February 9th, 2008 at 3:24 pm

    I had installed on 10.4 the php package from Entropy, which installs php in /usr/local/php5

    I simply upgraded my box to 10.5 and slogged thru the issues.

    What I didn't ponder was this.

    Since php is installed as part of 10.5, where is this installed version of PHP? That is, where is the native version of php installed at?

  89. #89 john responds...
    February 11th, 2008 at 2:32 am

    how about viewing the error_log on local.... anybody who has an idea?

  90. #90 paul responds...
    February 12th, 2008 at 4:30 pm

    Hi and thank you for the info setting up Apache in Leopard was a pain in the ass until I found this site. One question what do I create a new Configuration file in? Do i use test wrangler or something else? Thanks for all the help and info it is a life saver!

  91. #91 Michael responds...
    February 21st, 2008 at 8:19 pm

    Hi Guys,

    I have followed all the instructions and was able to uncomment the line to enable php. I then created the info.php file and saved it.
    When I open the browser and got http://localhost/info.php I see the actual text in the browser

    eg: i see this in the browser.

     

    Another php file i created does the same. Is there any reason why I see text, not the result of phpinfo()?

    Any help would be great.

  92. #92 Michael responds...
    February 21st, 2008 at 9:41 pm

    Forget my above post. I just didn't restart the web sharing after uncommenting the line in the apache config file.

    Cheers,
    Michael.

  93. #93 Michael Carruth responds...
    February 22nd, 2008 at 6:30 pm

    Stifo gets the platinum star for Post 84...it was the only thing that worked for me!

    Thanks, dude!

  94. #94 Mike responds...
    February 23rd, 2008 at 8:59 am

    Thank you for your work. You have a very readable manner of writing, easy to follow, not too much info and not too little. Thanks.

  95. #95 PHP Encoder responds...
    February 26th, 2008 at 4:49 am

    Thanks for the instructions, it really helps me

  96. #96 Damon responds...
    February 27th, 2008 at 11:16 am

    For GD and possibly others that were left out, check out:
    http://docs.moodle.org/en/Step_by_Step_Installation_on_a_Mac_OS_X_10.5_Server#Install_the_GD_Library_on_the_Mac_OS_X_10.5_Server

  97. #97 Keith responds...
    March 1st, 2008 at 10:44 am

    everything was working fine until i tried setting up the personal web site and every time of put “http://mysite/” i got the following error message - afari can’t open the page “http://mysite/” because it could not connect to the server “mysite”.

    And i can't work out what's wrong - i am very much a novice at this stuff HELP HELP

    Keith

  98. Indiscripts » Blog Archive » Apache, PHP, and MySQL in Leopard pingbacked on March 2nd, 2008 at 6:21 am
  99. #99 Tom responds...
    March 3rd, 2008 at 10:34 am

    Thanks for the hints

    One drawback to this is that if you have installed the MySQL GUI tools, they will look for the mysql.sock file at the old location. You can enter the new socket in the connection dialog under More Options, there is a box labeled "connect using socket." Just enter /var/mysql/mysql.sock.

    You can also enter 127.0.0.1 instead of localhost. Also some other applications will got no connection to MySQL using localhost, but when using 127.0.0.1 all works fine.

  100. Blog Rambler » Blog Archive » Development Web Server pingbacked on March 12th, 2008 at 7:02 pm
  101. #101 Jago Svensson responds...
    March 15th, 2008 at 3:42 pm

    Hi.
    Is there someone with a precompiled executable for php-cli 5.2 for OSX leopard with GD included.

    I mean the executable under /usr/bin/php about (13Mb)

    I would be very thankfull if someone could mail this to me.
    jago (at) jago.se

    Regards Jago Svensson

  102. #102 Tony Reed responds...
    March 17th, 2008 at 7:44 am

    I've downloaded and installed a Pecl extension, and when I try to run PHP (from the command-line) with the extension enabled, I get the following error:

    dyld: Symbol not found: _zend_register_long_constant
    Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20060613/id3.so
    Expected in: flat namespace

    and I don't know how to go about compiling the extension from scratch to try to figure it out.

    I've installed Pear, and it works fine. I've done this before, I know how and what to edit in php.ini.

    OS X 10.5.2, PHP 5.2.4, Zend Engine 2.2.0

    Anyone? Sorry, but this is annoying, and no one seems to know how to fix it.

  103. #103 RichSad responds...
    March 18th, 2008 at 8:00 am

    I have the same problem as someone above. I did this and there is no pear in
    /usr/share/pear

    the only pear I find is in:

    /private/var/root/bin/pear

    any idea why it ended up there? I have root enabled and did the whole sequence of events under su command (logged in as root).

  104. #104 Tony Reed responds...
    March 18th, 2008 at 11:29 am

    @RichSad, reply #103

    When you ran go-pear, you were presented with a screen that showed you where it was going to place the stuff. If you were logged in as root, then root's home directory is /var/root and if you just hit the "enter" key, you instructed go-pear to install the binaries for pear and pecl in /var/root/bin, which is go-pear's default which is relative to where it's called from.

    To run these binaries in place you can log in as root and run

    bin/pear
    bin/pecl

    and so on.

    I like this well-written set of instructions, but I think that telling novice users to work as root is a mistake. Anyway, I think you should move the binaries into some place that's in your $PATH as a non-root user.

  105. links for 2008-03-19 « Ramblings of an Eccentric Soul… pingbacked on March 19th, 2008 at 12:19 pm
  106. Configure Web Dev on your Mac - MAMP | I'm Knight pingbacked on March 22nd, 2008 at 9:40 am
  107. #107 Maciej Przybecki responds...
    March 30th, 2008 at 9:07 am

    It seems that after last Leopard security update 2008-002 my custom php installation (which replaced system one) stopped working. The php binary was replaced and it doesn't load gd.so and mysql.so modules anymore.

    I tried to recompile and reinstall php again but it breaks on linking, claiming aboud undefined symbols of iconv.

    Any ideas ?

  108. #108 Jonathan Bryan responds...
    March 31st, 2008 at 2:45 am

    Great Article.

    One question. Where is the proper place to install pear??

    go-pear wants to install in the current user's directory by default, but in your example, it appears that you installed to /usr/share/pear.

    Any advice would be greatly appreciated.

  109. #109 at responds...
    April 1st, 2008 at 4:02 pm

    Thank you for hints - it saved me a lot of nerves.

  110. #110 xurizaemon responds...
    April 16th, 2008 at 12:50 pm

    @Adam: http://www.google.co.nz/search?q=mamp or http://www.google.co.nz/search?q=xammp

  111. #111 Zhivko responds...
    April 27th, 2008 at 6:17 am

    works like a charm! thank you so much, excellent post, saved me weeks of frustration..

  112. JaideawHosting Admin Blog! » Blog Archive » Working with php in mac 10.5.X pingbacked on April 28th, 2008 at 4:04 pm
  113. #113 Paul responds...
    April 29th, 2008 at 1:57 pm

    Thanks so much for this post. The others didn't cover the full process or explain things properly. This made all the difference!

    Thanks

  114. #114 Patrick responds...
    April 29th, 2008 at 4:05 pm

    How great it is to have things explained so well :)

  115. #115 Anonymous responds...
    May 1st, 2008 at 6:49 am

    I've got Leopard on my G5 and I'm trying to get php with oracle oci to work with apache2

    I haven't a clue how to get this done.

    Before I upgraded from 10.4, I had Oracle running with Apache1 with php5 with OCI and no problems. Ever since the upgrade to Leopard my website has been effectively down.

    Any help would be greatly appreciated.

    Regards,

    dajon@comcast.net

  116. #116 todd responds...
    May 4th, 2008 at 11:27 am

    Looking for advice on how to compile php as and embedded library. I amusing this for configure

    ./configure --enable-embed --with-curl -enable-ftp --enable-zip --enable-sockets --enable-static --enable-soap --with-zlib --with-bz2 --enable-exif --enable-bcmath --enable-calendar

    I keep getting this error after running make

    ld: duplicate symbol _yytext in Zend/.libs/zend_ini_scanner.o and Zend/.libs/zend_language_scanner.o

    collect2: ld returned 1 exit status
    make: *** [libphp5.la] Error 1

    I have no idea what this means

    any ideas... thanks

    Todd

  117. #117 kisasi responds...
    May 4th, 2008 at 8:27 pm

    Thanks so much for the virtual hosts setup!!

  118. #118 Tapas responds...
    May 5th, 2008 at 3:00 pm

    Hi, I am trying to enable php. I followed most of the instruction, but it shows me the whole php code just like any other text file in the browser. doesn't show anything else than purely those texts. I am using Leopard 10.5. Do you think, you can help ?

  119. #119 website design responds...
    May 6th, 2008 at 10:36 am

    how na i install the DG2 Extension???

  120. #120 xentek responds...
    May 6th, 2008 at 10:23 pm

    @website design

    you don't. not with out much hair pulling and gnashing of teeth. switch to an all-in-one or try Mac Ports (more advanced terminal use required)

  121. #121 Luis Oscar Cruz responds...
    May 7th, 2008 at 12:37 pm

    How can I revert ?

    sudo mkdir /var/mysql
    sudo chown _mysql /var/mysql

  122. #122 hzpevghnte responds...
    May 7th, 2008 at 7:06 pm

    Wow, cool man, big thanks! http://etfdqecxzxdhq.com

Leave a Reply

XHTML: You can use these tags: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <div align=""> <em> <font color="" size="" face=""> <i> <li> <ol> <strike> <strong> <sub> <sup> <ul>

code: use [code=php][/code].

Comment Preview

  • Search

  • Subscribe

    Subscribe All Posts
    Subscribe All Comments
    Subscribe All Bookmarks
    Subscribe with Bloglines Subscribe with My Yahoo Add to netvibes Subscribe in NewsGator Online Subscribe with Google feed reader
  • Share This

  • Categories (Home)

    • Agile Methods (14)
    • Mac (14)
    • Misc (16)
    • Open Source (14)
    • PHP (93)
    • Software Design (27)
    • Usability (14)
    • WACT (7)
    • Web Design (20)
  • Recent Comments

    • Sarah Snow Stever  23
      Snowcore, ennah, Philippine Website Developers [...]
    • PHP Development From Java Architects Eye  9
      Bobrila, FelhoBacsi, Angsuman Chakraborty [...]
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  83
      hzpevghnte, Luis Oscar Cruz, xentek [...]
    • Improved Error Messages in PHP 5  9
      ennah, Khumaer, retry [...]
    • The value of MVC  9
      Vulchak, อะไหล่แอร์, Alyson Serrano [...]
    • Why PHP is easier to learn than Java  13
      , , WTF [...]
    • Yahoo YUI wins JavaScript Library Wars  9
      cfkjdiqovw, Jeff, Patrick Mueller [...]
    • goto in PHP  38
      Goldilocks, , SFM [...]
    • Decline of Google  3
      Dallas Graham, Will Mcclure, Harry Fuecks
    • Mouse problems with Safari 1.3 after using Expose  1
      Leigh Townsend
    • Design Eye for the Usability Guy  1
      Holli Holden
  • Pages

    • Tags
  • Recent Posts

    • Sarah Snow Stever
    • Benchmarking PHP’s Magic Methods
    • The Endpoints of the Scale of Stupidity on Video
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)
    • Keywords and Language Simplicity
    • Improved Error Messages in PHP 5
    • Michigan Taxes Graphic Design Services
    • Ruby versus PHP or There and Back Again
    • Mighty Mouse Kryptonite and Exceeding Expectations
    • reCAPTCHA - Combining Distributed Problem Solving with a Web Service
  • Archives

    • 2007: Jan Feb Mar Apr May Sep Oct Nov
    • 2006: Jan Feb Mar Apr May Jun Jul Oct Nov Dec
    • 2005: Jan Feb Mar Apr May Sep Oct Nov Dec
    • 2004: Apr May Jun Jul Aug Sep Oct Nov
  • Menu

    • Register
    • Login