Server Admin

Apache

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.

Folders

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.

Hosts file

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:

127.0.0.1     yoursitename

Apache configurations

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.

  1. In your “Sites” folder (~/Sites/), create a folder for each site, and each should have a www folder with your pages.
  2. Create conf and logs folders within ~/Sites.
  3. In the main Apache conf (/private/etc/apache2/httpd.conf), uncomment the line:
    Include /private/etc/apache2/extra/httpd-vhosts.conf

    and at the bottom, add:

    Include /Users/yourusername/Sites/conf/

    To avoid having to re-do lots of premissions, run Apache as you with this:

    User MyUserName
  4. 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

PHP

There is a good explanation of how to enable PHP in OSX, the short version is:

  • Edit /etc/apache2/httpd.conf
  • Remove the comment hash from in front of LoadModule php5_module
  • Add index.php to the default DirectoryIndex
  • Copy /etc/php.ini.default to /etc/php.ini
  • Edit /etc/php.ini
  • Find mysql.default_socket and mysqli.default_socket make them equal /private/tmp/mysql.sock
  • Restart apache with sudo httpd -k restart

MySQL

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.c file 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 ~/.bash_profile:

    PATH="${PATH}:/usr/local/mysql/bin"

  • In the site.cfg file make 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

FTP server

Although OSX comes with one, PureFTP seemed better for managing (adding GUI), along with some instructions on PureFTP installation.

Last modified: January 30, 2009

Contribute to this article:

NB: Posting a comment means that you agree to the comments policy.

NB: Your email will not be shown, published or used.

Allowed HTML tags: a, acronym, strong, code, em, blockquote, ul, ol, li.