boztek

: [Boris Gordon]

Install LAMP stack from source on Mac OS X 10.6 Snow Leopard using Homebrew

Install LAMP stack from source on Mac OS X 10.6 Snow Leopard using Homebrew

Here is a guide on using Homebrew to install a PHP 5.2 based stack that will live along side the PHP 5.3 that the Mac OS X 10.6 ships with. Currently this installs MySQL 5.1.41, PHP 5.2.12 and all dependencies.

It is for use with the Apache that ships with Snow Leopard and is compiled as 64-bit binaries on appropriate hardware, using the LLVM compiler.

The four easy steps are:

  1. Install Homebrew
  2. Grab my PHP 5.2 formula (Homebrew’s individual build scripts)
  3. Start the build, grab coffee, stare at screen
  4. Finish mysql install, edit apache config, restart apache

Install Homebrew

The following assumes you have installed XCode (get it from the Snow Leopard install disk or download from Apple), don’t have git installed(1) and have no /usr/local folder(2). Homebrew is a lightweight system for installing free software on the Mac (Snow Leopard optimised) from source. By default, all software is installed into /usr/local.

The easiest way to get Homebrew is to download and run the following commands at the terminal. They will build a copy of git in the process and link your local Homebrew to the mainline which is the quick way to get new build scripts.

$   sudo mkdir /usr/local
$   sudo chown -R `whoami` /usr/local
$   curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local
$   brew install git
$   cd /usr/local
$   git init
$   git remote add origin git://github.com/mxcl/homebrew.git
$   git pull origin master

Now you are ready to get the homebrew formula for PHP 5.2 and build a fresh stack.

Grab my PHP 5.2 formula

I am going to assume that you have installed Homebrew at /usr/local and are managing it with git - this would be the case if you used the instructions above. To get my PHP 5.2 build scripts, simply track my fork of Homebrew and merge in the php52 branch:

$   cd /usr/local
$   git remote add boztek git://github.com/boztek/homebrew.git && git fetch boztek
$   git checkout boztek/php52 && git checkout -b working
$   git pull --rebase origin master

If the last line causes a conflict during a rebase, don’t worry, just skip any failing patches:

$   git rebase --skip

Now when you want to keep up with the latest formulae in the main line of Homebrew you can re-run that last line:

$   git pull --rebase origin master

Start the build, grab coffee, stare at screen

The following command will build PHP 5.2 and MySQL with dependencies:

$   brew install php52 --with-mysql --with-apache

You might want to grab a beer as is also the Homebrew best practice …

Finish mysql install, edit apache config, restart apache

You just need to finish the MySQL install, set up your php.ini to your liking, point apache to your new PHP and restart the web server:

$   launchctl load -w /usr/local/Cellar/mysql/5.1.41/com.mysql.mysqld.plist
$   mysql_install_db
$   mysql_secure_installation

Recommended options are: change the root password [Y], keep the anonymous user [n], disallow remote root [Y], keep test database [n] and reload privilege tables [Y].

Your new PHP 5.2 has its own configuration which is symlinked to /usr/local/etc/php.ini. You’ll want to edit this to increase memory limit, upload and post sizes.3

The last step is to point apache to the module installed at /usr/local/Cellar/php/5.2.11/libexec/libphp.so. You can do this by symlinking the module into /usr/libexec/apache2/ (be very careful not to clobber the built-in module)

$   sudo ln -s /usr/local/Cellar/php52/5.2.12/libexec/apache2/libphp5.so /usr/libexec/apache2/libphp5.2.so

or leave it where it is, pointing to the right one in /etc/apache2/http.conf. Your http.conf should now have lines like this:

# LoadModule php5_module        libexec/apache2/libphp5.so
LoadModule php5_module        libexec/apache2/libphp5.2.so

Finally restart apache and test it out …

$   sudo apachectl graceful-stop
$   sudo apachectl start
$   echo "<?php phpinfo(); ?>" > ~/Sites/php52.php
$   open http://localhost/~$USER/php52.php

  1. If you already have git installed and are comfortable using it you could install Homebrew by making sure /usr/local exists, fixing permissions (sudo chown -R whoami /usr/local) and then running the following:

    cd /usr/local
    git init
    git remote add origin git://github.com/mxcl/homebrew.git
    git pull origin master

    You can now skip to step 2 and grab my php 5.2 formula. ↩

  2. To install homebrew in /usr/local if you already have files there, move the local folder somewhere else, install homebrew, then copy the files back. ↩

  3. If you are planning on copying a php 5.2 config file from somewhere else, rather than editing in place, make sure you copy the file to the /etc folder underneath /usr/local/Cellar/php52 and not /usr/local/etc so as to keep the symlink intact. ↩

Mysql not found

Hi, first congratulations by this project are very good.

I have installed php 5.2.11 thanks to you. I only had a small problem, when brew tries to download mysql does not find it (http://mysql.llarian.net/Downloads/MySQL-5.1/mysql-5.1.39.tar.gz) the only thing that I did was to change the URL so that it worked correctly (http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.39.tar.gz) in library/Formula/mysql.rb

So you are up and running?

The mysql formula is maintained elsewhere but I'll check instructions are still working and fix mysql if needed. Post here if you are stuck.

first delete usr/local

after deleting the local folder I was able to run the script all went fine. changed the httpd.conf to libphp5.2.so as described -- but what I saw was nothing douldn't even connect to mysql because of lack of the sock command.

so fetched me some beer and wait for another Mac-Update - BELCH

is mysql running?

Type 'ps aux | grep sql' and see if mysql is running - if not then type 'brew info mysql' to find the command to start mysql.

advices too fuzzy

so... I think after the third try I found out that homebrew from pkg-installer would not help git from the installer also. cut out the line that stops working when usr/local exists and then could not continue with that failure: * Installing git using homebrew Failure!

so what... (why do you put such advices on the internet?)

greez tom

check footnote 2 in instructions

Footnote 2 covers this possibility or as you have discovered if there's nothing there you need to keep you can just delete the local folder all together.

Got it working

Ok, found out what was wrong and found an solution. When I ran sudo apachectl -t I got the following error:

httpd: Syntax error on line 116 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/libphp5.2.so into server: dlopen(/usr/libexec/apache2/libphp5.2.so, 10): Library not loaded: /usr/local/Cellar/libiconv/1.13.1/lib/libiconv.2.dylib
Referenced from: /usr/libexec/apache2/libphp5.2.so
Reason: Incompatible library version: libphp5.2.so requires version 8.0.0 or later, but libiconv.2.dylib provides version 7.0.0"

I then found this page: http://code.google.com/p/git-osx-installer/issues/detail?id=18#c6

Thanks for your work with the howto!
regards, ollu

apache's DYLD_LIBRARY_PATH being defined is the issue

open /usr/sbin/envvars and either add to DYLD_LIBRARY_PATH or comment it out entirely.

Interesting

That's strange - my script is supposed to download and build libiconv 1.13.1 and then the php build is configured to use libiconv in /usr/local.

I didn't have to remove the system libiconv myself and it is not recommended.

I might have tried "brew uninstall libiconv && brew install libiconv" but at least you're up and running now.

The current version of my

The current version of my scripts will build a version of libiconv and use that to link to when building PHP but will leave the snow leopard version in tact and the default when compiling other software.

Apache want start

Hi,

Thanks for this howto! Really helpful, I might add that the first time I run the setup I got some troubles with "brew install php52 --with-mysql --with-apache" it threw me a bunch of errors. But then I desided to run it again and now no errors appeared.

And now to my actual problem: When I start apache (sudo apachectl start) all seems fine but when I try to access localhost it says "Unable to connect" as if the server wasn't running. Do you have any idea of what could be wrong?

Well, I restarted Terminal

Well, I restarted Terminal and tried again and things worked. Not sure what was going on there, but problem solved. Great work!

Let me know if you have any

Let me know if you have any problems - I'd like to keep this post as fresh as possible.

MySQL error

I'm getting an error when the mysql part of this runs. No idea what this is and searching hasn't pulled up anything. Any ideas? I'm running OS X 10.6.1.

Having this MySQL error

Having this MySQL error too

checking for specified location of the MySQL UNIX socket... /tmp/mysql
checking for MySQL UNIX socket location... /tmp/mysql
configure: error: Cannot find MySQL header files under /Users/jeduan/opt/brew/lib/mysql.
Note that the MySQL client library is not bundled anymore!

usr/local already there

MacBook-Pro:~ admin$ chmod u+x homebrew-install.rb MacBook-Pro:~ admin$ ./homebrew-install.rb /usr/local already exists, you'll want to move this out of the way first!

so.... whats next, the other methods didn't work because I'm stuck here:

MacBook-Pro:local admin$ git remote add boztek git://github.com/boztek/homebrew.git && git fetch boztek fatal: Not a git repository (or any of the parent directories): .git

git and homebrew were installed with their pkgs but what now(?):

MacBook-Pro:local admin$ git remote add boztek git://github.com/boztek/homebrew.git && git fetch boztek fatal: Not a git repository (or any of the parent directories): .git

homebrew and git seems to be very nice but ::: I'm stuck

Thanks for your work!