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).
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.
cd /Users/yourname/Sites mkdir mysite.com cd mysite.com printf "My awesome site" > index.html
Great - we’ve created our site. Now let’s set up Apache.
First we need to allow virtual hosts by uncommenting a line in the Apache config file
sudo vi +/'# Virtual hosts' /etc/apache2/httpd.conf
Save the file and exit
Now we can add the virtual host
sudo vi /etc/apache2/extra/httpd-vhosts.conf
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.
<VirtualHost *:80> <Directory /Users/yourname/Sites/mysite.com> Options +FollowSymlinks +SymLinksIfOwnerMatch AllowOverride All </Directory> DocumentRoot /Users/yourname/Sites/mysite.com ServerName mysite.local </VirtualHost>
As there is no DNS associated with your site we need to set this.
sudo vi /etc/hosts
Add the following. This relates to the ServerName you set in the Step 2
Now we just need to start apache
sudo apachectl start
If you see
org.apache.httpd: Already loaded
Then it is already running so restart it using
sudo apachectl restart
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”
If you need PHP then this needs to be enabled. You can do this using
sudo vi +/php5_module /etc/apache2/httpd.conf
#LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php5_module libexec/apache2/libphp5.so
Then save and exit. Finally we need to restart apache:
sudo apachectl restart
Now lets see if PHP is running ok:
cd /Users/yourname/Sites cd mysite.com printf "<?php phpinfo() ?>" > index.php
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.
Linux and Unix fc command tutorial with examples
Tutorial on using fc, a UNIX and Linux command for editing and re-executing commands previously entered into an interactive shell. Examples of editing and re-executing the last command, editing and executing a previous command, setting the text editor to be used, listing previous commands and executing a command without editing it.
Linux and Unix cal command tutorial with examples
Tutorial on using cal, a UNIX and Linux command for displaying a calendar in the console. Examples of displaying a single month, multiple months, showing week numbers, Julian dates and arbitrary dates passed as arguments.
Linux and Unix du command tutorial with examples
Tutorial on using du, a UNIX and Linux command for estimating file space usage. Examples of showing a disk usage summary, outputting a human readable format, showing the size of a directory and showing the ten largest files or folders on a system.