By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,192 Members | 1,874 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,192 IT Pros & Developers. It's quick & easy.

Configuring Apache, PHP, and MySQL for Mac OS X

P: 316
hi all,

i have been having problems with mamp and i have decided that it probably isn't worth the trouble. problem being that i was relying on that to run a small stupid php mysql program on a mac server. so i think i just want to install apache, mysql, and php seperate i was getting ready to start on this adventure then i realized i didn't know where to start. so i know i need to install the three services but i have no idea how to config stuff to make them communicate, i have always used rackspace managed hosting and without their support team i am totaly lost. so if anyone has any ideas or knows how i can do this i would be greatful

Sep 22 '07 #1
Share this Question
Share on Google+
3 Replies

Expert 5K+
P: 5,821
Heya, Eric.

Configuring Apache, PHP and MySQL from source is not too difficult, and after awhile, it can be fun!


Maybe just for me.

Anyway, here we go.

The first thing you'll want to do is download the most recent versions of the source for Apache, MySQL and PHP.


Note that MySQL has two downloadable versions: there's a fully-compiled version for Mac OS X, or you can download the source code. I prefer the source because then I can configure it to only support Unicode, but it's up to you.

Setting Up

Unzip / untar each archive (Mac OS X's BOMArchiveHelper will do this for you when you double-click on the downloaded file).

In the Finder select Go->Go to Folder... and type /usr/local. Click Go.

Create a new folder and name it 'src'. We're going to store all our source files in this directory.

Copy each source folder into /usr/local/src.

Launch and cd /usr/local/src.

Compiling Apache

In the Terminal, cd into your httpd source folder (the tab key is your friend).

Now, you can get wildly complicated with this (to see just how complicated, issue ./configure --help), but we're going to stick to the basics for now.

We're going to configure Apache with support for Mass Virtual Hosting (mod_vhost_alias) and URL Rewriting (mod_rewrite).

Issue the following commands:
Expand|Select|Wrap|Line Numbers
  1. > ./configure --cache-file=config.cache --enable-shared --disable-static --enable-vhost-alias --enable-rewrite
  2. > make
  3. > make check
  4. > sudo make install
make check will take awhile. Go grab yourself something to drink.

Of course, you will want to make sure that your build doesn't fail any tests before issuing a make install.

Note also that we did not configure Apache with SSL support. To get this working, you will need to install OpenSSL. If you need this, post back, and we'll get you set up.

Compiling MySQL

PHP requires that MySQL be installed first, so the next app to compile is MySQL.

cd into your MySQL source directory.

If you downloaded a pre-compiled version of MySQL, you're all set to go. All you need to do is copy the contents of the distro to /usr/local:
Expand|Select|Wrap|Line Numbers
  1. >cp -r /usr/local/src/mysql-{version info} /usr/local
  2. >ln -s /usr/local/mysql-{version info} /usr/local/mysql
Replace {version info} with your MySQL version info. For example, if you downloaded version 5.0.45 for PowerPC, your folder might be named mysql-5.0.45-osx10.3-powerpc.

And you're done.

If you've opted to compile the source code instead, you'll need to issue these commands:
Expand|Select|Wrap|Line Numbers
  1. > ./configure --config-file=./config.cache --enable-shared --disable-static --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_unicode_ci --with-extra-charsets=none
Remove that '--with-extra-charsets=none' if you want to be able to use character sets other than utf8.

MySQL also has additional configuration options (./configure --help).

Next, do the standard
Expand|Select|Wrap|Line Numbers
  1. > make
  2. > make check
  3. > sudo make install
MySQL's make check takes even longer than Apache's. Go grab something to eat.

Compiling PHP

cd into your PHP source directory.

PHP's a lot of fun to configure (./configure --help). We'll stick to the bare bones here:
Expand|Select|Wrap|Line Numbers
  1. > ./configure  --cache-file=config.cache --enable-shared --disable-static --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-gd --with-curl
  2. > make
  3. > make test
  4. > sudo make install
  5. > sudo pear upgrade-all
There are many many MANY more configuration options, and you may need some of them, but fortunately, it is possible (and in fact quite easy) to compile PHP without affecting your Apache nor MySQL installations, so you are always free to experiment, and you can post back anytime you get stuck :)

Note that PHP has make test instead of make check. PHP takes the least time to test of the 'big three'. Go do something that doesn't take long.

PHP will probably fail several tests. That's OK. A lot of functionality in the PHP language is experimental or not widely supported. As an example, my PHP build failed almost 200 tests (out of close to 3000, which works out to approximately 95% passed), but not a single one of them was for functionality that I will ever use.

And you can always recompile and install without affecting any of your other apps.

To start up Apache, issue:
Expand|Select|Wrap|Line Numbers
  1. > sudo /usr/local/apache2/bin/apachectl start
And MySQL:
Expand|Select|Wrap|Line Numbers
  1. > sudo /usr/local/mysql/support-files/mysql.server start
The location of the mysql.server file varies from build to build; it might be in /usr/local/mysql/bin instead.

Tune in next week to find out how to set up Mac OS X to automatically start httpd and mysqld at startup!

PS. Remind me to post this as an article.
Sep 23 '07 #2

Expert 5K+
P: 5,821
You might get errors if you try to compile MySQL with --cache-file=config.cache.

This line will work:
Expand|Select|Wrap|Line Numbers
  1. ./configure --enable-shared --disable-static --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_unicode_ci --with-extra-charsets=none
Sep 23 '07 #3

P: 316
you are officially my hero

Sep 24 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.