Quite a lot of people are asking me how to get a development setup running for MacOS X. With this post I hope to help all those that asked and others as well.
Let’s us start off to get all the needed files first:
- ColdFusion Installer (Get Version 7.x from Adobe’s website or then Version 8.0 from Adobe Labs)
- Get Apache 2.2.4 from apache.org (MacOS X internal webserver is Apache 1.3.3) and download the Unix Source.
Let’s get Apache compiled and configured. Don’t worry this won’t be very hard to do.
Compile and configure Apache 2.2.4
Once you have downloaded the tar file from apache.org switch to the download directory. Since we have to issue all the commands within the terminal you might as well do this in the terminal as well. Start up terminal and enter:
cd /mydirectorytothedownload
then uncompress the file with:
tar -xcvf httpd-2.2.4.tar.gz
You will then get a directory called “httpd-2.2.4″ in the very same directory. Switch over to that directory and edit the file “config.layout” (do this either in your favorite Text-Editor or then with “vi”). Now within the config.layout file there are different configuration settings for the installer. Just scroll all the way to the bottom and add the following lines:
<Layout Custom>
prefix: /Library/Apache2
exec_prefix: ${prefix}
bindir: ${exec_prefix}/bin
sbindir: ${exec_prefix}/bin
libdir: ${exec_prefix}/lib
libexecdir: ${exec_prefix}/modules
mandir: ${prefix}/man
sysconfdir: ${prefix}/conf
datadir: ${prefix}
installbuilddir: ${datadir}/build
errordir: ${datadir}/error
iconsdir: ${datadir}/icons
htdocsdir: ${datadir}/htdocs
manualdir: ${datadir}/manual
cgidir: ${datadir}/cgi-bin
includedir: ${prefix}/include
localstatedir: ${prefix}
runtimedir: ${localstatedir}/logs
logfiledir: ${localstatedir}/logs
proxycachedir: ${localstatedir}/proxy
</Layout>
Now we need to configure apache with our desired parameters. Still in the terminal copy and paste the below code into your terminal and hit enter:
CFLAGS=”-arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk” \
./configure –enable-layout=Custom \
–enable-mods-shared=all \
–with-ssl=/usr \
–with-mpm=prefork \
–enable-ssl \
–enable-dav \
–enable-cache \
–enable-proxy \
–enable-shared \
–disable-static \
–disable-unique-id \
–disable-ipv6 \
–enable-logio \
–enable-deflate \
–with-ldap \
–with-ldap-include=/usr/include \
–with-ldap-lib=/usr/lib \
–with-included-apr \
–enable-ldap \
–enable-auth-ldap \
–enable-cgi \
–enable-cgid \
–enable-suexec
Note: This configuration is for Intel Macs! I don’t know the correct command for any PPC Mac, but I am guessing you will need to change the “CFLAGS=”-arch i386…” to “CFLAGS=”-arch PPC….” (this is UNTESTED!).
Once done, save the file and now we are ready to compile the distribution. Note: For the following to work you should have the Apple Developer Tools installed!
Still in terminal and still in the same directory issue the command and hit enter:
make
A lot of code now runs within your terminal. Don’t worry, it is just compiling the distribution. Once finished issue the following command and hit enter again:
make install
This will install Apache in the given directory (/Library/Apache2). Now let us check if Apache actually runs as we intend it to do. Switch over to the Apache2 directory (/Library/Apache2) and go into the “bin” directory. Once there enter:
./httpd -k start (or just ./apachectl start)
If all goes well you should just have jumped to the next line in the terminal! Now call up your browser and enter either “localhost” or “127.0.0.1″ and you should see something like “It works!”! If not check out the tip below to change the user and group that Apache runs as.
Congratulation, you just compiled and installed Apache 2.2.4 successfully! There are some other things to configure but we will do this later on. Now, let’s just quickly install ColdFusion, then what would be Apache without the best Development platform on this planet
Install ColdFusion 7.x or 8
Quite simple and straightforward. Just open up the installer and walk trough the installer screens. When you come to the screen with the WebServer Connector chose your local Apache installation. Enter the path to the configuration file (httpd.conf), bin (httpd) and executables (apachectl) of Apache (Remember they are all in /Library/Apache2/conf (httpd.conf) and /Library/Apache2/bin). Enter the paths and hit OK.
Finish the installation and voila we are done. That was easy!
Fine tune Apache and/or ColdFusion
Change the default webserver document path (the path you serve your webpages from)
Obviously most of us don’t serve our webpages out of the default directory (especially not the /Library/Apache2/htdocs directory) we are in need to change this. For this we need to change the “httpd.conf” file. Fire up BBEdit, your favorite text-editor or use the terminal. Find the line that says:
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot “/Library/WebServer/Documents”
Change this path to suite your path (be careful NOT to add a “/” at the end! Doing so, will not start up Apache anymore. But hold on, there is one more line to change. Further down in the document find the line that reads:
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory “/Library/WebServer/Documents”>
And change this path to your “DocumentRoot” path as well. Once done, save the document and restart Apache with “/Library/Apache2/bin/apachectl restart”.
Change the user and group that Apache runs as
You might still not get a successful webpage result when you call it with your browser and this might as well be, because your Apache runs as another user and group not known to MacOS X. Since Apache is mainly used on Linux system it comes configured for these types of OS. Also, you might want to change the user and group so that you don’t have to change your personal setting of your own user when developing. Again, this setting is right within the “httpd.conf” file. Open it up and find the line that reads:
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon
Change this to your logged in user (for development) and group “admin” or to “www” and the group “wheel” (production). Once done save the document and restart Apache with “/Library/Apache2/bin/apachectl restart”.
Configure virtual hosts
Configuring virtual hosts with Apache is a broad topic (you can read it up over at Apache), thus here I am just showing an example how to configure your local environment with host names.
To let your system know that you host domain names (that is without a DNS) you can add host names to your “hosts” file. Open up the file “/etc/hosts” in your editor (you have to be root, thus just use the terminal and “vi”) and add the hosts you will need, like:
127.0.0.1 dev.local
127.0.0.1 testdomain.local
Save the file. On to Apache. Apache allows you to add as many virtual hosts as you wish. But with the default installation they have disabled that, thus we need to edit the “httpd.conf” file and enable it. Scroll all the way down until you find this line:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Yours will have a “#” in front of the line “include….” remove the “#” and save the file. Now, we need to add the virtual hosts, therefore we need to edit the file “/Library/Apache2/conf/extra/httpd-vhosts.conf”. Open it up and edit it your needs. With the example of the host name (in the /etc/hosts) file mine looks like this:
#
# Use name-based virtual hosting.
#
NameVirtualHost 192.168.1.152:80#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost 192.168.1.152:80>
ServerName 192.168.1.152
DocumentRoot /Users/nitai/Documents/workspace
HostnameLookups Off
#ServerAlias www.dummy-host.example.com
#ErrorLog logs/dummy-host.example.com-error_log
#CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
Once done, save it and restart Apache with “/Library/Apache2/bin/apachectl restart”. Now the settings should have fully applied and you should see your pages. If not, then try to empty any browser cache!
That was a long post but I hope some of you will benefit from it. Happy coding!