Native Web Development (apache, PHP and mySQL) on Mac OSX Leopard post thumbnail

Native Web Development (apache, PHP and mySQL) on Mac OSX Leopard

If you’re a web developer and you’re on a Mac, you’re probably using MAMP or XAMPP for your all in one apache + PHP + mySQL need. But did you know that your Mac system is already a web server by default installation? Utilizing the native web server, you can save yourself from downloading stuffs you don’t need.

It is not as complicated as you think. Given that Macs are descendants of *nix system, it already has apache2 and PHP module built in, we only need to activate those two and install mySQL. Here’s how.

Activating apache web server

Piece of cake, you only need to go to System Preferences and then to the Sharing prefpane.

System Preferences

System Preferences

Inside the Sharing prefpane check the web sharing on the left hand side. Simple as that and you’re done.

Check web sharing in the pref pane

Check web sharing in the pref pane

You know where you have the folder Sites in your home folder? If you put anything there, it will be accessible via http://localhost/~yourusername/. Cute anot?

Activating the PHP module

You will need to type things into terminal this time. This is also a piece of cake, don’t be afraid, the Terminal is our friend :)
To run terminal you can spotlight it or go to Applications / Utilities using Finder.

Terminall app via Finder

Terminall app via Finder

Here’s what you have to do in Terminal.

  1. First go to /etc/apache2/ directory by typing cd /etc/apache2/ <return>. If it returns an error check your input, see if you’ve typed it right.
    Opening the httpd.conf in terminal

    Opening the httpd.conf in terminal

  2. Next on, let’s open the apache configuration file: httpd.conf as root. We do this by typing sudo nano httpd.conf. You will be prompted to enter your login password. Upon doing so, this screen will show. This is nano, Terminal’s text editor.

    Editing httpd.conf using nano on Terminal

    Editing httpd.conf using nano on Terminal

  3. Now we’re going to activate the PHP5 module. If you take a look at the terminal screen, you’ll see a list of commands. We’ll do a ^W aka Where Is to find the line that says php5. Press Ctrl+W, type in php5 <return>
  4. Take a good look at the terminal screen, you will see this line:
    #LoadModule php5_module libexec/httpd/libphp5.so. You only have to delete the # sign:
    LoadModule php5_module libexec/httpd/libphp5.so
  5. Done, now exit nano with ^X command. You will be prompted to save your changes. Type Y <return> to save and exit. Don’t change the file name in process btw ;)

    Save and exit with ^X

    Save and exit with ^X

That’s it, we have ourselves an apache2 web server with PHP. You can check if the PHP module’s running with a simple phpinfo();

Installing mySQL

Another walk in the park. If you don’t already have it, you can download mySQL server here. You are looking for the mySQL server installer in package format, it’s the .dmg format you’re already familiar with. It’s a 60MB download, smaller than the 70+ MB XAMPP and 130+ MB MAMP ;)

Installing is simple, mount the .dmg and then install all the packages including the .prefpane. After installing all items you will be taken to the newly installed mySQL prefpane.

mySQL prefpane

mySQL prefpane

Done, now mySQL’s up and running. You might want to install Navicat or phpMyAdmin for the mySQL front end. Now that you have everything working, you can already start developing.

Extra: VirtualHostX to shorten your working URL

I’m not a big fan of long URLs, my working host is http://localhost/~anima/ and my phpMyAdmin URL is http://localhost/~anima/phpmyadmin/. Those are long badass URLs and I hate them, so I looked for a workaround shortening them and that’s when VirtualHostX comes to the rescue.

VirtualHostX

VirtualHostX

This way I can shorten my http://localhost/~anima/ to http://anima/ and my http://localhost/~anima/phpmyadmin/ to http://mysql/

Free version of VirtualHostX allows you to create 3 host names, that should be enough: one for the main working URL, one for mySQL and you have an extra one. Different story if you want to assign each projects of yours with a different host name. You must get a license then :)

Tyler Hall (the developer of VirtualHostX) was very kind to give me a free license of this because I tweeted something about it :)

Gotta love Macs, they have the beauty and the brains inside :) Happy developing!

[Post to Twitter] Tweet This  [Post to Delicious] Delicious This  [Post to Digg] Digg This  [Post to Ping.fm] Ping This  [Post to Reddit] Reddit This  [Post to StumbleUpon] Stumble This 

11 Comments

  1. nice post juragan! numpang ngelink + numpang tenar ya?

  2. Baru aja mau install xampp. Thanks! Eh tapi cuma beda 10MB tuh jadinya :)

  3. @Daus Haha, iyah memang, tapi the joy of doing things your way itu loh mas. dan juga, save one extra dock icon :D

  4. this is what we call The Passion Of A Mac User hehehe
    aku kok ya senengan yang instant ajah.

    nice tutorial!

  5. Thanks this was helpful. But you could ditch VirtualHostX and just edit the Apache VHosts file and your macs “hosts” file (/etc/hosts) and you can make routes like http://www.mytestsite.com go to your folder “Users/anima/Sites/testsite” i find the much more useful, so i just type in a normal domain.

  6. Thank’s. I’m stil trying to run navicat. I can’t make it connect to localhost.
    Let’s see how is my level on mac…..

  7. @carlos oh that’s interesting, I don’t have NaviCat so I didnt try. Could you make it work?

  8. As far I’m consern, Navicat is the best to managing MYSQL. http://www.navicat.com

  9. Maybe you could remember the user to restart apache after editing httpd.conf

  10. tea tree oil to treat vaginal itching Order Viagra Soft Tabs generic network card ben johnson drugs marine corps combat stress
    http://rxdrugs24×7.com/product/nizoral.html

  11. good job..well done.. :D

Leave a Reply

(required)

(will not be published) (required)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>