While I was at zendcon I needed to setup my macbook with a typical apache/php/mysql server, but I was unsatisfied with both the default server that apple included and with the install system provided by XAMPP. I’ve since setup a server on both my MacBook and my iMac.
In order to get support for mysql as well as tools necessary for compiling, you need to install the apple developer tools. Check your original mac disc as you may already have a copy.
Anyway, on with our install:
Apache
First, download the latest version of the apache httpd web server.
$ ./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite
$ make
$ sudo make install
MySQL
Then download the latest mysql source file. Make sure you download the source “Compressed GNU TAR archive (tar.gz)” as we’ll need to custom compile it.
However, PHP5 no longer includes mysql shared libraries needed during the configure process. To get these, download the source file for the mysql version you just installed. Once downloaded, decompress it and run the following:
Update: As of MySQL 5.5 they’ve modified the build process. If you’re using an older version, skip the old configuration system below.
First, ensure you have CMake installed (via standard configure/make/install). Then, we’ll use cmake to configure mysql using the same options we’ve used in the original example.
$ cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DCMAKE_BUILD_TYPE=Debug
$ make
$ sudo make install
$ sudo mkdir /usr/local/mysql/run
$ cd /usr/local/mysql
$ sudo chown -R mysql:mysql *
$ chmod -R 777 /tmp
$ sudo ./scripts/mysql_install_db
$ sudo /usr/local/mysql/bin/mysqld_safe &
Pre-5.5:
$ ./configure --prefix=/usr/local/mysql --with-unix-socket-path=/usr/local/mysql/run/mysql_socket --with-mysqld-user=mysql --with-comment --with-debug
$ make
$ sudo make install</code>
$ sudo /usr/local/mysql/bin/mysql_install_db --force
$ sudo mkdir /usr/local/mysql/run
$ sudo mkdir /usr/local/mysql/data
$ sudo chgrp -R mysql /usr/local/mysql
$ sudo chown -R mysql /usr/local/mysql/run /usr/local/mysql/var /usr/local/mysql/data
Then start the server with:
$ sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &
zlib
Then, install zlib if it’s not already installed on your system. Download zlib, and it should be a basic ./configure, make, sudo make install process.
Once zlib is installed, make sure you know the path as we’ll need it during the php configure process.
PHP
Next, download the latest php package. Decompress it, and now we’re ready to configure.
$ ./configure --prefix=/usr/local/apache --enable-cli --with-mysql=/usr/local/mysql --with-zlib-dir=/usr/local --with-apxs2=/usr/local/apache/bin/apxs
$ make
$ sudo make install
Restart apache and test everything out. If php didn’t do it automatically, add in AddType application/x-httpd-php .php to your httpd.conf file – commonly located in /usr/local/apache/conf/httpd.conf.
Then, start your webserver.
$ sudo /usr/local/apache/bin/apachectl start
And finally, once everything is done you’ll want to setup your account to properly allow access to mysql and apache commands. Just run the following to add their paths to your bash profile:
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
echo 'export PATH=/usr/local/apache/bin:$PATH' >> ~/.bash_profile