Because I travel a lot by train, it’s easy to have a local development environment with me. Because OSX Leopard contains Apache2 and PHP 5.2.6, I installed MySQL, ZF, PEAR, setup the vhost conf for apache and added the path to the ZF and PEAR libraries to /etc/php.ini. This seemed to work fine for a day or two, but after that I needed to use the PDO_MySQL library. This didn’t really work… The fact is that PDO_SQLite and PDO_SQLite2 are compiled along the installed PHP library, but PDO_MySQL isn’t… Big FAIL!.
So, we’ll have to setup a new PHP/Apache2 combo…..
Okay let’s start:
If you haven’t done it already, install the Developer Tools(XCode 3) from the OSX DVD
If you haven’t installed MacPorts on your system, do so by downloading it from the MacPorts website and running the installer.
Now open a terminal window and update MacPorts:
sudo port selfupdate sudo port sync
Create the following directory and symlink for the correct use of MySQL (the install searches there for libraries):
sudo mkdir /usr/local/mysql/lib/mysql sudo ln -sf /usr/local/mysql/lib/lib* /usr/local/mysql/lib/mysql/
Install Apache2:
sudo port install apache2
Let the apache2 process be autostarted by the system:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist
Move the old Apache stuff out of the way:
sudo mv /usr/sbin/apachectl /usr/sbin/apachectl-leopard sudo ln -s /opt/local/apache2/bin/apachectl /usr/local/bin/apachectl
Copy the sample conf file and make it the default
sudo cp /opt/local/apache2/conf/httpd.conf.sample /opt/local/apache2/conf/httpd.conf
Now you can modify your apache settings to your liking, but remember to use only the ones in the /opt/local/apache2/conf directory; the old configs(/etc/apache2/conf) are not used anymore.
Then make sure we have everything installed we want in there; I want: GD libraries, iconv, PDO_MySQL, curl
sudo port install jpeg sudo port install libpng sudo port install freetype sudo port install libmcrypt sudo port install tidy sudo port install libiconv
Rename the default iconv.h because it generates errors while compiling PHP
sudo mv /usr/include/iconv.h /usr/include/iconv.h.leo_orig sudo ln -s /opt/local/include/iconv.h /usr/include/iconv.h
Download the php5.2.8.tar.gz file from the PHP website.
go to your download directory and run
tar xvzf php-5.2.8.tar.gzThen move this folder to the /opt/local/php-5.2.8 folder
sudo mv php-5.2.8 /opt/local/
Then create a symlink that you can compile against:
sudo ln -s /opt/local/php-5.2.8 /opt/local/php
Go into the newly created ‘folder’:
cd /opt/local/php/
Now configure PHP:
'./configure' \ '--prefix=/opt/local/php' \ '--with-apxs2=/opt/local/apache2/bin/apxs' \ '--with-xsl=/usr' \ '--with-tidy=/opt/local' \ '--with-ldap=/usr' \ '--with-kerberos=/usr' \ '--enable-mbregex' \ '--enable-ftp' \ '--with-iodbc=/usr' \ '--with-curl=/usr' \ '--enable-mbstring' \ '--with-gd' \ '--with-jpeg-dir=/opt/local' \ '--with-png-dir=/opt/local' \ '--with-zlib-dir' \ '--enable-sockets' \ '--enable-exif' \ '--with-mcrypt=/opt/local' \ '--enable-soap' \ '--with-mysql=/usr/local/mysql' \ '--with-mysqli=/usr/local/mysql/bin/mysql_config' \ '--with-pdo-mysql=/usr/local/mysql/bin/mysql_config' \ '--with-mysql-sock=/tmp/mysql.sock' \ '--with-freetype-dir=/opt/local' \ '--with-openssl=/opt/local' \ '--with-iconv=/usr' \ '--with-libxml-dir=/usr' \ '--with-xmlrpc' \ '--enable-cli'
Then make and install php:
sudo make sudo make install
And rename the old PHP and create a symlink to the new binary:
sudo mv /usr/bin/php /usr/bin/php-leopard sudo ln -s /opt/local/php/bin/php /usr/bin/php
copy the new php.ini file and edit it to your liking:
sudo cp php.ini-dist lib/php.ini
Note: The new php.ini file in use is the one located at: /opt/local/php/lib/php.ini
Up until now the old webserver was running. Shut it down and then start the new apache2:
sudo apachectl-leopard stop sudo apachectl start
If all went well, Apache is running and PHP scripts get executed. Please check the installed features by calling a page with the following code on it, to ensure everything is installed.
<?php phpinfo(); ?>
In the next post we will add xDebug to the stack and later on the debugging environment is setup for different IDEs.
Part2: Installing xDebug on OSX
Nice howto!
There is an easier way to install all these components on OSX. Have you considered using ‘MAMP’? It’s an all in one installer for apache, mysql and php on osx.
Thanks !
Yes I know ‘MAMP’ and other nice packaged PHP/APACHE/MySQL bundles that come pre-compiled for OSX.
This could work for a lot of people, but in my experience the bundled packages don’t give me the flexibility I need/want/am used to.
If there are new versions out for PHP or for the supporting libraries I like to be able to use them; this is easier to do with a standard unix install of this software then when using all custom paths and libraries that are compiled within these paths.
If people don’t have a lot of unix/osx knowledge and just need to get their AMP(Apache,MySQL,PHP) stack running for development, good alternatives are (in order of preference) XAMPP , EasyLamp, MAMP or MAMPStack.
Strange… php doesn’t seem to work when I follow these steps. The php entry is in httpd.conf, and the new apache instance is running, but I get nothin!
Hi Ryan,
I’m sorry to hear it’s not working right away, I forgot to mention to alter the apache config to point to the folder you want to have your htdocs in and to point apache to your PHP module. Apache also has to be instructed to use the PHP module for a certain type of file and has to be instructed to call index.php instead of index.html if it’s available.
Could you please state if all of the following apply:
an entry in your httpd.conf loadmodule section, stating the following:
LoadModule php5_module modules/libphp5.soand somewhere at the end of the config file, or as in my case, in an external file that gets included:
What’s the exact result you get if you’re calling a php file containing only:
Do you get a blank page, or a page showing the script above ?
What do the apache logs(access- and/or errorlog) return on accessing this page ?
(location of the logfiles in this config: /opt/local/apache2/logs
Thanks for the tip. I had previously compiled my own version of php and apache on our OS X development web server. Well, the 10.5.6 update broke libphp5.so. I could not start apache, which complained of the following error: httpd: Syntax error on line 143 of /etc/apache2/httpd.conf: Cannot load /usr/local/apache2/libexec/apache2/libphp5.so into server: dlopen(/usr/local/apache2/libexec/apache2/libphp5.so, 10): Library not loaded: /usr/local/lib/libpng12.0.dylib\n Referenced from: /usr/local/apache2/libexec/apache2/libphp5.so\n Reason: Incompatible library version: libphp5.so requires version 35.0.0 or later, but libpng12.0.dylib provides version 1.0.0
I spent two days trying to recompile. I followed your instructions and everything works now. I like having everything in /opt/local, which should help prevent breakage from future Apple updates.
I did need to change the configure script slightly, since it complained about iconv even after creating the symlinks.
Here’s the syntax I used with the configure script:
‘–with-iconv=shared,/opt/local’
Thanks again for sharing.
-Jon
Hi Jon,
Thanks giving feedback. I’m glad at least some of the post was helpful to you.
Could you please tell me if you’re using OSX or OSX-Server ? Also, could you check if
php -msays that the iconv module is compiled in successfully ?
Thanks again.
Thank you Max. This was by far one of those sublime installation / configuration moments that come by so infrequently. Bravo!
Hello!
I had the same problem but I fixed it without recompiling everything.
I found it on apple discussions.
PDO_MYSQL
1. Download PDO_MYSQL / http://pecl.php.net/package/PDO_MYSQL
2. cd ~/Downloads/PDO_MYSQL-x.x.x/PDO_MYSQL-x.x.x
3. phpize
4. ./configure ‘–with-pdo-mysql=shared,/usr/local/mysql5′
5. make
6. sudo make install
NB! The /usr/local/mysql5 is your mysql installation directory.
php.ini
1. Add points 2. and 3. to /private/etc/apache2/php.ini
2. extension_dir = “/usr/lib/php/extensions/no-debug-non-zts-20060613″
3. extension=pdo_mysql.so
[...] my previous post we installed the latest apache and php from source and now I’d like to install xDebug to it. [...]
Hi Max…
I just found your blog and it like a breath of fresh air. Truly. I’ve had a long week, and I’m looking forward to running through the steps you’ve outlined installing php5.2.8 on Leopard, tomorrow, when my eyes have had some rest.
I’m not a unix whiz by any stretch of the imagination and had no idea that getting the pdo_mysql driver enabled would produce so much grief.
I’ll be back but until then here is a link to post of mine at the apple discussion forums appealing for aid and comfort on this very issue. No takers as of 2-4-09. Oh well.
http://discussions.apple.com/thread.jspa?threadID=1892407&tstart=0
Hi John,
Thank you for your nice words.
I’ve posted a reply to the question you asked on the Apple forums.
The easiest way of installing MySQL/Apache2/PHP with a lot/most common modules installed is by using one of the packaged installers I mentioned in my comment dated 31 December 2008.
If you like to get more experience and ‘feel’ for using the command line and configuring and installing from commandline, following howtos like on malisphoto and on this site are perfectly fine.
I hope my suggestion on the Apple Forum works for you. If not, just reply on the forum or post here.
Cheers,
Max
Thank you, Max. You are a godsend.
John
Hi Max…
I’m afraid I’ve made an impressive mess, and feeling a nice case of vertigo.
Full disclosure:
Just before I found you –and in a moment of angst and desperation which I’m sure you can empathize with, I gave up and installed a Marc Liyanage package referenced here at an apple discussion post: http://discussions.apple.com/thread.jspa?threadID=1669076.
In the second post there is a Liyanage ‘package’ link: Marc’s php 5.2.4 is what comes with this link. I know it was a step backwards in version, but I was feeling desperate.
In retrospect I’d guess that installing Marc’s package broke anything I did following the malisphoto tutorial. http://www.malisphoto.com/tips/php-on-os-x.html
Even so, I followed your suggestion and edited the httpd.conf to: ——LoadModule php5_module libexec/apache2/libphp5.2.8-pdogd.so——then stopped and restarted apache. NOTE: The file libphp5.2.8-pdogd.so still exists: /usr/libexec/apache2/libphp5.2.8-pdogd.so
I then pointed my browser [Firefox 3] to the server but it won’t connect.
–ERROR LOGS–
–SYSTEM Error Log
/private/var/log/system.log shows this:
Syntax error on line 115 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/libphp5.2.8-pdogd.so into server: dlopen(/usr/libexec/apache2/libphp5.2.8-pdogd.so, 10): Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib\n Referenced from: /usr/libexec/apache2/libphp5.2.8-pdogd.so\n Reason: no suitable image found. Did find:\n\t/usr/local/mysql/lib/mysql/libmysqlclient.15.dylib: stat() failed with errno=62
–APACHE error_log
/private/var/log/apache2/error_log shows this:
[Thu Feb 05 07:52:22 2009] [notice] Digest: generating secret for digest authentication …
[Thu Feb 05 07:52:22 2009] [notice] Digest: done
[Thu Feb 05 07:52:22 2009] [notice] Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7l DAV/2 PHP/5.2.6 configured — resuming normal operations
[Thu Feb 05 07:54:34 2009] [notice] caught SIGTERM, shutting down
–QUESTIONS–
1. Where do I go from here?
2. The development stack as I understand it, is made up of three pieces that are knit together to form a working unit: apache, php, mysql.
Can each of these parts be changed or upgraded independently of one another without disturbing the other two? Or, has my messing with Leopord’s natively installed PHP compromised the Apache and MySQL installations?
3. I’m interested in growing my knowledge. Trial by fire is certainly an effective if painful teacher, but is there a more systematic way to go about it?
I imagine you have a full life, so thank you very much Max for making time for me.
John
Hi Max…
I’m reinstalling, and going through the steps you’ve outlined above. It’s now 11am EST
I’ll be back with the results.
John
I am having a rough time getting this to work on my Macbook. I have done everything and all was great until I tried to call the phpinfo page and I get 404. Any suggestions? I am at my wits end with this.
Cheers,
David
Hi David,
I Assume you forgot to change the DocumentRoot and the“> in /opt/local/apache2/conf/httpd.conf. If you change these to reflect the settings from the previous httpd.conf located in /etc/apache2/conf and then restart apache it should work.
Please let me know if this helped.
Max,
That worked famously, thank you!
Now could you verify that I still need to reconfigure mysql and phpMyAdmin for my previous work to show up. I am currently getting an Database Error: Unable to connect to the database:Could not connect to MySQL. When I try to connect to my new configuration. I will say though that my computer “web address” changed during the process and I am unsure when that happened but, do I just need to go into my old phpMyAdmin and update the server address. I know there was a file set-up for that I just cant recall what the name of it is or where it was located.
Thank Again, it was a big help!!
Cheers,
David
ok so I do have the new apache2 and php 5.2.8 up and running but I can only see this when I call test.php in the address bar with the actual IP address as like http://172.27.173.70/test.php. The problem lies in the fact that all my website stuff I was working on before the upgrade to the latest apache/php was located on “localhost” In fact i can call the old version of php 5.2.6 through the localhost/test.php. I know this is probably an alias issue but I am a newbie and at my whits end as to where to continue/start looking. Do I need to recompile mySQL and phpMyAdmin and move all my files over to opt/local for this all to work? And BTW…….when I finally get all this worked out should I or could I totally remove the old apache/php stuff from my puter or would that be a bad thing?
Cheers,
David
Hi Max,
I followed your instructions and all seemed to work. However I now do not seem to have the correct permissions to browse sites on my machine. It states “You don’t have permission to access…”.
I have already updated my DocumentRoot in httpd.conf.
Any recommendations?
Thanks,
Ari.
Hi Ari,
Please have a look in your /opt/local/apache2/conf/httpd.conf and change th following line from the main block (the one that points to your web-directory) from
to the following:
And make sure to have the following set or included in the same file:
Hope it will get you better results now….
Cheers!
I tried to configure php and got a error at the end. It says:
configure: error: mysql configure failed. Please check config.log for more information.
I checked the config.log, and there are actually several errors mentioned. Lots of them seem to have to do with finding files related to gcc.
Are these important, or should I just ignore the errors and continue?
Thanks,
John
Hi Max,
Thanks for this walk through.
After following your direction my “infophp.php” file is still displaying my old php version php 5.2.6.
Strangely enough I can navigate to the php 5.2.8 directory in /opt/local/
and it’s link as “/opt/local/php”.
Typing “which php” as root generates “/usr/bin/php” which is a link to “/opt/local/php-5.2.8/bin/php”
Am I missing a step here?
Jan
Hi John,
Sorry to hear it generates errors.
For me it’s very difficult to troubleshoot remotely. Things you could check:
Hope this gives you some leads…
Hi Jan,
Did you stop the current running version of “Websharing” (The shipped version of Apache2).?
you could check this by running:
If you see /usr/bin/httpd in this list, you need to type
sudo apachectl-leopard stopor turn off “Web sharing” from the “system preferences” -> “Sharing” tab.
then (re)start the newly installed apache:
sudo apachectl restartThen try the testpage again….
Good luck!
Hi Max,
Thanks for the great walk through.
PHP didn’t function as expected until I added:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html
To the end of the httpd.conf file as you explained to Ari. Now all works.
Wondering how to set up Apache to create a new site directory for each added user as the default Apple configuration does?
Joseph
Hi Joseph,
Apache doesn’t add the Sites directory; OSX adds the directory to your userfolder if a new useraccount is created.
Apache does load it into the configuration. To enable this do the following:
make sure the following module is loaded in your httpd.conf:
LoadModule userdir_module modules/mod_userdir.soYou now have to add the following line to the httpd.conf to direct apache to the right subfolder below the userdir:
UserDir SitesTo set the permissions correctly you’ll have the following to the httpd.conf too
After restarting your webserver with sudo apachectl restart, calling the URL: http://localhost/~username should direct you to the /Users/username/Sites folder.
The rights have to be set for each user; this won’t work automatically anymore. If there is enough response I could write a post on how to fix some of this.
I’m attempting to follow this tutorial, so i can get a web dev environment set up on my system so I can learn PHP. When I open my terminal to execute second step, I get the following error (It won’t accept my password)
——————————————————
Last login: Sat Apr 18 19:43:10 on ttys000
Ditko:~ Ditko$ sudo port selfupdate
WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type “man sudo” for more information.
To proceed, enter your password, or type Ctrl-C to abort.
Password:
Sorry, try again.
Password:
Sorry, try again.
Password:
——————————————————
Any ideas of what I might be doing wrong? When I type, nothing appears in the terminal following the word ‘Password:’
Any help?
Thanks
Hello Ditko,
If you need a dev-environment to learn PHP and you aren’t very skilled in the OSX base-system/unix terminal, it might be better to opt for an all-in-one solution like XAMPP (or one of the other packages listed in the 2nd comment).
Good luck !