NOTE: this howto is now pretty outdated. I'll probably be reinstalling Leopard in the near future because Apple hates me so I'll update it when I rebuild.
Over the past many weeks, I've been tasked at well over 100% completing a not-so-secret project. If I've blown you off in email or on IRC, I'm sorry. I've been too busy to deal with much of anything, and I've let many things slide (as can be witnessed by this Friday night blog post). Do ping me again, if I missed you.
The not-so-secret project is a complete rewrite of the php|architect site including a brand new codebase for our store, which also hosts Python Magazine.
Anyway, one of the things that happened during development was an upgrade to Mac OS X 10.5 - Leopard. There are a bunch of things wrong with Leopard, but over all I'm pretty happy with it. I did, however, have a bit of a hard time getting my development environment up and running (I did a clean install). After the jump, I'll outline the steps that I took to get a functioning Apache, PHP, MySQL installed. Sure, you could use the leopard-bundled Apache and PHP, but if you're like me, you generally upgrade PHP (and use weird extensions) a lot more often than Apple will upgrade it.
Built on Rasmus' birthday. How appropriate (-:
First, a couple things should be noted: I'm still without local SSL support on Apache. I've been in touch with the maintainer of apache2 on macports (who, coincidentally, is probably familiar to many of you due to his past work on the PHP project: James Cox), but I still don't have a solution. See this bug report for info. The second thing is that my colleague/client/boss/friend (wow.. that sounds like a dangerous combination!) Marco helped me out quite a bit with the initial leopard-friendly incantations to make things build.
On with the compiling!
First things first: you'll need to download/install some packages. You'll need Xcode from the Leopard Install DVD, or from here. Xcode contains the compiler tools and a bunch of other stuff for Mac OS. Be forewarned: the download is bigger than 1GB!
Download and install MySQL from here. Yes, it says 10.4, but it works fine with Leopard (for me, anyway). Install it and the startup item that's in the DMG.
Then, download and install Macports this is the OS X port of the FreeBSD Ports system, and while I prefer pre-built packages like those offered in Fink (apt-get is nice), when I checked installing Fink on Leopard consisted of weird contortions involving a bootstrap from Tiger. No thanks. Install macports.
You'll also need a recent version of PHP. I have 5.2.5. Get it here.
Now that you have the necessary files, you'll need to fire up Terminal. The beauty of OS X is that when the GUI fails you, there's an underlying unix system that does what you command! (-:
MySQL installs strangely. Let's fix that. As root do this:
[code]
ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql #needed for PHP, later
mkdir /usr/local/bin #user-installed binaries
ln -s /usr/local/mysql/bin/my* /usr/local/bin #put utils like mysql (client) and mysqldump in your path
[/code]
With MySQL taken care of, we'll move on to ports. Again, as root:
[code]
port selfupdate #makes sure ports is up to date
port sync #syncs with the remote port index (like apt-get update)
[/code]
Now, let's use ports to install the necessary packages. Again as root:
[code]
port install apache2 # install apache 2.2.x
port install apache2 # yes, you need to do it twice, thanks to a bug that doesn't see awk the first time
launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist #startup item (as instructed by the apache port output)
cp /opt/local/apache2/conf/httpd.conf.sample /opt/local/apache2/conf/httpd.conf # copy the config file
mv /usr/sbin/apachectl /usr/sbin/apachectl-leopard # move the bundled apachectl out of the regular path
ln -s /opt/local/apache2/bin/apachectl /usr/local/bin/apachectl #and move the port-installed apache2 into the path
[/code]
Congratulations. Apache is (almost) installed (-:
As root, you'll need to: edit /opt/local/apache2/conf/httpd.conf and comment out this line: LoadModule ssl_module modules/mod_ssl.so (see the bug mentioned above).
[code]
sudo apachectl start
[/code]
Then point your browser at localhost. You should get a page stating "It works!" Now, let's build PHP.
Before you do, you'll need to port install some libraries (depending on your configure line for PHP; mine's below). As root:
[code]
port install jpeg
port install libpng
port install freetype
port install libmcrypt
port install tidy #leopard comes with Tidy, but it's got a broken header file
[/code]
Unpack the downloaded php tarball and cd to the directory where you extracted it. Here's my configure line:
[code]
'./configure' \
'--prefix=/Users/sean/php' \
'--with-apxs2=/opt/local/apache2/bin/apxs' \
'--with-xsl=/usr' \
'--with-tidy=/opt/local' \
'--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-pdo-mysql=/usr/local/mysql/bin/mysql_config' \
'--with-mysql-sock=/tmp/mysql.sock' \
'--with-freetype-dir=/opt/local' \
'--with-openssl=/opt/local' \
'--without-iconv' \
'--enable-cli'
[/code]
Then make and sudo make install. You should now have a functioning PHP. I moved the leopard-bundled PHP out of the way and mine into its place with this (as root):
[code]
mv /usr/bin/php /usr/bin/php-leopard
ln -s /Users/sean/php/bin/php /usr/bin/php
[/code]
The only thing that remains is to tell Apache how to handle PHP files. Add these lines to /opt/local/apache2/conf/httpd.conf:
[code]
LoadModule php5_module modules/libphp5.so # make install should have done this for you
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps
[/code]
You may also want to tweak the default DirectoryIndex to add index.php.
Now, create /opt/local/apache2/htdocs/info.php with the following contents:
[code][/code]
Then, sudo apachectl restart.
If all went well, you should see your new php's phpinfo output.
If not... something went wrong (or I screwed up the instructions). Either way, post a comment, and I'll try to help.
Hope this helps you.. it would have saved me a few hours, if I had run into something similar.
S
Why would you not want to simply install everything from MacPorts to make it all easier to update? If you're going to use MacPorts for Apache, you may as well go all out.
My port install command goes something like:
sudo port install apache2
Then after it dies on awk:
sudo port install apache2 && sudo port install sqlite && sudo port install mysql5 +server && sudo port install php5 +apache2+macosx+mysql5+pear+sqlite
I usually also tack on subversion, curl, ruby, ImageMagik, and a variety of others, but that gets the general idea. From then on the latest versions are simply a "sudo port upgrade outdated" away.
Actually you can make it even shorter by just typing:
sudo port install php5 +apache2 +mysql5 +pear +sqlite
That will actually install apache2, mysql5, and php5 in the proper order. Worked great for me.
Huh :) It's work.
You can also use the apache 2.2 64bit and php 5.2.4 version that comes with Leopard. Just customize the apache configs in /etc/apache2/. Works fine for me. Don't understand why you install it all twice. I use osx 10.5.1.
This helped me heaps, thanks Sean!
The only things I couldn't get it to compile with were iconv (Leopard problem?) and imap (MacPorts error with the cclient library). All my other extensions were fine.
I think using of MacPorts is the best way. I'm fan of MacPorts...
Hello,
thanks a lot for your informing tutorial on setting up a apache server on Leopard :)
But me being new to the Terminal and the UNIX structures of my Mac i cetrainly did something wrong, because the info.php i put into /opt/local/apache2/htdocs/ givers me:
Fatal error: Call to undefined function phpÊphpinfo() in /opt/local/apache2/htdocs/info.php on line 1
I really followed every line of your tutorial without any errors (except the awk problem, but after second command it worked as well) and still i get this error ! Any idea why this is happening ?
Best regards,
Christian
Hi Christian,
Looks like you have a weird character between ?php and phpinfo() "Ê" should simply be a space.
(btw, if you get that error message, it means that PHP is working—congrats! (-: )
S
Thanks for a great how-to! Everything worked as expected and I found Macports to be really useful for some other stuff as well.
I have followed these instructions on 2 Macs and they worked perfectly. I am trying to do it again on a fresh install of Leopard on an iMac and it won't work for some reason. The apache install doesn't work correctly. It acts like it is still trying to start up Leopard's Apache. I have followed the instructions correctly. When I run sudo apachectl start, I get the following error"
httpd: apr_sockaddr_info_get() failed for ESJMac.local
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
I have gone in and edited my httpd.conf to add a ServerName and it still doesn't work. If I try to run sudo apachectl stop, I get a no pid error.
Any ideas how I can fix this?
I've tried a couple of times to install php but its not creating half the files. I can't find the main php binary files or php.ini for example.
I'm a new user to Mac and have been familiar with unix commands for some time now, I found this tutorial to be very clear and concise Worked perfectly for me anyway!! Thanks for taking the time.
Also great comments on the macports suggestions, very informative!
Have done everything step by step so far:
- made sure I had the latest Xcode
- downloaded and installed MySQL (from above link)
- downloaded and installed MacPorts (from above link)
- downloaded latest PHP distribution (from above link)
- took care of the "strange MySQL install" with first three command line prompts
...now, I'm trying to do the "port" command line prompts, but my system is not recognizing the "port" command:
-bash: port: command not found
Any ideas about what's going on? Any help would be appreciated...
Seems port isn't in your path.
Try /opt/local/bin/port in place of port
S
Thanks alot, everything went fine! :)
I'm finding someway to access mysql, seems I need something like mysqladmin >.
Hi, I'm having a issue with mysql. I followed all the steps but when configuring php I get:
checking for mSQL support... no
checking for MSSQL support via FreeTDS... no
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... /tmp/mysql.sock
checking for MySQL UNIX socket location... /tmp/mysql.sock
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.
I can post some of the config.log if needed. Maybe I missed a part.
Same here on 10.4.11 client / MySQL 5.0.51 / PHP 5.2.6 ...Michael, did you ever figure out what went wrong?
This is driving me nuts. The libraries are sitting right there in /usr/local/mysql:
-rwxr-xr-x 1 root wheel 2110319 Apr 17 06:50 libmysqlclient.15.0.0.dylib
-rwxr-xr-x 1 root wheel 2110319 Apr 17 06:50 libmysqlclient.15.dylib
-rw-r--r-- 1 root wheel 2851924 Apr 17 06:50 libmysqlclient.a
-rwxr-xr-x 1 root wheel 2110319 Apr 17 06:50 libmysqlclient.dylib
-rwxr-xr-x 1 root wheel 2118307 Apr 17 06:46 libmysqlclient_r.15.0.0.dylib
-rwxr-xr-x 1 root wheel 2118307 Apr 17 06:46 libmysqlclient_r.15.dylib
-rw-r--r-- 1 root wheel 2867452 Apr 17 06:46 libmysqlclient_r.a
-rwxr-xr-x 1 root wheel 2118307 Apr 17 06:46 libmysqlclient_r.dylib
Biggest THX!
This tutorial kicks ass!! Don't know If I ever could have done this on my own!
I've used this twice now and it's worked each time, no hitches. Thanks for the great write-up.
Quick follow-up...any quick direction on getting this all with mysqli included as well? Is it as simple as adding '--with-mysqli=/usr/local/mysql' \ into the config?
You ROCK. Thank you for saving my day.