Installing Apache, PHP, MySQL and MemCached on OS X

This is my note on how to to install Apache, PHP and MySQL on a an OS X box. Although some of these applications are come with the operating systems, it is always good to know how to upgrade them to the latest version.

1. Apple Developer Tools and Mac Port

Before installing Mac Port, you will need the Apple Developer Tools. You can download it from the Apple Developer’s Network.

After installing Apple Developer’s Tools, you can install Mac Port. You can get it from the here.

Update Mac Port

sudo port selfupdate

Add the Mac Port path in the profile: ”’~/.bash_profile”’:

export PATH=/opt/local/bin:$PATH

MySQL:Mac Port
Install MySQL from Mac Port:

sudo port install mysql5

MySQL:Package
Go to the [http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg MySQL’s website] to download the package.

Setup the a master password for root user:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'

Add the MySQL path in the profile: ”’~/.bash_profile”’:

export PATH=/usr/local/mysql/bin:$PATH

Apache:Mac Port

Install Apache from Mac Port:

sudo port install apache2

Open the configuration file: ”’/opt/local/etc/rc.conf”’ and add the following at the end of the file:

APACHE2=-YES-

PHP:Mac Port

Install PHP from Mac Port:

sudo port install php5 +apache2 +mysql5 +pear 

When that is done, register PHP 5 with Apache 2:

cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so

And create a php.ini file (which you can edit to configure PHP 5):

sudo cp /opt/local/etc/php.ini-dist /opt/local/etc/php.ini

httpd.conf

Edit the Apache configuration file ”’/opt/local/apache2/conf/httpd.conf”’ and add the following lines to the end of the file:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Replace this line:

DirectoryIndex index.html

by the following:

DirectoryIndex index.php index.html

php.ini

If the MySQL is installed from package rather than from Mac Port, we need to modify the mysql.default_socket value.

Open ”’/opt/local/etc/php.ini”’:

mysql.default_socket = /tmp/mysql.sock

MemCached

Install MemCached from Mac Port:

 sudo port install memcached
 sudo port install php5-memcache

We need to enable MemCached in PHP5.

First, we need to add the following in ”’/opt/local/etc/php.ini:”’:

extension_dir=/opt/local/lib/php/extensions/no-debug-non-zts-20060613
extension = memcache.so

Run the following command to start MemCached:

sudo /opt/local/bin/memcached -d -u nobody

Our sponsors:

2 Replies to “Installing Apache, PHP, MySQL and MemCached on OS X”

  1. Corrinne Radick

    Hi webmaster can I use some of the information from this post if I provide a link back to your site?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *