Apache, PHP & vhosts

Apache configuration is one of the stumbling blocks that keeps a lot of web designers from using programming languages like PHP. This page is geared toward web designers with little to no previous knowledge of how to use terminal or configure Apache.

Introduction to Apache on your mac

wildflowers

When making websites and testing them locally you won’t be able to use server side programming languages like PHP. You also can’t use absolute paths to files or images which is a major drag. If you have a mac with OS X though you have the Apache web server already installed on your computer. You just need to turn it on and do some configuration and you can develop your sites locally instead of uploading your files to a remote server every time you want to see a change.

One Time Setup Steps

1. Read The Disclaimer

This tutorial walks you through making changes to your system’s default installation of Apache, it’s been tested on a few computers running OSX 10.3, 10.4, & 10.5 and everything has worked great. This does not however mean we guarantee it’ll work for you.

Use this tutorial at your own risk: We’re not in any way responsible for any errors in this text, or any damage that may result from misunderstanding the tutorial.

If you aren’t very interested in learning about how to configure Apache and you’d rather it just worked, you may want to check out MAMP and VirtualHostX.

Still with us? If so, get a cold drink and get comfortable because the one time setup steps can take a bit of time if you’re new to this stuff.

2. Welcome To Your Sites/ Directory

3. Starting Apache

Set Your System Preferences

Test To Make Sure Apache Is Running

4. Open Your Terminal

5. Opening and Editing httpd.conf

Because Leopard upgraded to Apache 2 and PHP 5, your httpd.conf file is in a different location depending on your version of OS X.

Opening the file

Enabling PHP

Including my-vhosts.conf

Next, we’ll include a file that defines our virtual hosts (our websites).

Save the file

6. Making your my-vhosts.conf file

7. Editing our Hosts file

8. Restarting Apache

Does it work?

You should now be able to see your website by going to http://test/ in any web browser on the computer you setup. You can even simply type test into the browser and get the page.

If you are still having problems let us know and maybe we can help

If it did work but there’s something that you thought could be clearer, let us know how we can improve the tutorial.

Steps to take each time you add a new site

1. Add A New Site (directory) to your Sites/ folder

2. Adding a new site to your my-vhosts.conf file

3. Open Your Terminal

4. Adding a new site to your Hosts file

5. Restarting Apache

Follow the instructions above for Restarting Apache

Does it work?

You should now be able to see your website by going to http://newsite/ in any web browser on the computer you setup. You can even simply type newsite into the browser and get the page.

If you are still having problems let us know and maybe we can help

If it did work but there’s something that you thought could be clearer, let us know how we can improve the tutorial.

Credits

Thanks to Justin Blecher for getting us started with vhosts and Jessica Chen for letting us use her computer as a guinea pig.

mYm Feeds RSS

Topics covered:
Enable Javascript