Setting up a local web server on OS X Snow Leopard 10.6

Basic Web Server

MAMP is great. It’s an easy way to host your PHP/MySQL site locally for test­ing and devel­op­ment. But, if you want to take advan­tage of Snow Leopard’s built in web server capa­bil­i­ties, OS X makes it easy. Go into Sys­tem Pref­er­ences > Shar­ing, and check the “Web Shar­ing” box.

That’s it. You can now setup an HTML-only web­site locally. Where do you put the files? The default folder is /Library/WebServer/Documents/. While we’re at it, let’s setup PHP and MySQL to work locally, as well.

Test it. http://localhost. No need for a port as it will use apache’s default port 80.

PHP and MySQL will now need to be setup for a full func­tion­ing local host.

Set­ting up PHP

Open up Ter­mi­nal (Applications->Utilities->Terminal) and type:

sudo nano /etc/apache2/httpd.conf

Go to this line

#LoadModule php5_module        libexec/apache2/libphp5.so

and uncom­ment the line by remov­ing the hash character

LoadModule php5_module        libexec/apache2/libphp5.so

After sav­ing the file (Control+O) and exit­ing (Control+X). Restart Apache.

sudo apachectl restart

Con­fig­ur­ing PHP

cd /etc
sudo cp php.ini.default php.ini
sudo chmod 666 php.ini
sudo nano php.ini

Find this line and remove the semi-colon

;date.timezone = 

