Tips on Local Development
Okay, so I've posted before about MAMP, XAMPP and the alternatives but now I'm going to dig a bit deeper into tricks and tips. Bear in mind that I'm writing this on how I do my development and your software choices and the like may be somewhat different than mine.
Localhost: XAMPP
Language: PHP
Database: Sequel Pro
Editor: Coda
OS: Snow Leopard
I usually 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 anything with due to time restraints).
I found this tutorial online a while back by Arron Wolf and it was a really good way to keep my logical file structure instead of duping directories back and forth from XAMPP's native htdocs folder. This is not super intense a process even though some people may shy away from Command Line. Follow along with the instructions on that site if you want to get it set up for your latest project. Go ahead, I'll wait…
…Okay great, you're back! Now let's begin with one really dead easy trick to keep your configuration files working on both sides, without having to change them every time you commit many site changes.
-
if ($_SERVER["REMOTE_ADDR"] == "127.0.0.1") {
-
-
$l = mysql_connect ( "localhost" , "root" , "" ) or die("Error connecting: <br /><br />".mysql_error());
-
-
$siteurl = "http://stardup.dev/"; // WITH TRAILING SLASH!
-
-
} else {
-
-
$l = mysql_connect ( "localhost" , "stardup_user" , "**********" ) or die("Error connecting: <br /><br />".mysql_error());
-
-
$siteurl = "http://stardup.com/"; // WITH TRAILING SLASH!
-
}
This can be done in any other programming language, however the if/else syntax changes a bit. I've also begun taking this a little further, including other bits in my code like $header and $footer stuff that will help me visually determine which one I may be looking at (as I'm often too lazy to look at the address bar).
So my next tip is related to running a lightweight version of XAMPP (because you really don't need all of the features for local development). I write a very simple Applescript that launches XAMPP with options, and then placed it in my System Preferences > Accounts > My Account > Login Items
-
do shell script "/Applications/XAMPP/xamppfiles/xampp startapache" user name "yourname" password "yourpassword" with administrator privileges
-
do shell script "/Applications/XAMPP/xamppfiles/xampp startmysql" user name "yourname" password "yourpassword" with administrator privileges
Now I know a lot of the more hardcore programmers are probably wondering why I have to do the username/pass with administrator privileges twice, the answer is because I know only as much Applescript as I need to, and nothing more.
Posted in Life, PHP, Tools, Workflow Be the first to comment! »

