Home arrow Site Administration arrow Page 3 - Building Apache, MySQL, and PHP on Mac OS X

Making MySQL - Administration

Apple's new operating system, Mac OS X, has a UNIX at it's core. What can you do with that? Make a killer development box that includes runtime environments for PHP and MySQL! This article runs you through all the steps for building Apache, MySQL, and PHP on your Mac OS X-based box.

  1. Building Apache, MySQL, and PHP on Mac OS X
  2. Prerequisites
  3. Making MySQL
  4. Making WebDAV
  5. Making PHP
  6. Caveats
By: Lucas Marshall
Rating: starstarstarstarstar / 11
May 21, 2001

print this article


Compiling MySQL is the most difficult part of our entire process. It doesn't just involve compiling and installing, but you also have to create a StartupItem for it so it will start whenever your Mac OS X box starts. You should compile it first so you'll have all the client libraries you'll need later for PHP.

First of all, you need to create a new user named mysql. The reason for having a user for a server process like this is security. When I have you actually compile MySQL later, I'll have you make sure it always runs under the mysql user, and then you'll be able to limit, via UNIX permissions, what files the process can modify.

To create a new user correctly, you'll need to get into NetInfo, the underlying database that keeps track of a lot of things in Mac OS X. To access NetInfo, you need to use the NetInfo Manager, which can be found in the Utilities folder that is in the Applications folder. It looks like this:

NetInfo is a very important part of Mac OS X, so there is quite a bit of security around it. Once you have NetInfo Manager open, the first thing you'll need to do is unlock it so you can make changes. Just click the lock in the lower left of the NetInfo Manager window. It looks like this:

A dialog box will come up asking for the username and password for an user with Administrator access.

Fill out the fields and click OK. The NetInfo manager should now be unlocked, and you'll be able to modify the NetInfo tree. The tree is displayed in a manner similar to the Browser view in the Finder. Click on users, then click on the new directory button.

This will create a new NetInfo directory. Use the New Property and New Value options in the Directory menu to create properties. Select New Property, set the name, select New Value, fill in the value, make sure that the property names and values match those of the directory in the screenshot below.

Once your NetInfo looks like mine, go ahead and click on one of the other directories and this dialog box will appear:

Click Save, then click Update this copy in the next dialog. You're now done with NetInfo Manager, so you can quit it.

You're not done yet, however. You still need to compile MySQL! You should still have the Terminal open from earlier. Type the following into it:

% gnutar zxf mysql-3.23.38.tar.gz
This will decompress the MySQL source into a directory in the current directory. Next, type the following:

% cd mysql-3.23.38
% ./configure --enable-assembler --with-mysqld-user=mysql

The --enable-assembler flag tells the configure script that we want MySQL to be compiled using assembler code where possible - this has the advantage of speeding up our final MySQL server.

Note: Some people have reported problems compiling (the next step) when they have specified the --enable-assembler flag. If it doesn't work for you, just re-run the configure script, omitting the --enable-assembler flag.

The --with-mysqld-user=mysql flag tells the configure script that we want the compiled MySQL to run under the mysql user we made earlier.

Now you compile.

% make
The "make" command will compile all the programs that are part of the MySQL distribution.