and add your own time­zone. A list of time­zones can be found here (http://php.net/manual/en/timezones.php)

date.timezone = America/Halifax

You’re halfway there. PHP 5 is now run­ning on your local server.

Set­ting up MySQL

Down­load the MySQL pack­age for Mac OS X.5 (32 or 64 bits depend­ing on your machine)
Install every­thing in the pack­age in this order:

  • mysql
  • the startup item
  • the pref­er­ence pane.

Now, open /etc/php.ini, find these three lines

pdo_mysql.default_socket=/var/mysql/mysql.sock
mysql.default_socket = /var/mysql/mysql.sock
mysqli.default_socket = /var/mysql/mysql.sock

and replace /var/mysql/ with /tmp/

pdo_mysql.default_socket=/tmp/mysql.sock
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

After installed, you can start MySQL in the sys­tem pref­er­ences. To access your data­base from the Terminal

/usr/local/mysql/bin/mysql -u root

Change your Home Directory

Want your local server’s files to be located some­where other than the default /Library/WebServer/Documents/? Open /etc/apache2/httpd.conf, and change the next two lines to reflect your new home directory.

DocumentRoot "/Library/WebServer/Documents"
...
<Directory "/Library/WebServer/Documents">

Dru­pal Problems?

If you’re get­ting errors dur­ing Dru­pal instal­la­tion try link­ing the MySQL sock file like below

cd /
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Drupal’s Clean Urls

Hav­ing prob­lems enabling Clean Urls? Find all instances of the fol­low­ing line in /etc/apache2/httpd.conf

AllowOverride None

and change None to All

AllowOverride All

45 Responses to Setting up a local web server on OS X Snow Leopard 10.6

  1. Nice and to the point of the matter!

  2. Awe­some tuto­r­ial. I was using MAMP and it just doesn’t work how I’d like it to. Now my iMac feels even more hawt.

  3. Luke Sent me over here via twit­ter. Got my MBP today and this filled a seri­ous gap. Thanks a lot

  4. Apt, use­ful & con­cisely pre­cise.
    Thanks a lot!

  5. Thanks — exactly what I needed to get up and run­ning with some local dev.

    You the man!

  6. I really appre­ci­ate this post but I’m lost after installing mysql! How do I open /etc/php.ini?

    • Open­ing php.ini is in the Con­fig­ur­ing PHP sec­tion, the first and last lines will open it up.

      I ended up get­ting a PDO error, couldn’t con­nect to the file, if this hap­pens, just restart apache by unclick­ing and reclick­ing the ‘Web Shar­ing’ box in the first step.

  7. Great tuto­r­ial — clear and to the point. Thanks!

  8. I just fol­lowed these instruc­tions on OS X Lion and it works, the prob­lem is I can­not seem to find the web­page which is dis­played and which sim­ply says it works! I looked in the /Library/WebServer/Documents direc­tory and there is no file there.

    • I went to the Library folder, and I did not found the Webserver

      • There are two “Library” fold­ers on your machine.

        Make sure you go to “Mac­in­tosh HD”->“Library”->“WebServer”->“Documents”

        or

        Go into Finder, click Go in the top bar, select “Go to Folder…” then type “/Library/WebServer/Documents/”

        The other library folder (in your home folder) does not have the Web­Server files.

        Hope that helps.

  9. Thanks, man. It is still use­ful for me even I just want prac­tice writ­ing html+css and js

  10. Can any­one sug­gest why I can open http://192.168.1.102/~JS/

    if I click the link in Sys­tem Preferences/Sharing/Web Sharing

    but once I am in the browser, if I try a refresh on that page I get Fire­fox can’t estab­lish a con­nec­tion to the server at 192.168.1.102″

  11. Fix for my above problem:

    Edit httpd.conf

    # OLD —Doc­u­men­t­Root “/Library/WebServer/Documents”

    Doc­u­men­t­Root “/Users/JS/Sites”

  12. This is a nice piece you have going here…thanks..
    Do you think you could add a bit on con­fig­ur­ing for phpmyAdmin?

  13. Thanks so much — top article

  14. Ace arti­cle, stripped my mac of every­thing clut­tered thats not built in, although Im lost at “sudo apachect1 restart” — com­mand not found

  15. my bad.. mis­taken the l for a 1 — oops :)

  16. emandeguzman

    Thanks!
    Very easy to follow

  17. Not a very good tuto­r­ial as you assume every­one knows how to use use ter­mi­nal. What is meant by, Go to this line? How do you edit text in this thing — it’s horrible.

    • sim­ply typ­ing ctrl+w will enable you to find the line needed. that lit­tle 8 bit cur­sor you see? take it where you want to using the arrow keys and press back­space to delete it. the instruc­tions using ter­mi­nal are are the bot­tom of the ter­mi­nal. couldn’t be simpler.

      I’d rec­om­mend installing php­myad­min as a man­ager as its pretty darn good (most cpanel’s online use it)

  18. Gday, I’m new to blog­ging and web­sites in gen­eral
    and was curi­ous about how you got the “www” included in your
    domain name? I see your domain name, “http://georgebutler.com/blog/setting-up-local-web-server-on-os-x-snow-leopard-10–6/” has the www and
    my domain looks like, “http://mydomain.com”. Do you know just how I can alter
    this? I’m using Word­Press plat­form. Thanks for yor time

  19. I’m new to devel­op­ing web­sites and I was won­der­ing if hav­ing your site title related to your arti­cles and other con­tent really that vital? I notice your title, “%BLOGTITLE% ” does appear to be spot on with what your blog is about how­ever, I pre­fer to keep my title less con­tent descrip­tive and based more around site brand­ing. Would you think this is a good idea or bad idea? Any assis­tance would be greatly val­ued.
    supra high tops http://www.scrapbookstoreslist.com/countries/supraca.html

  20. Hey there. I am won­der­ing if you’d be inter­ested in doing a web­site link exchange? I notice your blog: %BLOGURL% and my web­site are struc­tured around the same sub­ject mat­ter. I’d love to swap links or per­haps guest author a arti­cle for you. Here is my per­sonal email: %EMAIL%. You should con­tact me if you’re even slightly inter­ested. Many thanks.
    supra sky­top 3 http://www.scrapbookstoreslist.com/legal/stuff.html

  21. When I ini­tially com­mented I clicked the “Notify me when new com­ments are added” check­box and now each time a com­ment is added I get four e-mails with the same com­ment. Is there any way you can remove me from that ser­vice? Bless you!
    cheap ghds http://www.wildwoodultimate.com/ghdstraightener.html

  22. It’s a shame you don’t have a donate but­ton! I’d with­out a doubt donate to this superb blog! I guess for now i’ll set­tle for book­mark­ing and adding your RSS feed to my Google account. I look for­ward to new updates and will talk about this site with my Face­book group. Talk soon!
    mon­ster head­phones http://www.kingwin.com/buy/online_buy.asp

  23. I know this if off topic but I’m look­ing into start­ing my own blog and was won­der­ing what all is required to get setup? I’m assum­ing hav­ing a blog like yours would cost a pretty penny? I’m not very web savvy so I’m not 100% sure. Any tips or advice would be greatly appre­ci­ated. Thanks
    nike free run http://www.kingwin.com/news/news_pages.asp

  24. Please let me know if you’re look­ing for a author for your site. You have some really great posts and I believe I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some mate­r­ial for your blog in exchange for a link back to mine. Please blast me an email if inter­ested. Thank you!
    nike air max 90 http://www.kingwin.com/products/pwrsupply_line_u.asp

  25. My spouse and I absolutely love your blog and find most of your post’s to be exactly I’m look­ing for. Does one offer guest writ­ers to write con­tent for you per­son­ally? I wouldn’t mind pub­lish­ing a post or elab­o­rat­ing on a num­ber of the sub­jects you write related to here. Again, awe­some blog!
    supra http://www.scrapbookstoreslist.com/ContactUs.html

  26. Howdy would you mind let­ting me know which web host you’re using? I’ve loaded your blog in 3 dif­fer­ent inter­net browsers and I must say this blog loads a lot faster then most. Can you rec­om­mend a good host­ing provider at a hon­est price? Many thanks, I appre­ci­ate it!
    ghd styler http://www.susanlenz.com/

  27. Wow that was strange. I just wrote an very long com­ment but after I clicked sub­mit my com­ment didn’t show up. Grrrr… well I’m not writ­ing all that over again. Any­way, just wanted to say superb blog!
    Mon­cler Sale http://www.wildwoodultimate.com/Monclerca.html

  28. Wow, awe­some blog lay­out! How long have you been blog­ging
    for? you make blog­ging look easy. The over­all look of your site is fan­tas­tic, let alone the content!

  29. raindancedani

    you da man.
    thanks for the magic.

  30. Great tuto­r­ial. Just what I was look­ing for. Thank you.

  31. I found a very easy to use with mysql on mac os x free tool — Valentina Stu­dio http://www.valentina-db.com/en/valentina-studio-overview Does every­thing you need, and does it very well.

  32. Hello! I just want to offer you a big thumbs up for the excel­lent info you’ve
    got here on this post. I’ll be return­ing to your web site for more
    soon.

  33. Every week­end i used to pay a visit this web­site, because i wish for enjoy­ment, since this this site cona­tions
    really good funny mate­r­ial too.

  34. It’s a shame you don’t have a donate but­ton! I’d cer­tainly donate to this
    bril­liant blog! I guess for now i’ll set­tle for book­mark­ing and adding your
    RSS feed to my Google account. I look for­ward to fresh updates and will share this site with
    my Face­book group. Talk soon!

  35. Great blog! Do you have any tips and hints for aspir­ing
    writ­ers? I’m plan­ning to start my own site soon but I’m a lit­tle
    lost on every­thing. Would you pro­pose start­ing with a free plat­form like Word­Press
    or go for a paid option? There are so many options out
    there that I’m com­pletely over­whelmed .. Any rec­om­men­da­tions?
    Appre­ci­ate it!

Trackbacks/Pingbacks

  1. Sasha – Mac OS X 10.6 Snow Leopard Localhost Environment Setup
  2. Fridge Gizmo step 2 | Blog My Wiki!
  3. Menjalankan Server di Mac Os | The furthest place you rarely be is : your heart

Leave a Reply

Web Design Ideas and Resources