Here are step-by-step instructions on how to install Apache, MySQL, PHP & Postgres on OS X 10.6. There are plenty of places providing pretty much the same details, but sometimes their instructions don’t work terribly well.
First off, here are our objectives:
- Apache 2.2.15
- MySQL 5.1.46
- PHP 5.3.2
- Postgres 9.0 alpha5
- Microsoft SQL Server connection support
This is on a Macbook Pro, running OS X 10.6.2
I have two additional requirements too; Apache must replace the existing OS X version, and support virtual directory user configurations, so I can have multiple sites running on the same instance.
NOTE: these steps are based largely on what you can find here: http://adylitica.com/2009/11/24/installing-amp-apache-mysql-php-on-mac-os-x-10-6-snow-leopard/
Another note: All of these instructions assume that you’re comfortable with using the Terminal and the ./configure, make etc commands.
Also, you’ll have to manually navigate to the appropriate directories to run each of these commands.
Last note: All of the necessary files have their version number included. You will probably find that these have since been updated. That’s fine, but I can only guarantee that the versions I’ve named will work.
Step 1: Software update.
Make sure your new OS X 10.6.x installation is completely up-to-date. Run a ‘software update’ check first. You’ll also need to install the Xcode tools if you haven’t already.
Step 2: MySQL
I could not get MySQL working with the version explicitly labelled for OS X 10.6. PHP would completely fail to recognise it. So make sure you download the x86_64bit version for 10.5. Perhaps this issue will be fixed in the future.
Download: MySQL 5.1.46-osx10.5-x86_64.dmg
Installation: This is a handy installer application, so no worries here.
Step 3: Memcache
Memcache is pretty handy to make websites work faster. It’s worth installing, but optional.
Download:
Installation:
Libmemcached:
./configure && make && make install
Libevent:
./configure && make && make install
Memcached:
./configure && make && make install
Step 4: OpenSSL
OpenSSL has been updated to version 1.0. OS X already has OpenSSL included, but you can upgrade it if you want.
Download: OpenSSL 1.0.0
Installation:
./config && make && make install
Step 5: cURL
cURL is a pretty handy interface, which if you do any serious PHP development, you’ll probably need at some point.
Download: cURL 7.20.1
Installation:
./configure –with-ssl=/usr/local/ssl –enable-thread
make && make install
Step 6: ImageMagick and GD Support
ImageMagick is pretty cool, and GD support is something you’ll probably need too, so we’ll install all the necessary files now.
Download:
Installation:
Imagemagick: The Imagemagick page has instructions on how to get the binaries working. Just copy the files to a location of your choice, and run the tests they give.
Freetype:
./configure && make && make install
Libpng:
cp scripts/makefile.darwin Makefile
make && make install
Jpegsrc:
./configure && make && make install
Tiff:
./configure && make && make install
Step 7: LibSSH2
This will let PHP communicate with SSH servers.
Download: LibSSH 1.2.5
Installation:
./configure && make && make install
Step 8: Apache
You have Apache on OS X, but we’ll be upgrading it. This will replace the existing Apple installation, and allow you to use the user configuration .conf files.
Download: Apache 2.2.15
Installation:
./configure –enable-layout=Darwin –enable-mods-shared=all
NOTE: –enable-mods-shared=all is probably overkill. You could also try –enable-mods-shared=most for a reduced set.
Check that you have user .conf files, at a location like this: /etc/apach2/users/geoff.conf. If you do, and you plan on using virtual hosts, make sure that this line is in the .conf files:
NameVirtualHost *:80
You can set up a virtual host like this:
<virtualhost *:80>
DocumentRoot /Users/yourname/Sites/yoursite
ServerName yoursite.local</virtualhost>
Edit the /etc/hosts file to include this line:
127.0.0.1 yoursite.local
Step 9: Postgres
We’ll be installing Postgres, ‘cos I like it better than MySQL. If you don’t do this bit, then you’ll need to modify the PHP configuration string to exclude the Postgres includes.
Download: PostgreSQL 9.0alpha5
Installation: You’ll need to create a ‘postgres’ user via ‘Accounts’ in the System Preferences panel of OS X. Then follow the instructions which are included in the Postgres readme file.
Add the Postgres path to the shell:
export PATH=$PATH:/usr/local/pgsql/bin
Step 10: FreeTDS
This is required for MSSQL connection support. If you don’t think you’ll be connection to SQL Server, then you can skip this step.
Download: FreeTDS 0.8.2
Installation:
./configure –enable-msdblib
This will install FreeTDS into /usr/local. You need to provide this location in the PHP configuration settings if you’re using MSSQL.
Step 11: PHP
We will be creating a PHP installation with support for:
- APC (code caching)
- ImageMagick
- SOAP (better than using PEAR)
- Memcache
- Zlib (file compression)
- OpenSSL
- Multibyte string support (mbstring)
- mbregex
- cURL (ability to retrieve web requests)
- SSH2
- PEAR
- MySQL
- Postgres (pgsql)
- SQL Server support (mssql)
- PDO (a better database connection method)
- GD (a graphics manipulation library)
First, go to pecl.php.net and download the following:
Download: PHP 5.3.2
Now we need to patch the iconv function. OS X 10.6 is a bit strange in how this works.
Create a file called ‘patch’, with the following content:
— php-5.3.0/ext/iconv/iconv.c 2009-03-16 22:31:04.000000000 -0700
+++ php/ext/iconv/iconv.c 2009-07-15 14:40:09.000000000 -0700
@@ -51,9 +51,6 @@
#include
#endif-#ifdef HAVE_LIBICONV
-#undef iconv
-#endif#include “ext/standard/php_smart_str.h”
#include “ext/standard/base64.h”
@@ -182,9 +179,6 @@
}
/* }}} */-#ifdef HAVE_LIBICONV
-#define iconv libiconv
-#endif/* {{{ typedef enum php_iconv_enc_scheme_t */
typedef enum _php_iconv_enc_scheme_t {
Patch the inconv file, by finding the iconv directory, usually inside the PHP source directory at /ext/iconv.
Run this command:
patch -p1 < /path/to/patch_file
When it asks you what file to patch, type ‘iconv.c’.
Rename the PECL extension directories by dropping the version details. So ‘APC-3.1.3p1’ becomes ‘APC’ for instance.
Move all of these directories into the ‘/ext’ directory of the PHP source code.
Delete the existing ./configure file:
rm ./configure
Now rebuild it (ignore the warnings):
./buildconf –force
Now run this configuration script:
./configure
–prefix=/usr/local/php5
–with-apxs2
–enable-imagick
–enable-apc
–enable-soap
–enable-memcache
–with-zlib
–with-openssl=/usr
–enable-mbstring
–enable-mbregex
–with-curl
–enable-memcached
–enable-ssh2
–with-pear
–with-mssql=/usr/local
–with-mysql=/usr/local/mysql
–with-mysql-sock=/tmp
–with-pgsql=/usr/local/pgsql
–with-pdo-pgsql=/usr/local/pgsql/
–with-pdo-mysql=/usr/local/mysql
–with-gdmake
make install
Copy /etc/php.ini.default to /etc/php.ini
NOTE: if it makes a mention about changing your include_path, then you should do it. PHP Unit requires it.
Edit /etc/php.ini, and find this line:
include_path = “.:/usr/lib/php”
And change it to (your prefix value in the configuration string):
include_path = “.:/usr/local/php5/lib/php”
Step 12: PHPUnit
PHPUnit is a handy unit testing tool that we’ll be installing.
Download: PHPUnit 3.4
Installation: Follow the instructions at the website. You’ll need to have installed PEAR in the PHP configuration for this to work.
Step 13: XCache
XCache is good for speeding up slow websites, it can make development work much more tolerable!
Download: Xcache 1.3
Installation:
Move the xcache files into a directory you’d like to install them in (I couldn’t figure out the flags to make it install to a particular destination). So I put them in /usr/local/xcache.
Run the phpize & ./configure commands as detailed in the installation documentation.
Xcache has probably been installed in /usr/lib/php/extensions/no-debug-non-zts-20090626/xcache.so .
Fire up /etc/php.ini and do a search for xcache. There is a reference to the xcache.so where the precise details are incomplete. Change the path to the correct location of xcache.so.
You can also change the size of the cache by changing the value of xcache.size.
You can also change the value of xcache.count to the actual number of processors on your machine.
Move the admin folder into your ~/Sites folder and make a site for it. You can then see what xCache is doing.
Starting things
To start MySQL:
/usr/local/mysql/support-files/mysql.server start
To start Apache
apachectl start
Apache should already be running, so you can also use ‘stop’ and ‘graceful’ to restart it.
To start Postgres
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l ~/logfile start
This will put a logfile in the postgres user directory