% sudo make install
The "make install" command installs the MySQL distribution, programs and libraries. Putting "sudo" before it runs it as root, the UNIX super-user. Sudo will ask you for your password (not root's).

% sudo /usr/local/bin/mysql_install_db
This will install the very important mysql permissions database.

% sudo chown -R mysql /usr/local/var
This command will change the owner of the newly installed MySQL databases to the mysql user.

% sudo /usr/local/bin/safe_mysqld &
This will start MySQL. Now that MySQL is all installed, you may want to make a Mac OS X Startup Item for it so it will start every time the computer starts. Here's how you do it.

If there isn't a StartupItems folder in your Library folder, execute this command:

% mkdir /Library/StartupItems
It will make one. The reason we put it in Library and not System/Library is that everything in System/Library is reserved for use by the operating system only.

% mkdir /Library/StartupItems/MySQL
This will make a new directory for our MySQL startup item. Next you'll need to make a startup script.

Type this:

% pico /Library/StartupItems/MySQL/MySQL
and then paste the following into the window.

#!/bin/sh. /etc/rc.common### Start up MySQL server##if [ "${MYSQLSERVER:=-NO-}" = "-YES-" ]; then ConsoleMessage "Starting MySQL Server" /usr/local/share/mysql/mysql.server startfi
Teaching you how to use pico or vi, or any other UNIX text editor is beyond the scope of this article. I'm having you use pico because it is easiest.

To save in pico type ctrl-O, then select the appropriate options that come up at the bottom of the Terminal. To exit pico, type ctrl-X.

Once you've saved and exited, type the following command to make the parameter list for your startup item.

% pico /Library/StartupItems/MySQL/StartupParameters.plist
and paste the following:

{ Description = "MySQL Server"; Provides = ("MySQL"); Requires = ("Resolver"); OrderPreference = "None"; Messages = { start = "Starting MySQL Server"; stop = "Stopping MySQL Server"; };}
This parameter list tells Mac OS X what the Startup Item provides and what it requires.

% chmod -R -w /Library/StartupItems/MySQL/
This command makes it so no one can edit our new Startup Item.

% chmod +x /Library/StartupItems/MySQL/MySQL
This one tells the system that the MySQL startup script is executable.

% sudo chown -R root /Library/StartupItems/MySQL
And this one changes the owner of our new Startup Item to be the superuser, root. Now that we have a startup item, we need to tell the system that we want it run at startup.

Run the following command:

% sudo pico /etc/hostconfig
And paste the following at the bottom of the file.

Whew. We're all done with MySQL now. There are some problems running MySQL that I will cover in the caveats section near the end of this article, but until then, we have some more (easier) compiling to do.{mospagebreak title=Making Apache} You may be asking "Why do I need to compile Apache when Mac OS X already comes with it?" Well, in my opinion it's always good to have a new version of such essential software. Also, it's best to ensure compatibility with the new modules you're going to be compiling, especially mod_dav.

% cd ..
This will take you out of the MySQL source directory.

% gnutar zxf apache_1.3.19.tar.gz % cd apache_1.3.19
The Apache source is decompressed and ready to go.

% ./configure --with-layout=Darwin --server-uid=www \
--server-gid=www --enable-module=most --enable-shared=max

The --with-layout=Darwin option tells the configure script that we want Apache installed with the correct layout for Mac OS X, the --server-uid=www and --server-gid=www tells configure to make it so the compiled Apache runs as user www in group www (this user and group are already in the system, Apple uses them for the built in Apache), --enable-module=most tells the configure script to enable the standard Apache modules, and --enable-shared=max tells the script to include mod_so (needed for dynamic modules, or DSOs) and compile all the standard modules as dynamic modules.

% make % sudo make install
These commands compile and install Apache. You won't be needing to make a Startup Item for it because there was already one installed in the default Apache Apple included in Mac OS X.

That's it for Apache. Wasn't that easy?

>>> More Site Administration Articles          >>> More By Lucas Marshall

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Coding: Not Just for Developers
- To Support or Not Support IE?
- Administration: Networking OSX and Win 7
- DotNetNuke Gets Social
- Integrating MailChimp with Joomla: Creating ...
- Integrating MailChimp with Joomla: List Mana...
- Integrating MailChimp with Joomla: Building ...
- Integrating MailChimp with Joomla
- More Top WordPress Plugins for Social Media
- Optimizing Security: SSH Public Key Authenti...
- Patches and Rejects in Software Configuratio...
- Configuring a CVS Server
- Managing Code and Teams for Cross-Platform S...
- Software Configuration Management
- Back Up a Joomla Site with Akeeba Backup

Developer Shed Affiliates


Dev Shed Tutorial Topics: