Apache2 Config Notes
Problem: You receive this error message when starting or stopping apache2:
apache2: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Solution: Edit /etc/apache2/httpd.conf and add this line:
ServerName localhost
Apple ships an older version of Apache with its operating system. If you want to install Apache2 on you Mac, do the following. This procedure also details the steps of installing and configuring mod_python on an Intel mac running OS X 10.4.8.
Before you do anything else, make sure you have Apple's developer tools installed.
You will be downloading, building and installing Apache and mod_python from source. I have a Projects folder in my home directory where I do all of this stuff and that is the place where I will be putting the files that we will install. Actually, for a little more organization I will create and use this folder for today's project: ~/Projects/apache
Apache2
Download a copy of the source for Apache2 from http://httpd.apache.org/download.cgi. As of the time of this writing the current version is 2.2.4. I use the .tar.gz version. Put it in your ~/Projects/apache directory, open a Terminal window, and issue these commands:
cd ~/Projects/apache tar xfz httpd-2.2.4.tar.gz cd httpd-2.2.4 ./configure --prefix=/usr/local/apache2 --enable-so --with-mpm=worker make sudo make install
Note: For the ./configure... line above, if you leave off the part that reads --enable-so --with-mpm=worker, everything will build and install, including the mod_python part below. Even loading the default page will work. But you will get errors when you try to use the mod_python stuff. The errors in Apache2 logs will read something like this:
[notice] child pid 16302 exit signal Bus error (10)
Building mod_python under OS X 10.5 (Leopard) with PPC based hardware
In the mod_python source folder:
./configure
Edit src/Makefile.
Change
LDFLAGS= -Wl,-framework,Python -u _PyMac_Error -framework Python -Wl,-F.
To
LDFLAGS= -Wl,-framework,Python -u _PyMac_Error -framework Python -Wl,-F. -arch ppc64 -arch ppc -arch i386 -arch x86_64
Change
$(APXS) $(INCLUDES) -c $(SRCS) $(LDFLAGS) $(LIBS)
To
$(APXS) $(INCLUDES) -c -Wc,"-arch ppc64" -Wc,"-arch ppc" -Wc,"-arch i386" -Wc,"-arch x86_64" $(SRCS) $(LDFLAGS) $(LIBS)
Then
make sudo make install
Now that part is cool. Before the above steps the command sudo apachectl configtest was bitching about mod_python.so.
But troubles not over. Now when I try and load a *.psp file I see this in the apache error log:
ImportError: dlopen(/Library/Python/2.5/site-packages/mod_python/_psp.so, 2): no suitable image found. Did find:\n\t/Library/Python/2.5/site-packages/mod_python/_psp.so: no matching architecture in universal wrapper
I tried this:
file `which python` /usr/bin/python: Mach-O universal binary with 2 architectures /usr/bin/python (for architecture ppc7400): Mach-O executable ppc /usr/bin/python (for architecture i386): Mach-O executable i386
Looks like Apple did NOT build Python with support for all 4 architectures. In particular, on this PPC machine it needs support for ppc64 for apache. Damn!
mod_python
This is optional. I'm installing it because I'm doing some development work with Django and I needed it.
These instructions assume you have Python 2.5 installed. If you have not yet done so, please download the installer from http://www.python.org/download/. Just run it, accepting the defaults.
Download a copy of the source for mod_python from http://www.apache.org/dist/httpd/modpython/. At the time of this writing the current version is 3.3.1. I downloaded http://www.apache.org/dist/httpd/modpython/mod_python-3.3.1.tgz. Put it in ~/Projects/apache. From the Terminal issue these commands:
cd ~/Projects/apache/ tar xfz mod_python-3.3.1.tgz.tar cd mod_python-3.3.1 ./configure --with-apxs=/usr/local/apache2/bin/apxs \ --with-python=/Library/Frameworks/Python.framework/Versions/Current/bin/python make sudo make install
Test your new Apache2 installation
First make sure that your built-in Apache is not running. From the Terminal issue this command: sudo apachectl stop.
Now start up Apache2.
sudo /usr/local/apache2/bin/apachectl start
Open a web browser and enter this URL:
http://localhost/
You should see this in your browser window:
It works!
To see how to configure mod_python and run an example file (that also uses SQLite3, see this page.
To have your new Apache2 server start automatically when you boot your machine, you have a couple of options. You could replace the existing apachectl file in /usr/sbin with a symbolic link to the one located in /usr/local/apache2/bin. That way you could start and stop it using System Preferences / Sharing / Services / Personal Web Sharing. But I prefer to not mess with the stuff that Apple installs. So just leave that option unchecked, which will tell your mac to not use the built-in Apache 1.3.x web server. Instead, create your own startup script as follows.
I'm not going to give all the painful details of using the Terminal. I assume you have a basic knowledge of the Terminal and know how to move around with it. You will need to use sudo or su root to do the following.
Create the directory /Library/StartupItems/Apache2
Create the file /Library/StartupItems/Apache2/Apache2 with the following contents:
#!/bin/sh
#
# /Library/StartupItems/Apache2/Apache2
#
# Automatically start up a local copy of Apache2
# on system bootup for Mac OS X.
#
if [ -z $1 ] ; then
echo "Usage: $0 [start|stop|restart] "
exit 1
fi
test -r /etc/rc.common || exit 1
. /etc/rc.common
SCRIPT="/usr/local/apache2/bin/apachectl"
StartService ()
{
if [ "${APACHE2:=-NO-}" = "-YES-" ] ; then
ConsoleMessage "Starting Apache2"
$SCRIPT start > /dev/null 2>&1
fi
}
StopService ()
{
ConsoleMessage "Stopping Apache2"
$SCRIPT stop > /dev/null 2>&1
}
RestartService ()
{
ConsoleMessage "Restarting Apache2"
$SCRIPT restart > /dev/null 2>&1
}
if test -x $SCRIPT ; then
RunService "$1"
else
ConsoleMessage "Could not find Apache2 start script!"
fi
Create the file /Library/StartupItems/Apache2/StartupParameters.plist with the following contents:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Description</key> <string>Apache2</string> <key>OrderPreference</key> <string>None</string> <key>Provides</key> <array> <string>Apache2</string> </array> <key>Uses</key> <array> <string>Network</string> <string>Resolver</string> </array> </dict> </plist>
From the Terminal:
cd /Library/StartupItems sudo chown -R root:wheel Apache2 sudo chmod 755 Apache2/Apache2 sudo chmod 644 Apache2/StartupParameters.plist
Edit the file /etc/hostconfig and add the following line:
APACHE2=-YES-
OK, from now one, don't use Apple's built-in version of Apache. To start, stop, or restart Apache 2 manually, you may do either of the following:
sudo /usr/local/apache2/bin/apachectl start|stop|restart sudo /Library/StartupItems/Apache2/Apache2 start|stop|restart
If you want to disable automatic starting of Apache2 when your system boots, just change in line in /etc/hostconfig from APACHE2=-YES- to APACHE2=-NO-.
Have fun!
