Not keen on the command line? Using something like MAMP may be a better option for you. I’m using vi to edit the files but feel free to use your text editor of choice (TextMate, emacs etc).
Step 1 - Creating your site
On OSX websites are stored in /Users/yourname/Sites so it is a good idea to store your site in there. Let’s create a site in there. Note you’ll need to change yourname in the example to whatever your name is.
1 2 3 4 | |
Great - we’ve created our site. Now let’s set up Apache.
Step 2 - Setting up Apache
First we need to allow virtual hosts by uncommenting a line in the Apache config file
1
| |
Change
1
| |
to
1
| |
Save the file and exit
Step 3 - Adding the virtual host
Now we can add the virtual host
1
| |
Add the following to the end of the file. Remember to change ‘yourname’ to whatever your name is and also ‘mysite.com’ to whatever your site folder name is. ServerName is the name you will use to access the site from a browser so if you want something specific change it.
1 2 3 4 5 6 7 8 | |
Step 4 - Setting your hosts file
As there is no DNS associated with your site we need to set this.
1
| |
Add the following. This relates to the ServerName you set in the Step 2
1
| |
Step 4 - Start Apache
Now we just need to start apache
1
| |
If you see
1
| |
Then it is already running so restart it using
1
| |
Now open a browser and visit “http://mysite.local/” (or whatever ServerName you set). All being well you should see a page displaying “My awesome site”
Step 5 - Enable PHP
If you need PHP then this needs to be enabled. You can do this using
1
| |
Change
1
| |
to
1
| |
Then save and exit. Finally we need to restart apache:
1
| |
Now lets see if PHP is running ok:
1 2 3 | |
Now if you open a browser and visit http://mysite.local/index.php you should see the phpinfo() page. Apache is set to serve index.html before index.php so if you delete the index.html you will also be able to access the phpinfo() page at http://mysite.local.
All done! To add further sites just repeat steps 3, 4 and 5.