Currently Being Moderated

Setting up a local web server on MacOS X 10.7 "Lion"

Here is my definitive guide to getting a local web server running on MacOS X 10.7 “Lion”. This is meant to be a development platform so that you can build and test your sites locally, then deploy to an internet server. This User Tip only contains instructions for configuring the Apache server, PHP module, and Perl module. I have another User Tip for installing and configuring MySQL and email servers.


Note: This user tip is specific to MacOS X 10.7 “Lion”. Pay attention to your OS version.

Another note: These instructions apply to the client versions of MacOS X, not Server. Server does a few specific tricks really well and is a good choice for those. For things like database, web, and mail services, I have found it easier to just setup the client OS version manually.



  1. Basic understanding of and how to run command-line programs.
  2. Basic understanding of web servers.
  3. Basic usage of vi. You can substitute nano if you want.


  1. Xcode is required for adding PHP modules.


Lines in bold are what you will have to type in. Lines in bold courier should be typed at the Terminal.

Replace <your short user name> with your short user name.


Here goes... Enjoy!


To get started, edit the Apache configuration file as root:

sudo vi /etc/apache2/httpd.conf


Enable PHP by uncommenting line 111, changing:

#LoadModule php5_module libexec/apache2/


LoadModule php5_module libexec/apache2/

(If you aren't familiar with vi, go to line 111 by typing "111G" (without the quotes). Then just press 'x' over the '#' character to delete it. Then type ':w!' to save, or just 'ZZ' to save and quit.)


If you want to run Perl scripts, you will have to do something similar:


By default, Apache in Lion is not configured to support the Perl module. To enable full Perl support in Apache, insert the following at line 112, just after the line:

LoadModule perl_module libexec/apache2/

(if you aren't familiar with vi, go to line 111 and type "o" (without the quotes) to create a new blank line and enter editing mode. Type the line above or paste is from the clipboard. Press the "esc" key to return to command mode. Then save and quit.)


Then, configure Perl to run from any directory like PHP. In /etc/apache2/users/<your short user name>.conf change the line that says:

    Options Indexes MultiViews


    AddHandler perl-script .pl

    PerlHandler ModPerl::Registry

    Options Indexes MultiViews FollowSymLinks ExecCGI

(Hint: in vi, type "dd" (without the quotes) to delete a line.)


Lion and later versions no longer create personal web sites by default. If you already had a Sites folder in Snow Leopard, it should still be there. To create one manually, enter the following:

mkdir ~/Sites

echo "<html><body><h1>My site works</h1></body></html>" > ~/Sites/index.html.en

Now you are ready to turn on Apache itself. But first, do a sanity check. Sometimes copying and pasting from an internet forum can insert invisible, invalid characters into config files. Check your configuration by running the following command in the Terminal:

apachectl configtest


If this command returns "Syntax OK" then you are ready to go. It may also print a warning saying "httpd: Could not reliably determine the server's fully qualified domain name". You could fix this by setting the ServerName directive in /etc/apache2/httpd.conf and adding a matching entry into /etc/hosts. But for a development server, you don't need to do anything. You can just ignore that warning.


Turn on the Apache httpd service by running the following command in the Terminal:

sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist


There is a "Web Sharing" button in System Preferences > Sharing. It must also be checked to enable Apache.


In Safari, navigate to your web site with the following address:


It should say:


It works!


Now try your user home directory:

http://localhost/~<your short user name>


It should say:


My site works


Now try PHP. Create a PHP info file with:

echo "<?php echo phpinfo(); ?>" > ~/Sites/info.php


And test it by entering the following into Safari's address bar:

http://localhost/~<your short user name>/info.php


You should see your PHP configuration information.


To test Perl, try something similar. Create a Perl test file with:

echo "print \$ENV{MOD_PERL} . qq{\n};" >  ~/Sites/


And test it by entering the following into Safari's address bar:

http://localhost/~<your short user name>/

You should see the string "mod_perl/2.0.5".


If you want to setup MySQL, see my User Tip on Installing MySQL.


If you want to add modules to PHP, I suggest the following site. I can't explain it any better.


If you want to make further changes to your Apache system or user config files, you will need to restart the Apache server with:

sudo apachectl graceful


  • 0 Replies:

Delete User Tip

Are you sure you want to delete this user tip?