I’ve moved away from using MAMP, it was getting in the way when I wanted to do custom things with MySQL and Django, but if you want to use PHP it’s still fine.
If you enable the standard OSX apache (see this Sitepoint article) that works, however, it doesn’t seem to allow for more than one site at a time. Unless you’re prepared to edit the Apache config files on the command line, which I am.
NB: This applies to Leopard, 10.5.6.
Firstly I should point out my general setup has a folder for each site, a folder for config files, and a folder for log files. Each ‘site’ folder has many folders within it for collateral, but a
www folder for the web root.
I also add each site to my hosts file, so that I can address it as the domain without extension. For example, the local version of this site is at
http://alastairc/. To do the same, add this to your
/etc/hosts file for each site:
To replicate this setup, follow these instructions (backing up anything important first, obviously). I’m not an OSX or Apache expert, but this worked for me.
- In your “Sites” folder (
~/Sites/), create a folder for each site, and each should have a
wwwfolder with your pages.
- In the main Apache conf (/private/etc/apache2/httpd.conf), uncomment the line:
and at the bottom, add:
To avoid having to re-do lots of premissions, run Apache as you with this:
- Download this example.conf to the
~/Sites/conf/folder, and rename it to match your site. Open it, and replace “MyUserName” and “example” with your short username and the site’s name.
That’s it, each site should now have it’s own domain, for you at least!
A difference from Debian Linux is that you use slightly different commands to start/restart the server, for example, this is a restart:
sudo httpd -k restart
There is a good explanation of how to enable PHP in OSX, the short version is:
- Remove the comment hash from in front of
index.phpto the default
mysqli.default_socketmake them equal
- Restart apache with sudo httpd -k restart
Whilst PHP and Python (and others) are installed in OSX 10.5 by default, but not MySQL. It’s fairly straightforward, download and install from the official site.
MySQL and Python install on OSX
I did everything for installing this connector module, and realised that it was actually a lack of the developer tools in OSX that was the problem, so I will take these one at a time next time, not all of them:
- Ensure you have the Developer tools from Leopard installed! Otherwise you’ll get errors like “Missing Pyhon.h”
- Download the MySQL for Python package.
- Open the
_mysql.cfile and comment out (with double forward-slashes) the following lines:
#ifndef uint #define uint unsigned int #endif
- Put MySQL on you path by adding this to
- In the
threadsafe = False
- Fix the MySQL location with:
sudo ln -s /usr/local/mysql/lib/ /usr/local/mysql/lib/mysql
Then you can run the build and install:
# python setup.py clean
# python setup.py build
# sudo python setup.py install