Installing Apache, PHP and MySQL on OSX Leopard

These instructions may not be 100% complete as I am writing this after the fact. However someone with a basic set of Unix skills can probably fill in the gaps. This post is primarily here to remind me of the basics involved. I will revisit this next time I install everything again from scratch.

Leopard comes with a built in apache server and PHP. All that is required is for PHP to be activated. MySql however is required to be installed.

Activating Apache and Activating PHP
I generally keep all my websites in the /User/YourUserNameDirectory/Sites directory in the subdirectories

You will need to initially edit your /etc/apache2/httpd.conf file. Make sure you are logged in as root as well. My editor of choice is vi but I believe you should be able to use pico in place of vi (Just replace the word vi with pico thoughout this guide)

Begin by opening up iTerm or Terminal and type the following to become root
sudo -s -H
This will make you root to be able to edit the system files required
Now enter the config directory and open up the config file for editing

cd /etc/apache2/
vi httpd.conf

Find the line
# LoadModule php5_module libexec/apache2/
and remove the #

If you want to setup virtual hosts as well go to the end of this file and add the line
Include virtualhosts.conf

Now save the file and exit your editor.

Skip ahead to find out about the virtualhosts installation before restarting apache if you want

For activating PHP you will also want to create a php.ini file. There is a default one in the /etc directory and you can just use that
cp /etc/php.ini.defaults /etc/php.ini

Now restart apache
apachectl restart

Installing MySql
Download the latest dmg package from here.

Open up the package and run the installer. Optionally run the auto start installer as well.

Now you will need to set a password for the root user in mysql as it is blank by default and if you are planning on using phpMyAdmin it will need one.

Startup iTerm or Terminal

To be continued………

Setting up Virtual Hosts
If you have added the Include line mentioned above you will now need to create this conf file do describe your virtual hosts.

Start editing your file
vi virtualhosts.conf

and put lines in like the following

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /Users/youUserName/Sites/phpmyadmin.localhost
    ServerName phpmyadmin.localhost
    CustomLog logs/access.log common

Ensure that the directories you have provided for DocumentRoot and ErrorLog exist otherwise apache will crap when you try to restart it.

If you are developing locally on your laptop you will also need to add entries into your hosts file to tell your web browser to look on the local machine

vi /etc/hosts

Add lines in here like the following matching up the sites you want fred.localhost phpmyadmin.localhost

When you have completed adding these sites to your custom apache conf file and hosts file restart apache.
apachectl restart

Setting up PhpMyAdmin
This is probably the most convienent way to maintain a MySql database for development. There are alot of people who think PhpMyAdmin is dangerous for production environments but in this case it’s not a problem.

Download the latest version from here.

Create a ‘site’ for it
and extract the contents of the download to there.

Create and entry for it in your virtualhosts.conf and hosts file as shown above.

One thing to note as a security feature is that phpMyAdmin will not allow you to login as root when root has no password. So you will need to ensure you have either created an account or set a password for root in mysql.

If all goes well when you restart apache you should be able to access phpmyadmin.localhost through your local webbrowser.

Migrating all of the above from your old machine to a new machine
Pretty much follow the same steps as above but if you want to maintain all your old database you will need to copy them across from /usr/local/mysql/data directory. Also ensure they are owned by _mysql user.

Tags: , , , , , , , ,

Leave a Reply