<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Geek Chic &#187; PHP</title>
	<atom:link href="http://www.jeffreyclarke.net/blog/tags/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeffreyclarke.net/blog</link>
	<description>Dorky.  And also True.</description>
	<lastBuildDate>Wed, 20 Apr 2011 20:20:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>A Web Development Environment on Snow Leopard</title>
		<link>http://www.jeffreyclarke.net/blog/2011/02/a-web-developmen-environment-on-snow-leopard/</link>
		<comments>http://www.jeffreyclarke.net/blog/2011/02/a-web-developmen-environment-on-snow-leopard/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 22:17:34 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA['Puters]]></category>
		<category><![CDATA[General Nerdiness]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[MacOSX 10.6]]></category>
		<category><![CDATA[Macports]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Subversion]]></category>

		<guid isPermaLink="false">http://www.jeffreyclarke.net/blog/?p=1177</guid>
		<description><![CDATA[This is an update to an earlier post I submitted about how to set up a web dev environment on Leopard.  A few things have changed from Leopard to Snow Leopard (namely switching to 64 bit code) so it makes sense to refresh this guide. * * * * * If you&#8217;re like me and [...]]]></description>
			<content:encoded><![CDATA[<p>This is an update to an earlier post I submitted about <a href="http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/">how to set up a web dev environment on Leopard.  A few things have changed from Leopard to Snow Leopard (namely switching to 64 bit code) so it makes sense to refresh this guide.<span id="more-1177"></span></a></p>
<p><a href="http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/"> </a></p>
<p><a href="http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/">* * * * *</a></p>
<p><a href="http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/">If you&#8217;re like me and you&#8217;d tried to have your Leopard PHP-MYSQL build just work on Snow Leopard, I&#8217;m sure you met with the same rude awakening that I did.</a></p>
<p><a href="http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/">It didn&#8217;t work.</a></p>
<p><a href="http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/"> </a></p>
<p><a href="http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/"></a></p>
<p><a href="http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/"></a></p>
<p><a href="http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/">If you followed my guide for installing </a><a href="http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/">LAMP on Leopard</a>, you should start by cleaning out MacPorts and starting fresh.</p>
<p>To be certain, you should honestly clean out everything.  But before you do, be sure to list out all the ports you currently have installed.  Do that like this:</p>
<blockquote>
<pre><code>sudo port installed</code></pre>
</blockquote>
<p>And copy the list of installed ports to a text file. For reference.</p>
<p>Next let&#8217;s do some housecleaning (BE CAREFUL! DON&#8217;T UNINSTALL UNLESS YOU MEAN IT!):</p>
<blockquote>
<pre><code>sudo port clean --all vile
sudo port -f uninstall installed</code></pre>
</blockquote>
<p>Then you can go about re-installing your environment. The guide below is slightly modified to be able to work on Snow Leopard.  Enjoy!</p>
<p>* * * * *</p>
<p>I&#8217;ve found a relatively easy way to maintain a flexible, updatable  development under MacOS 10.6 which goes so far as to install my own  components, but not to have to compile them (which I&#8217;ve done several  times and can attest, is a pain).</p>
<p>This setup gives you a great web development environment under  Leopard (geared in my case towards Flash development compatible with the  WordPress platform), which does a better job of playing by the rules  than the default install of a lot of these elements.  And with MacPorts,  the whole thing is modular and very easily maintained.</p>
<p>And everything on the list is free and/or open-source.</p>
<p>* Note that you&#8217;ll need to have administrator privileges on your user account to do this.</p>
<p>** Also note that this is geared towards creating a relatively  unfettered development environment.  I don&#8217;t make any considerations  about server security or server optimization for large-scale web  applications.  This is really geared towards creating a simple, local  dev environment.</p>
<p><strong>Includes:</strong></p>
<ul>
<li>XCode Tools</li>
<li> MacPorts</li>
<li> Apache2</li>
<li> PHP 5</li>
<li> MySQL 5</li>
</ul>
<p><strong>* optional installs:</strong></p>
<ul>
<li> GIT/Subversion</li>
<li>GitX/SCPlugin</li>
<li> Sequel Pro (formerly CocoaMySQL)</li>
</ul>
<p><em>derived from a bunch of sources, including:</em></p>
<p><a href="http://seancoates.com/php-5-2-5-on-leopard" target="_blank">php-5.2.5 on Leopard</a></p>
<p><a href="http://blog.rajatpandit.com/2009/03/12/using-macport-to-setup-php5-apache2-on-leopard/" target="_blank">Using Macport to Setup PHP5 and Apache2 on Leopard/</a></p>
<p><a href="http://matthewcarriere.com/2008/04/02/installing-mysql-on-mac-os-x-leopard-using-macports/" target="_blank">Installing MYSQL on Mac OS X Leopard Using Macports</a></p>
<p><strong>Here goes:</strong></p>
<p><strong>1. Install XCode Tools:</strong></p>
<p><a href="http://developer.apple.com/technology/xcode.html" target="_blank">http://developer.apple.com/technology/xcode.html</a></p>
<p>pretty self-explanatory. Install them.  You&#8217;ll need them at the very  least for MacPorts.  But they come in handy if you ever need to compile  anything.</p>
<p><strong>2. Install MacPorts</strong></p>
<p><a href="http://www.macports.org/install.php" target="_blank">http://www.macports.org/install.php</a></p>
<p>MacPorts is a modular install system with easy update / swap /  uninstall capacity.  It&#8217;s like Fink (I say, never having used Fink) &#8212;  just an easy way to install a bunch of standard programs.</p>
<p>There are several install options, but the easiest thing to do is just use the disk image here:</p>
<p><a href="hhttp://distfiles.macports.org/MacPorts/MacPorts-1.9.2-10.6-SnowLeopard.dmg" target="_blank">http://distfiles.macports.org/MacPorts/MacPorts-1.9.2-10.6-SnowLeopard.dmg</a></p>
<p>Unless you&#8217;re an advanced user I recommend you do that.</p>
<p><strong>3. Update MacPorts</strong></p>
<blockquote>
<pre><code>sudo port -v selfupdate #makes sure ports is up to date
sudo port sync #syncs the local port index with the remote index</code></pre>
</blockquote>
<p><strong>4. Install Apache 2</strong></p>
<blockquote><p><code>sudo port install apache2 +universal<br />
sudo port load apache2 # set to autorun at boot</code></p></blockquote>
<p>The standard web server. Standard, because it&#8217;s really stable, fast and flexible.</p>
<p>more info: <a href="http://blog.rajatpandit.com/2009/03/12/using-macport-to-setup-php5-apache2-on-leopard/" target="_blank">http://blog.rajatpandit.com/2009/03/12/using-macport-to-setup-php5-apache2-on-leopard/</a></p>
<p>** notes **</p>
<p>You don&#8217;t necessarily need these, but I find it&#8217;s helpful to have some  aliases to address apache &#8212; mostly for start, stop and restart  functionality.  You can set these aliases to be whatever you want.  Or  ignore them.  I just find them helpful.</p>
<blockquote><p><code>alias apache_start="sudo /opt/local/apache2/bin/apachectl start"</code></p>
<p><code>alias apache_restart="sudo /opt/local/apache2/bin/apachectl restart"</code></p>
<p><code>alias apache_stop="sudo /opt/local/apache2/bin/apachectl stop"</code></p></blockquote>
<p><strong>5. Install MySQL 5</strong></p>
<p>(Note that you might need to <a href="#relink-sql-sock">re-link your MySQL sock</a> file before you initialize and setup if this is your first time using MySQL on your system.)</p>
<blockquote><p><code>sudo port install mysql5-server +universal</code></p>
<p><code>sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql #initialze mysql</code></p>
<p><code>sudo port load mysql5-server #set mysql to autostart at boot</code></p>
<p><code> </code><code>sudo /opt/local/bin/mysqld_safe5 #start</code></p></blockquote>
<p>#create symbolic links to not have to type in mysql5 every time:</p>
<blockquote><p><code>sudo ln -s /opt/local/bin/mysql5 /opt/local/bin/mysql</code></p>
<p><code> </code><code>sudo ln -s /opt/local/bin/mysqladmin5 /opt/local/bin/mysqladmin</code></p></blockquote>
<p>More info: <a href="http://matthewcarriere.com/2008/04/02/installing-mysql-on-mac-os-x-leopard-using-macports/" target="_blank">http://matthewcarriere.com/2008/04/02/installing-mysql-on-mac-os-x-leopard-using-macports/</a></p>
<p><strong>6. Install php5 (with apache2, mysql and pear support)</strong></p>
<blockquote><p><code>sudo port install php5 +apache2 +mysql5 +pear +universal</code></p></blockquote>
<p><strong>7. Activate PHP</strong></p>
<blockquote><p><code>sudo cp /opt/local/etc/php5/php.ini-development  /opt/local/etc/php5/php.ini</code></p>
<p><code>cd /opt/local/apache2/modules</code></p>
<p><code> </code><code>sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so</code></p></blockquote>
<p><strong>8. Move Snow Leopard&#8217;s standard Apache out of the regular path</strong></p>
<blockquote><p><code>sudo mv /usr/sbin/apachectl /usr/sbin/apachectl-leopard</code></p></blockquote>
<p><strong>9. Move your new Apache into the path</strong></p>
<p>(you might not need the first 2 steps, but I&#8217;m working on a totally clean Leopard build, so I don&#8217;t have these directories yet)</p>
<blockquote><p><code>sudo mkdir /usr/local</code></p>
<p><code>sudo mkdir /usr/local/bin</code></p>
<p><code> </code><code>sudo ln -s /opt/local/apache2/bin/apachectl /usr/local/bin/apachectl</code></p></blockquote>
<p><strong>10. Move Leopard&#8217;s bundled PHP out of the way</strong></p>
<blockquote><p><code>sudo mv /usr/bin/php /usr/bin/php-leopard</code></p></blockquote>
<p><strong>11. Do some Apache configuration for PHP:</strong></p>
<p>(all of these are modifications to the httpd.conf file located here: /opt/local/apache2/conf/httpd.conf)</p>
<p><strong>a. </strong>Add index.php to the list of DirectoryIndex:</p>
<blockquote><p><code>&lt;IfModule dir_module&gt;</code></p>
<p><code>DirectoryIndex index.html index.php</code></p>
<p><code> </code><code>&lt;/IfModule&gt;</code></p></blockquote>
<p><strong>b.</strong> Add handlers for PHP files:</p>
<blockquote><p><code># Add handling for PHP files</code></p>
<p><code>&lt;IfModule php5_module&gt;</code></p>
<p><code>AddHandler application/x-httpd-php .php</code></p>
<p><code>AddHandler application/x-httpd-php-source .phps</code></p>
<p><code> </code><code>&lt;/IfModule&gt;</code></p></blockquote>
<p>This block can go anywhere in the httpd.conf &#8212; but it&#8217;s probably best to keep the module handlers in alphabetical order.</p>
<p><strong>c. </strong>Restart Apache</p>
<p>If you added the alias to your bash profile, you can now do apache_restart. Otherwise, enter:</p>
<blockquote><p><code>sudo apachectl restart</code></p></blockquote>
<p><strong>11. Include user Sites directories (enable the following file by un-commenting it):</strong></p>
<blockquote><p><code># User home directories</code></p>
<p><code> </code><code>Include conf/extra/httpd-userdir.conf</code></p></blockquote>
<p><strong>12. Re-link mysql.sock:<a name="relink-sql-sock"></a></strong></p>
<blockquote><p><code>sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock</code></p></blockquote>
<p>This step is essential so everyone can agree where MySQL is living on  the system and how to connect to it.  Before I did this, Apache and PHP  seemed to be able to access MySQL, and I could access MySQL from the  command line, but programs like SequelPro couldn&#8217;t find the MySQL  socket.  This step seems to correct that problem and let everyone play  nicely.</p>
<p><strong><em>** OPTIONAL **</em></strong></p>
<p>These steps are optional &#8212; certainly not essential, but I find them to be very helpful tools for web development.</p>
<p><strong>13. Install Git/Subversion (Version Control)</strong></p>
<p>I personally have become a huge fan of <a href="http://git-scm.com/" target="_blank">Git</a>.  I want to encourage you to become a fan too if you aren&#8217;t already.</p>
<p>You can install Git using <a href="http://code.google.com/p/git-osx-installer/" target="_blank">Mac OSX installer.</a></p>
<p>Alternatively, if you want to keep with <strong>Subversion</strong> (or, say, you need both), do this:</p>
<blockquote><p>sudo port install subversion +universal</p></blockquote>
<p>This installs the latest version of Subversion on the system &#8212; which  is then used for SVN access from the command line, from Eclipse, from  SCPlugin, etc.</p>
<p><strong>14. Install GitX/SCPlugin</strong></p>
<p>You&#8217;ll now want a way to interface with your version control system of choice.  My favorite interface for Git so far is GitX.  It&#8217;s much more for tracking revisions and simple commits than for branches and complex merges.  For those you&#8217;ll need the command line.  But for simple tracking and commits (what you do from day to day), GitX is for you.  <a href="http://gitx.frim.nl/" target="_blank">Download GitX here</a>.</p>
<p>If, instead/in addition, you&#8217;re looking for a tool to interact with Subversion, I recommend SCPlugin.</p>
<p><a href="http://scplugin.tigris.org/" target="_blank">http://scplugin.tigris.org/</a></p>
<p>SCPlugin is a great little tool that integrates Subversion access  with the MacOS Finder and lets you do all of your basic SVN commands  from there (checkout, update, revert, etc).  It doesn&#8217;t give you deep,  deep access into SVN commands like version checkout or repository  browsing, but for lazy commands like checkout and update, it&#8217;s great.</p>
<p><strong>15. Install CocoaMySQL / SequelPro</strong></p>
<p><a href="http://sequel-pro.googlecode.com/files/CocoaMySQL-pre0.7b6.zip" target="_blank">CocoaMySQL 0.7b6</a></p>
<p><a href="http://www.theonline.org/cocoamysql/CocoaMySQL-SBG-v0_7_1.dmg.zip%20%28CocoaMySQL-SBG%200.7.1%29" target="_blank">CocoaMySQL-SBG 0.7.1</a></p>
<p>Of those two I prefer <strong>0.7b6 </strong>&#8211; It seems perfectly stable to me.</p>
<p>CocoaMySQL is an awesome little MySQL editor / browser based on the  CocoaMySQL codebase.  I&#8217;ve been using it for years and I&#8217;ve found it&#8217;s a  lot faster than entering SQL commands in the Terminal or dealing with  PHPMyAdmin (which is super-slow even running locally).</p>
<p>CocoaMySQL lets you manage DBs effortlessly. I find it&#8217;s great for DB  creation (when you&#8217;re still sketching out a project and want to play  around with table structure), and for common tasks like importing and  exporting.</p>
<p>It&#8217;s a native MacOS application, so it&#8217;s really zippy and it lets you  do local and remote DB access.  And it plays nice with all of the  components we&#8217;ve installed so far.</p>
<p>I highly recommend it.</p>
<p>The only drawback is that the codebase for CocoaMySQL has been  abandoned.  It&#8217;s been picked up by the SequelPro project, but honestly  these guys have a ways to go before their product matches CocoaMySQL  (like &#8212; they still need to add user administration).  By the time you  read this maybe they&#8217;ve added some features.  If not, I&#8217;d say CocoaMYSQL  still works beautifully &#8212; even though the code has been abandoned.</p>
<p>If you want SequelPro, though, you can get it here:</p>
<p><a href="http://www.sequelpro.com/" target="_blank">http://www.sequelpro.com/</a></p>
<p><strong>16. ADVANCED &#8211; Virtual Hosts</strong></p>
<p>I first experimented with Virtual Hosts when I started doing  WordPress development &#8212; mostly because WordPress seems much happier  with shorter real world style urls like:</p>
<p><em>http://radio.local</em></p>
<p>than those you&#8217;d typically see running on your local box:</p>
<p><em>http://localhost/~jeff/projects/wordpress/radio-station</em></p>
<p>But once I started playing with these, I decided it was MUCH easier  to be able to deal with these super-short urls (think Bit.ly for your  local box) than to have to type in the whole thing.  It&#8217;s made my life a  lot simpler, so I figured I&#8217;d pass along the info.</p>
<p>Note that when you choose a host name, you&#8217;ll want to choose one that  doesn&#8217;t exist on the web.  You&#8217;re basically overriding your machine&#8217;s  host lookup functionality &#8212; hard coding urls to corresponding locations  on your local disk &#8212; and thereby bypassing DNS lookup.  So if you  pathed http://www.google.com to your local disk, your computer wouldn&#8217;t  be able to find the real google until you undid the Virtual host.  So be  careful.</p>
<p>I typically choose a hostname that includes the suffix .local.   That&#8217;s never given me any problems (eg. projects.local, flash.local,  radio.local).</p>
<p>Let&#8217;s begin.</p>
<p>You&#8217;ll be dealing with 3 files on this:</p>
<ul>
<li>httpd.conf</li>
<li>httpd-vhosts.conf</li>
<li>hosts</li>
</ul>
<p>Which, if you followed the steps above, are located at:</p>
<ul>
<li>/opt/local/apache2/conf/httpd.conf</li>
<li>/opt/local/apache2/conf/extra/httpd-vhosts.conf</li>
<li>/private/etc/hosts</li>
</ul>
<p><strong>a. Enable Apache&#8217;s Virtual Host configuration</strong></p>
<p>in httpd.conf, uncomment the Virtual Hosts line:</p>
<blockquote><p><code>Include conf/extra/httpd-vhosts.conf</code></p></blockquote>
<p>This will allow you to add hosts to your vhosts configuration file.</p>
<p><strong>b. Add host locations</strong></p>
<p>open the vhosts file in your favorite text editor:</p>
<blockquote><p><code>/opt/local/apache2/conf/extra/httpd-vhosts.conf</code></p></blockquote>
<p>The first thing you&#8217;ll want to do here is comment out the default examples they give you (the ones that include <em>ServerAdmin webmaster@dummy-host.example.com</em>).  You might want them as a reference, but you don&#8217;t want them to be active.  Comment them out.</p>
<p>Next you&#8217;ll add your host.  Substitute in values below to correspond to your build and the hostname you choose:</p>
<blockquote><p><code>&lt;VirtualHost *:80&gt;</code></p>
<p><code>DocumentRoot "/Users/USERNAME/PATH"</code></p>
<p><code>ServerName hostname.suffix</code></p>
<p><code> </code><code>&lt;/VirtualHost&gt;</code></p></blockquote>
<p>Typically life is easier if you choose a disk path inside of your  Sites directory.  If you don&#8217;t you might need to do some more file  permission configuration.</p>
<p>In my case, the host I added is:</p>
<blockquote><p><code>&lt;VirtualHost *:80&gt;</code></p>
<p><code>DocumentRoot "/Users/jeff/Sites/projects"</code></p>
<p><code>ServerName projects.local</code></p>
<p><code> </code><code>&lt;/VirtualHost&gt;</code></p></blockquote>
<p>So now Apache knows that when it&#8217;s told to serve any files referenced  by the url projects.local, it&#8217;ll serve them from the path I&#8217;ve given it  in my Sites directory.  There are other arguments you can add to the  VirtualHost node, but this is all you need.</p>
<p><strong>c. Add host names to your hosts file</strong></p>
<p>Next you need to tell the machine that when you ask for that  particular server name, you want it to ask the local Apache server to  serve it.  Editing this file is globally applicable to all browser  applications &#8212; so once you edit this file, programs like Firefox,  Safari, Opera, etc will all serve up your local page instead of looking  the url up with the friendly neighborhood DNS.</p>
<p>Your machine already does this to a certain extent &#8212; for example,  the &#8216;localhost&#8217; prefix is already set up via the hosts file so that the  machine knows to look to the local Apache server, rather than out on the  web.  What we&#8217;re doing is adding one or many shortcuts that mimic this  behavior &#8212; but which point to more specific locations on disk.</p>
<p>Open your hosts file:</p>
<blockquote><p><code>/private/etc/hosts</code></p></blockquote>
<p>and add the line:</p>
<blockquote><p><code>127.0.0.1     hostname.suffix</code></p></blockquote>
<p>(so in my case I added):</p>
<blockquote><p><code>127.0.0.1     projects.local</code></p></blockquote>
<p>then save the file.</p>
<p><strong>d. Restart Apache</strong></p>
<p>Go back to the terminal and restart apache:</p>
<blockquote><p><code>sudo apachectl restart</code></p></blockquote>
<p>Now you should be all set.  Open up your browser and point it towards the virtual host you just made. In our case that&#8217;s:</p>
<p><em>http://projects.local</em></p>
<p>And your browser should serve up that url like magic. ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeffreyclarke.net/blog/2011/02/a-web-developmen-environment-on-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>A Web Development Server Environment on Leopard</title>
		<link>http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/</link>
		<comments>http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 14:29:49 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA['Puters]]></category>
		<category><![CDATA[General Nerdiness]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Leopard]]></category>
		<category><![CDATA[Mac OS 10.5]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jeffreyclarke.net/blog/?p=977</guid>
		<description><![CDATA[UPDATE: I&#8217;ve now written a modified guide for Snow Leopard! I apologize &#8212; this is a little nerdier than this blog typically gets, but I wanted to put this up online somewhere and didn&#8217;t have anywhere else to put it. I&#8217;ve been frustrated with the web server that comes with Mac OS 10.5 (Leopard) and [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE:</strong> I&#8217;ve now written a modified guide for <a href="http://www.jeffreyclarke.net/blog/2011/02/a-web-developmen-environment-on-snow-leopard/">Snow Leopard</a>!</p>
<p>I apologize &#8212; this is a little nerdier than this blog typically gets, but I wanted to put this up online somewhere and didn&#8217;t have anywhere else to put it.</p>
<p>I&#8217;ve been frustrated with the web server that comes with Mac OS 10.5 (Leopard) and I&#8217;ve worked to set up my own server for web development projects.  I&#8217;d tried this a number of ways, but this time I was really happy with the process and the end result &#8212; so I typed up a little document on how to set up a nice web dev environment (partly so I can repeat it, but partly to share).  Enjoy!</p>
<p><span id="more-977"></span></p>
<p style="text-align: center;">* * * * *</p>
<p><!--   body #page #content{ text-align:left;margin:5px auto; padding:10px 0 0; width:100%;}    --></p>
<p>I&#8217;ve found a relatively easy way to maintain a flexible, updatable development under MacOS 10.5 which goes so far as to install my own components, but not to have to compile them (which I&#8217;ve done several times and can attest, is a pain).</p>
<p>This setup gives you a great web development environment under Leopard (geared in my case towards Flash development compatible with the WordPress platform), which does a better job of playing by the rules than the default install of a lot of these elements.  And with MacPorts, the whole thing is modular and very easily maintained.</p>
<p>And everything on the list is free and/or open-source.</p>
<p>* Note that you&#8217;ll need to have administrator privileges on your user account to do this.</p>
<p>** Also note that this is geared towards creating a relatively unfettered development environment.  I don&#8217;t make any considerations about server security or server optimization for large-scale web applications.  This is really geared towards creating a simple, local dev environment.</p>
<p><strong>Includes:</strong></p>
<ul>
<li>XCode Tools</li>
<li> MacPorts</li>
<li> Apache2</li>
<li> PHP 5</li>
<li> MySQL 5</li>
</ul>
<p><strong>* optional installs:</strong></p>
<ul>
<li> Subversion</li>
<li> SCPlugin</li>
<li> Sequel Pro (formerly CocoaMySQL)</li>
</ul>
<p><em>derived from a bunch of sources, including:</em><br />
<a href="http://seancoates.com/php-5-2-5-on-leopard" target="_blank">php-5.2.5 on Leopard</a><br />
<a href="http://blog.rajatpandit.com/2009/03/12/using-macport-to-setup-php5-apache2-on-leopard/" target="_blank">Using Macport to Setup PHP5 and Apache2 on Leopard/</a><br />
<a href="http://matthewcarriere.com/2008/04/02/installing-mysql-on-mac-os-x-leopard-using-macports/" target="_blank">Installing MYSQL on Mac OS X Leopard Using Macports</a></p>
<p><strong style="display: block; margin-top: 30px; margin-bottom: 25px; font-size: 1.3em;">Here goes:</strong></p>
<p><strong>1. Install XCode Tools:</strong><br />
<a href="http://developer.apple.com/technology/xcode.html" target="_blank">http://developer.apple.com/technology/xcode.html</a></p>
<p>pretty self-explanatory. Install them.  You&#8217;ll need them at the very least for MacPorts.  But they come in handy if you ever need to compile anything.</p>
<p><strong>2. Install MacPorts</strong><br />
<a href="http://www.macports.org/install.php" target="_blank">http://www.macports.org/install.php</a></p>
<p>MacPorts is a modular install system with easy update / swap / uninstall capacity.  It&#8217;s like Fink (I say, never having used Fink) &#8212; just an easy way to install a bunch of standard programs.</p>
<p>There are several install options, but the easiest thing to do is just use the disk image here:</p>
<p><a href="http://svn.macports.org/repository/macports/downloads/MacPorts-1.7.1/MacPorts-1.7.1-10.5-Leopard.dmg" target="_blank">http://svn.macports.org/repository/macports/downloads/MacPorts-1.7.1/MacPorts-1.7.1-10.5-Leopard.dmg</a></p>
<p>Unless you&#8217;re an advanced user I recommend you do that.</p>
<p><strong>3. Update MacPorts</strong></p>
<blockquote><p>sudo port -v selfupdate #makes sure ports is up to date<br />
sudo port sync #syncs the local port index with the remote index</p></blockquote>
<p><strong>4. Install Apache 2</strong></p>
<blockquote><p>sudo port install apache2<br />
sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist # set to autorun at boot</p></blockquote>
<p>The standard web server. Standard, because it&#8217;s really stable, fast and flexible.</p>
<p>more info: <a href="http://blog.rajatpandit.com/2009/03/12/using-macport-to-setup-php5-apache2-on-leopard/" target="_blank">http://blog.rajatpandit.com/2009/03/12/using-macport-to-setup-php5-apache2-on-leopard/</a></p>
<p>** notes **<br />
You don&#8217;t necessarily need these, but I find it&#8217;s helpful to have some aliases to address apache &#8212; mostly for start, stop and restart functionality.  You can set these aliases to be whatever you want.  Or ignore them.  I just find them helpful.</p>
<blockquote><p>alias apache_start=&#8221;sudo /opt/local/apache2/bin/apachectl start&#8221;<br />
alias apache_restart=&#8221;sudo /opt/local/apache2/bin/apachectl restart&#8221;<br />
alias apache_stop=&#8221;sudo /opt/local/apache2/bin/apachectl stop&#8221;</p></blockquote>
<p><strong>5. Install MySQL 5</strong></p>
<blockquote><p>sudo port install mysql5 +server<br />
sudo /opt/local/lib/mysql5/bin/mysql_install_db &#8211;user=mysql #initialze mysql<br />
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist #set mysql to autostart at boot<br />
sudo /opt/local/bin/mysqld_safe5 #start</p></blockquote>
<p>#create symbolic links to not have to type in mysql5 every time:</p>
<blockquote><p>sudo ln -s /opt/local/bin/mysql5 /opt/local/bin/mysql<br />
sudo ln -s /opt/local/bin/mysqladmin5 /opt/local/bin/mysqladmin</p></blockquote>
<p>More info: <a href="http://matthewcarriere.com/2008/04/02/installing-mysql-on-mac-os-x-leopard-using-macports/" target="_blank">http://matthewcarriere.com/2008/04/02/installing-mysql-on-mac-os-x-leopard-using-macports/</a></p>
<p><strong>6. Install php5 (with apache2, mysql and pear support)</strong></p>
<blockquote><p>sudo port install php5 +apache2 +mysql5 +pear</p></blockquote>
<p><strong>7. Activate PHP</strong></p>
<blockquote><p>cd /opt/local/apache2/modules<br />
sudo /opt/local/apache2/bin/apxs -a -e -n &#8220;php5&#8243; libphp5.so</p></blockquote>
<p><strong>8. Move Leopard&#8217;s standard Apache out of the regular path</strong></p>
<blockquote><p>sudo mv /usr/sbin/apachectl /usr/sbin/apachectl-leopard</p></blockquote>
<p><strong>9. Move your new Apache into the path</strong><br />
(you might not need the first 2 steps, but I&#8217;m working on a totally clean Leopard build, so I don&#8217;t have these directories yet)</p>
<blockquote><p>sudo mkdir /usr/local<br />
sudo mkdir /usr/local/bin<br />
sudo ln -s /opt/local/apache2/bin/apachectl /usr/local/bin/apachectl</p></blockquote>
<p><strong>10. Move Leopard&#8217;s bundled PHP out of the way</strong></p>
<blockquote><p>sudo mv /usr/bin/php /usr/bin/php-leopard</p></blockquote>
<p><strong>11. Do some Apache configuration for PHP:</strong><br />
(all of these are modifications to the httpd.conf file located here: /opt/local/apache2/conf/httpd.conf)</p>
<p><strong>a. </strong>Add index.php to the list of DirectoryIndex:</p>
<blockquote><p>&lt;IfModule dir_module&gt;<br />
DirectoryIndex index.html index.php<br />
&lt;/IfModule&gt;</p></blockquote>
<p><strong>b.</strong> Add handlers for PHP files:</p>
<blockquote><p># Add handling for PHP files<br />
&lt;IfModule php5_module&gt;<br />
AddHandler application/x-httpd-php .php<br />
AddHandler application/x-httpd-php-source .phps<br />
&lt;/IfModule&gt;</p></blockquote>
<p>This block can go anywhere in the httpd.conf &#8212; but it&#8217;s probably best to keep the module handlers in alphabetical order.</p>
<p><strong>c. </strong>Restart Apache<br />
If you added the alias to your bash profile, you can now do apache_restart. Otherwise, enter:</p>
<blockquote><p>sudo apachectl restart</p></blockquote>
<p><strong>11. Include user Sites directories (enable the following file by un-commenting it):</strong></p>
<blockquote><p># User home directories<br />
Include conf/extra/httpd-userdir.conf</p></blockquote>
<p><strong>12. Re-link mysql.sock:</strong></p>
<blockquote><p>sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock</p></blockquote>
<p>This step is essential so everyone can agree where MySQL is living on the system and how to connect to it.  Before I did this, Apache and PHP seemed to be able to access MySQL, and I could access MySQL from the command line, but programs like SequelPro couldn&#8217;t find the MySQL socket.  This step seems to correct that problem and let everyone play nicely.</p>
<p><strong style="display: block; margin-top: 30px; margin-bottom: 0px; font-size: 1.3em;"><em>** OPTIONAL **</em></strong><br />
These steps are optional &#8212; certainly not essential, but I find them to be very helpful tools for web development.</p>
<p><strong>13. Install Subversion</strong></p>
<blockquote><p>sudo port install subversion</p></blockquote>
<p>This installs the latest version of Subversion on the system &#8212; which is then used for SVN access from the command line, from Eclipse, from SCPlugin, etc.</p>
<p><strong>14. Install SCPlugin</strong></p>
<p><a href="http://scplugin.tigris.org/" target="_blank">http://scplugin.tigris.org/</a></p>
<p>SCPlugin is a great little tool that integrates Subversion access with the MacOS Finder and lets you do all of your basic SVN commands from there (checkout, update, revert, etc).  It doesn&#8217;t give you deep, deep access into SVN commands like version checkout or repository browsing, but for lazy commands like checkout and update, it&#8217;s great.</p>
<p><strong>15. Install CocoaMySQL / SequelPro</strong></p>
<p><a href="http://sequel-pro.googlecode.com/files/CocoaMySQL-pre0.7b6.zip" target="_blank">CocoaMySQL 0.7b6</a><br />
<a href="http://www.theonline.org/cocoamysql/CocoaMySQL-SBG-v0_7_1.dmg.zip (CocoaMySQL-SBG 0.7.1)" target="_blank">CocoaMySQL-SBG 0.7.1</a></p>
<p>Of those two I prefer <strong>0.7b6 </strong>&#8211; It seems perfectly stable to me.</p>
<p>CocoaMySQL is an awesome little MySQL editor / browser based on the CocoaMySQL codebase.  I&#8217;ve been using it for years and I&#8217;ve found it&#8217;s a lot faster than entering SQL commands in the Terminal or dealing with PHPMyAdmin (which is super-slow even running locally).</p>
<p>CocoaMySQL lets you manage DBs effortlessly. I find it&#8217;s great for DB creation (when you&#8217;re still sketching out a project and want to play around with table structure), and for common tasks like importing and exporting.</p>
<p>It&#8217;s a native MacOS application, so it&#8217;s really zippy and it lets you do local and remote DB access.  And it plays nice with all of the components we&#8217;ve installed so far.</p>
<p>I highly recommend it.</p>
<p>The only drawback is that the codebase for CocoaMySQL has been abandoned.  It&#8217;s been picked up by the SequelPro project, but honestly these guys have a ways to go before their product matches CocoaMySQL (like &#8212; they still need to add user administration).  By the time you read this maybe they&#8217;ve added some features.  If not, I&#8217;d say CocoaMYSQL still works beautifully &#8212; even though the code has been abandoned.</p>
<p>If you want SequelPro, though, you can get it here:</p>
<p><a href="http://www.sequelpro.com/" target="_blank">http://www.sequelpro.com/</a></p>
<p><strong>16. ADVANCED &#8211; Virtual Hosts</strong></p>
<p>I first experimented with Virtual Hosts when I started doing WordPress development &#8212; mostly because WordPress seems much happier with shorter real world style urls like:</p>
<p><em>http://radio.local</em></p>
<p>than those you&#8217;d typically see running on your local box:</p>
<p><em>http://localhost/~jeff/projects/wordpress/radio-station</em></p>
<p>But once I started playing with these, I decided it was MUCH easier to be able to deal with these super-short urls (think Bit.ly for your local box) than to have to type in the whole thing.  It&#8217;s made my life a lot simpler, so I figured I&#8217;d pass along the info.</p>
<p>Note that when you choose a host name, you&#8217;ll want to choose one that doesn&#8217;t exist on the web.  You&#8217;re basically overriding your machine&#8217;s host lookup functionality &#8212; hard coding urls to corresponding locations on your local disk &#8212; and thereby bypassing DNS lookup.  So if you pathed http://www.google.com to your local disk, your computer wouldn&#8217;t be able to find the real google until you undid the Virtual host.  So be careful.</p>
<p>I typically choose a hostname that includes the suffix .local.  That&#8217;s never given me any problems (eg. projects.local, flash.local, radio.local).</p>
<p>Let&#8217;s begin.</p>
<p>You&#8217;ll be dealing with 3 files on this:</p>
<ul>
<li>httpd.conf</li>
<li>httpd-vhosts.conf</li>
<li>hosts</li>
</ul>
<p>Which, if you followed the steps above, are located at:</p>
<ul>
<li>/opt/local/apache2/conf/httpd.conf</li>
<li>/opt/local/apache2/conf/extra/httpd-vhosts.conf</li>
<li>/private/etc/hosts</li>
</ul>
<p><strong>a. Enable Apache&#8217;s Virtual Host configuration</strong><br />
in httpd.conf, uncomment the Virtual Hosts line:</p>
<blockquote><p>Include conf/extra/httpd-vhosts.conf</p></blockquote>
<p>This will allow you to add hosts to your vhosts configuration file.</p>
<p><strong>b. Add host locations</strong></p>
<p>open the vhosts file in your favorite text editor:</p>
<blockquote><p>/opt/local/apache2/conf/extra/httpd-vhosts.conf</p></blockquote>
<p>The first thing you&#8217;ll want to do here is comment out the default examples they give you (the ones that include <em>ServerAdmin webmaster@dummy-host.example.com</em>).  You might want them as a reference, but you don&#8217;t want them to be active.  Comment them out.</p>
<p>Next you&#8217;ll add your host.  Substitute in values below to correspond to your build and the hostname you choose:</p>
<blockquote><p>&lt;VirtualHost *:80&gt;<br />
DocumentRoot &#8220;/Users/USERNAME/PATH&#8221;<br />
ServerName hostname.suffix<br />
&lt;/VirtualHost&gt;</p></blockquote>
<p>Typically life is easier if you choose a disk path inside of your Sites directory.  If you don&#8217;t you might need to do some more file permission configuration.</p>
<p>In my case, the host I added is:</p>
<blockquote><p>&lt;VirtualHost *:80&gt;<br />
DocumentRoot &#8220;/Users/jeff/Sites/projects&#8221;<br />
ServerName projects.local<br />
&lt;/VirtualHost&gt;</p></blockquote>
<p>So now Apache knows that when it&#8217;s told to serve any files referenced by the url projects.local, it&#8217;ll serve them from the path I&#8217;ve given it in my Sites directory.  There are other arguments you can add to the VirtualHost node, but this is all you need.</p>
<p><strong>c. Add host names to your hosts file</strong></p>
<p>Next you need to tell the machine that when you ask for that particular server name, you want it to ask the local Apache server to serve it.  Editing this file is globally applicable to all browser applications &#8212; so once you edit this file, programs like Firefox, Safari, Opera, etc will all serve up your local page instead of looking the url up with the friendly neighborhood DNS.</p>
<p>Your machine already does this to a certain extent &#8212; for example, the &#8216;localhost&#8217; prefix is already set up via the hosts file so that the machine knows to look to the local Apache server, rather than out on the web.  What we&#8217;re doing is adding one or many shortcuts that mimic this behavior &#8212; but which point to more specific locations on disk.</p>
<p>Open your hosts file:</p>
<blockquote><p>/private/etc/hosts</p></blockquote>
<p>and add the line:</p>
<blockquote><p>127.0.0.1     hostname.suffix</p></blockquote>
<p>(so in my case I added):</p>
<blockquote><p>127.0.0.1     projects.local</p></blockquote>
<p>then save the file.</p>
<p><strong>d. Restart Apache</strong><br />
Go back to the terminal and restart apache:</p>
<blockquote><p>sudo apachectl restart</p></blockquote>
<p>Now you should be all set.  Open up your browser and point it towards the virtual host you just made. In our case that&#8217;s:</p>
<p><em>http://projects.local</em></p>
<p>And your browser should serve up that url like magic. ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeffreyclarke.net/blog/2009/06/a-web-development-server-environment-on-leopard/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.708 seconds -->

