I'm a 37'ish year old web application developer from South Portland, Maine. I love meeting fellow techies, drop me a line if you want to talk shop.
Posted on 08/02/2006 at 04:50 AM
I’ve been developing web applications for some 10 years now. My routine is such that I almost always develop locally before uploading to a live server.
Through the years I’ve bought many new machines and had to tackle from scratch the installation/configuration of my development environment on each of them. Often, I loose my notes from each previous attempt and am forced to query the web for comprehensive how-to’s. No more!
I’m posting these notes online, if you have questions on the process please feel free to ask. If anything needs explanation or fixing I will attend to it ASAP.
PLEASE NOTE, I am still documenting the darwinports portion, though that really is the easiest bit.
OUTLINE:
My Requirements
Project Overview
Compile and Install DarwinPorts
- curl 7.15.4_0 + dependancies
- gd2 2.0.33_2 + dependancies
- ImageMagick 6.2.7-5_0 + dependancies
- expat 2.0.0_1
Compile and Install APACHE 2.2.2
- Create a StartupItem for Apache
- Protect yourself with .htaccess Authentication
- Customize your Apache 2.2.2 httpd.conf
Compile and Install MYSQL 5.0.22
- Configure/Prepare MySQL
- Create a StartupItem for MySQL
Compile and Install PHP 5.1.4
Youre done!
My Requirements
I had these expectations for how the installation should go.
My installations should not conflict with OS Xs built in software.
My machine should be callable via any of its names.
- http://localhost:80/
- http://192.168.1.xxx:80/
- http://xxx.xxx.xxx.xxx:80/
Apache should be configured to host any number of virtual sites.
Each Virtual site must be defined as being on its own port
- easier to handle than name or ip based virtual sites
- xxx.xxx.xxx.xxx:80, xxx.xxx.xxx.xxx:81, xxx.xxx.xxx.xxx:82, etc
All sites served by Apache should be secured from the public.
- via .htaccess authentication
Apache should serve itself from my ~/Sites folder.
Project Overview
This installation results in the following directory setups:
/usr/local
apache2/ - apache src folder
httpd-2.2.2/ - apache installation
httpd-2.2.2.tar.gz - original apache download
mysql-5.0.22/ - mysql src folder
mysql-5.0.22.tar.gz - original mysql download
mysql5/ - mysql installation
php-5.1.4/ - php src folder
php-5.1.4.tar.gz - original php download
php5/ - php installation
/Library/StartupItems/Apache2/
Apache2 - the
StartupParameters.plist - the property list
/opt/local - darwinports
We will Install:
Apache 2.2.2
MySQL 5.0.22
PHP 5.1.4
Darwinports 1.211
- curl 7.15.4_0
- openssl 0.9.8b_0 (dependancy)
- zlib 1.2.3_0 (dependancy)
- gd2 2.0.33_2
- freetype 2.1.10_1 (dependancy)
- jpeg 6b_1 (dependancy)
- libpng 1.2.10_2 (dependancy)
- ImageMagick 6.2.7-5_0
- bzip2 1.0.3_0 (dependancy)
- freetype 2.1.10_1 (dependancy)
- jpeg 6b_1 (dependancy)
- libpng 1.2.10_2 (dependancy)
- libxml2 2.6.23_0 (dependancy)
- tiff 3.8.2_0 (dependancy)
- zlib 1.2.3_0 (dependancy)
- expat 2.0.0_1
All Darwinport installations are placed in /opt/local. And make sure you have the newest Xcode from Apple’s Developer site before compiling.
Compile and Install DarwinPorts
Get Darwinports pkg installer.
Installed ports will NOT be accessible until you add /opt/local/bin to your path. The Pkg installer typically does this for you, or instructs you to do it yourself.
First thing you want to do after the PKG installer completes is open a new Terminal window, or close and reopen the one you are in. This loads in your new $PATH variable. Then run this command to update Darwinports.
$ sudo port -d selfupdate
Afterwards, you’ll want to run each of these commands.
$ sudo port install ImageMagick
$ sudo port install curl
$ sudo port install gd2
$ sudo port install expat
If all goes well, you’re done. If it doesn’t, post below and I will try and help you out.
One more thing, if you have a need to add darwinport installed apps to your systems path, I’ve found a quick way to do this is to add /opt/local/bin to the $PATH of your /etc/profile.
Compile and Install APACHE 2.2.2
$ cd /usr/local/
$ su
$ curl -O httpd-2.2.2.tar.gz
$ gnutar -xzf httpd-2.2.2.tar.gz
$ cd httpd-2.2.2/
$ ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-so --enable-ssl
$ make
$ make install
Create a StartupItem for Apache
First we need to create the startup item folder which will contain 2 specific files.
$ mkdir /Library/StartupItems/Apache2
$ cd /Library/StartupItems/Apache2
While in that directory, we create the first file, an executable that the system will use to start Apache.
$ pico Apache2
and then insert the following ...
#!/bin/sh
# Source common setup, including hostconfig.
#
. /etc/rc.common
StartService( )
{
# Don't start unless Apache2 is enabled in /etc/hostconfig
if [ "${APACHE2:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Starting Apache2"
/usr/local/apache2/bin/apachectl start &
fi
}
StopService( )
{
ConsoleMessage "Stopping Apache2"
/usr/local/apache2/bin/apachectl stop &
}
RestartService( )
{
# Don't restart unless Apache2 is enabled in /etc/hostconfig
if [ "${APACHE2:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Restarting Apache2"
/usr/local/apache2/bin/apachectl graceful &
else
StopService
fi
}
RunService "$1"
Save your file and then we make it executable.
$ chmod +x Apache2
Now we create the second file, which holds the startup parameters.
$ pico StartupParameters.plist
and then insert the following ...
< ?xml version="1.0" encoding="UTF-8"? >
<!DOCTYPE plist
SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>Description</key>
<string>Apache2</string>
<key>Provides</key>
<array>
<string>Apache2</string>
</array>
<key>Requires</key>
<array>
<string>Network</string>
</array>
<key>OrderPreference</key>
<string>Late</string>
</dict>
</plist>
Then we need to switch gears to inform the system that Apache should be turned on at startup. To do this we need to edit the system’s hostconfig file.
$ pico /etc/hostconfig
Just add this text near the bottom of the file.
APACHE2=-YES-
Protect yourself with .htaccess Authentication
I set this up so that any site being served from my machine has a password prompt, regardless of which port its on, as long as its being served from a subfolder of my web root.
Go to your web’s root folder, this will be ~/Sites. We’re going to create an .htaccess file.
$ pico .htaccess
and then insert the following ...
AuthName "BEWARE"
AuthType Basic
AuthUserFile (FULL PATH TO WEBROOT>)/.htpasswd
Require valid-user
Save your file, then we need to create to create the .htpasswd file that we’re referencing above. There are 2 commands you need to know for this if you want to grant more than one user a login, otherwise use the first command only.
$ htpasswd -c .htpasswd (USERNAME) // the first time, -c creates the file
$ htpasswd .htpasswd (USERNAME) // without -c each time after
Customize your Apache 2.2.2 httpd.conf
Now we tell Apache to serve to any of our machine’s names. Edit your /usr/local/apache2/conf/httpd.conf file.
ServerName *
Here I also turn on a few include neat the bottom of the file. You need to un-comment these lines by removing the # preceding them.
Include conf/extra/httpd-autoindex.conf
Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-default.conf
Now we edit /usr/local/apache2/conf/extra/httpd-vhosts.conf and change NameVirtualHost to the following.
NameVirtualHost *:80
Underneath this, you’ll find the area you need to add in your virtual sites for. Apache requires that our first entry here is for port 80. I usually don’t put any files in this folder and opt to let Apache show me directory listings instead. This lets you see what sites you have all in one quick glance.
<VirtualHost *:80>
ServerName default
DocumentRoot /Users/(USERNAME)/Sites
<Directory "/Users/(USERNAME)/Sites">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Every VHOST entry thereafter should be written in this format. Replace (WHATEVER) with your own stuff. Remember, the folder needs to physically exist or apache wont startup later.
Listen 81
<VirtualHost *:81>
ServerName (ALPHANUMERIC_FOLDERNAME)
DocumentRoot /Users/(USERNAME)/Sites/(FOLDERNAME)
</VirtualHost>
Compile and Install MYSQL 5.0.22
MySql always installs very easily for me, these commands came from apples own site: here
$ cd /usr/local/
$ gnutar -xzf mysql-5.0.22.tar.gz
$ cd mysql-5.0.22
$ ./configure --prefix=/usr/local/mysql5 --with-unix-socket-path=/usr/local/mysql5/run/mysql_socket --with-mysqld-user=mysql --with-comment --with-debug
$ make
$ make install
Configure/Prepare MySQL
Any questions on this stuff, just ask.
$ /usr/local/mysql5/bin/mysql_install_db --force
$ mkdir /usr/local/mysql5/run
$ chgrp -R mysql /usr/local/mysql5
$ chown -R mysql /usr/local/mysql5/run /usr/local/mysql5/var
$ /usr/local/mysql5/bin/mysqld_safe --user=mysql &
$ /usr/local/mysql5/bin/mysqladmin -u root password <newpassword>
Create a StartupItem for MySQL
First we need to create the startup item folder which will contain 2 specific files.
$ mkdir /Library/StartupItems/MySQL
$ cd /Library/StartupItems/MySQL
While in that directory, we create the first file, an executable that the system will use to start MySQL.
$ pico MySQL
and then insert the following ...
#!/bin/sh
# Source common setup, including hostconfig.
#
. /etc/rc.common
StartService( )
{
# Don't start unless MySQL is enabled in /etc/hostconfig
if [ "${MYSQL:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Starting MySQL"
/usr/local/mysql5/bin/mysqld_safe --user=mysql &
fi
}
StopService( )
{
ConsoleMessage "Stopping MySQL"
/usr/local/mysql5/bin/mysqladmin shutdown
}
RestartService( )
{
# Don't restart unless MySQL is enabled in /etc/hostconfig
if [ "${MYSQL:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Restarting MySQL"
StopService
StartService
else
StopService
fi
}
RunService "$1"
Save your file and then we make it executable.
$ chmod +x MySQL
Now we create the second file, which holds the startup parameters.
$ pico StartupParameters.plist
and then insert the following ...
< ?xml version="1.0" encoding="UTF-8"? >
<!DOCTYPE plist
SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>Description</key>
<string>MySQL</string>
<key>Provides</key>
<array>
<string>MySQL</string>
</array>
<key>Requires</key>
<array>
<string>Network</string>
</array>
<key>OrderPreference</key>
<string>Late</string>
</dict>
</plist>
Then we need to switch gears to inform the system that MySQL should be turned on at startup. To do this we need to edit the system’s hostconfig file.
$ pico /etc/hostconfig
Just add this text near the bottom of the file.
MYSQL=-YES-
If you need an explanation of the following just ask.
mysql> use mysql;
mysql> delete from user where Host like "%";
mysql> grant all privileges on *.* to root@"%" identified by 'mypassword' with grant option;
mysql> grant all privileges on *.* to root@localhost identified by 'mypassword' with grant option;
mysql> flush privileges;
mysql> exit;
Compile and Install PHP 5.1.4
$ cd /usr/local/
$ su
$ curl -O php-5.1.4.tar.gz
$ gnutar -xzf php-5.1.4.tar.gz
$ cd php-5.1.4
$ ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql5 --with-libxml-dir=/opt/local/include/libxml2 --with-curl=/opt/local/include/curl --with-expat-dir=/opt/local --with-freetype-dir=/opt/local --with-jpeg-dir=/opt/local --with-png-dir=/opt/local --with-tiff-dir=/opt/local --with-zlib-dir=/opt/local --with-gd --with-openssl --with-xml --with-xmlrpc --enable-wddx --enable-soap
$ make
$ make install
You’re done!
Often times I will release code for free or go that extra distance to help others online. If my skills were useful to you, please consider a small donation. Thank you very much.
@ github.com
@ twitter.com
@ calendaraboutnothing
Foundation's Edge, RJones Family, We're Not.com (only for staging), Ailee Jones (same as rjones for now)
Aaron, Barnaby, Brian, Chris, Dirk, Frank, Four, Justin, Matt, Mike, Monty, Paul, Sean, Travis
I can usually be found lounging on irc.freenode.net while I work, on the following channels: #fauna, #github, #hello-heroku, #jquery, #passenger, #ruby, #rubyonrails, #slicehost, #sproutcore, #textmate, #werenot.