Tips on Local Development

February 20th, 2010 by Jack Keller

Okay, so I've posted before about MAMP, XAMPP and the alter­na­tives but now I'm going to dig a bit deeper into tricks and tips. Bear in mind that I'm writ­ing this on how I do my devel­op­ment and your soft­ware choices and the like may be some­what dif­fer­ent than mine.

Local­host: XAMPP
Lan­guage: PHP
Data­base: Sequel Pro
Edi­tor: Coda
OS: Snow Leop­ard

I usu­ally set up my sites in the Default ~/Sites folder on my Mac, just to keep things in one area mainly and for this demo we'll be using stardup.com (a domain I own and have never really done any­thing with due to time restraints).

I found this tuto­r­ial online a while back by Arron Wolf and it was a really good way to keep my log­i­cal file struc­ture instead of dup­ing direc­to­ries back and forth from XAMPP's native htdocs folder. This is not super intense a process even though some peo­ple may shy away from Com­mand Line. Fol­low along with the instruc­tions on that site if you want to get it set up for your lat­est project. Go ahead, I'll wait…

…Okay great, you're back! Now let's begin with one really dead easy trick to keep your con­fig­u­ra­tion files work­ing on both sides, with­out hav­ing to change them every time you com­mit many site changes.

PHP:
  1. if ($_SERVER["REMOTE_ADDR"] == "127.0.0.1") {
  2.  
  3.     $l = mysql_connect ( "local­host" , "root" , "" ) or die("Error con­nect­ing: <br /><br />".mysql_error());
  4.     mysql_select_db( "stardup" ) or die("Error get­ting db: <br /><br />".mysql_error());
  5.    
  6.     $siteurl = "http://stardup.dev/"; // WITH TRAILING SLASH!
  7.  
  8. } else {
  9.  
  10.     $l = mysql_connect ( "local­host" , "stardup_user" , "**********" ) or die("Error con­nect­ing: <br /><br />".mysql_error());
  11.     mysql_select_db( "stardup" ) or die("Error get­ting db: <br /><br />".mysql_error());
  12.  
  13.     $siteurl = "http://stardup.com/"; // WITH TRAILING SLASH!
  14. }

This can be done in any other pro­gram­ming lan­guage, how­ever the if/else syn­tax changes a bit. I've also begun tak­ing this a lit­tle fur­ther, includ­ing other bits in my code like $header and $footer stuff that will help me visu­ally deter­mine which one I may be look­ing at (as I'm often too lazy to look at the address bar).

So my next tip is related to run­ning a light­weight ver­sion of XAMPP (because you really don't need all of the fea­tures for local devel­op­ment). I write a very sim­ple Apple­script that launches XAMPP with options, and then placed it in my Sys­tem Pref­er­ences > Accounts > My Account > Login Items

CODE:
  1. do shell script "/Applications/XAMPP/xamppfiles/xampp star­ta­pache" user name "your­name" pass­word "your­pass­word" with admin­is­tra­tor privileges
  2. do shell script "/Applications/XAMPP/xamppfiles/xampp start­mysql" user name "your­name" pass­word "your­pass­word" with admin­is­tra­tor privileges

Now I know a lot of the more hard­core pro­gram­mers are prob­a­bly won­der­ing why I have to do the username/pass with admin­is­tra­tor priv­i­leges twice, the answer is because I know only as much Apple­script as I need to, and noth­ing more.

Share?
  • Facebook
  • Design Float
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Digg

Posted in Life, PHP, Tools, Workflow Be the first to comment! »

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

About media|extranet

We're a group of industry professionals who would like to give a little bit back to the community. Although we've just begun, we plan to do some write-ups on Advertising, Marketing, Development (.NET, PHP, Flash, Flex, AIR, JavaScript Frameworks, etc.) and Copywriting. Visit our contact section if you would like to see us cover something that we're not. The links below are for our writers, visit them directly if you have a project in mind that could utilize their talents.

Visit Snackbox