This guide will help you run WordPress(the blog app that runs this website) in your own personal Mac for testing purposes or for backing up your blog. On WordPress on Mac – Part 1: PHP & Mysql we covered installing PHP and MySQL. On part two we’ll cover setting up local sub-domains. What is a sub-domain and why do I need one? Sub-domains are websites with absolute URLs that are accessed via a prefix to the url i.e.the server mail.earthlink.net is a sub-domain of earthlink.net. Why do I want to do this locally? Because it will make it possible to mimic your website structure locally. In other words, it’s all about file paths. If you set it up your images and link will work, if not, you’ll have broken links and images.

Step 1: Setting up Apache
Apache comes as part of Mac OS X and it can be easily activated by the click of a button. However there are a few tweaks we need to do to Apache before we can use it for WordPress. To modify the Apache settings we need to edit some configuration files that are in some hidden folders. Now here a nerd will tell you to open the command line and edit the files in some DOS looking environment. But since we’re not nerds here, just cool geeks, we’ll use the free text editing application Text Wrangler which allows you to edit hidden text files and takes care of file permissions when saving.
Download Text Wrangler.

User Apache file
First we’ll edit your apache user file so that we can use ModRewrite in WordPress. ModRewrite is what translates search friendly URLS to the true url. From Text Wrangler, select “File > Open Hidden…” , make sure you enable “All Files” and navigate to the folder “etc/httpd/users/” then open the file of the current logged in user. In my case it’s “melvin.conf”.



Comment out these lines within the directory lines by adding the # symbol at the beginning of the lines:
#Options Indexes MultiViews
#AllowOverride None
Then Add the following lines
AllowOverride All
Options Indexes MultiViews ExecCGI FollowSymLinks Includes
Order allow,deny
Allow from all
Close the file.
Mod-Rewrite Log
Now we’ll specify where to log any errors for Mod Rewrite. From Text Wrangler, select “File > Open Hidden…” and navigate to “etc/httpd/httpd.conf”. Go to the end of the file and add the following code:


# begin custom edit
# mod_rewrite
RewriteLog /var/log/httpd/rewrite.log
RewriteLogLevel 9
#end custom edit
Keep the file open for the next step.
Local Sub-Domains
Next we’re going to set up a local sub-domain. This will allow our site URl to be “http://blog.localhost” instead of “http://localhost/~username/blog”. A local sub-domain will allows us to set up our local blog in the same way we would if we had it hosted at a public server. For example we use absolute URLs like ‘/images/header.jpg’ and that code will work on both local or public servers. It also makes for a very short and manageable URLs.
From Text Wrangler, add the following code after the Rewrite segment we just added but before the “#end custom edit” line.

# virtual hosts
NameVirtualHost 127.0.0.1# localhost
ServerName localhost
DocumentRoot /Users/melvin/Sites/
# wordpress.localhost
ServerName wordpress.localhost
DocumentRoot /Users/melvin/Sites/Projects/wordpress
# change the sub-domain name to your desired sub-domain name
# change to the name of your home folder
# change to the path of your project folder from the Sites folder
The first part will link “localhost” to your personal “SItes” folder. The second part is to specify the sub-domain. In this case I want the sub-domain “http://wordpress.localhost/” to test a custom version of wordpress, however you can rename this to whatever you want. Replace the path of DocumentRoot to the path to your site. In my case I put all my projects in a folder called Projects in the Sites folder in my home folder. For this example I am using the folder name wordpress but you can rename it according to your project name. Repeat this second block for each sub-domain needed.
Close the file.
Hosts File
Next we’ll add the sub-domains to the list of hosts. From Text Wrangler, select “File > Open Hidden…” and navigate to “etc/hosts”. Add the following line to the list. Make sure you specify the same sub-domain you did in the previews step:


127.0.0.1 wordpress.localhost
Restart the Apache Server
From the Finder select ‘Apple > System Preferences > Sharing > Services’ and Start ‘Personal Web Sharing’. Quit System Preferences.

Now point your browser to http://wordpress.localhost or whatever sub-domain name you chose.

If you don’t have anything in the folder you specified in the previews step you will get this 404 Not Found Error. This means it’s working. You can move any html files to that folder for testing. Or as we’ll do in the next Step of this tutorial, download WordPress and place the files on that folder.
Hello, I am Melvin Rivera; creator of
Follow me @


I am having great difficulty in getting a database set-up using any number of the SQL utilities out there. Can you advise to set-up using MySQL?
I can’t seem to get a user under that httpd file. I’ve looked on my network, & my hard drive, but nothing!
What am I supposed to be logged into here, the computer, or what? I must be missing something.
Dunno if this is on the right one, but I upgraded to Tiger and now Safari cant find my local host, where do I need to go back to in this process?? or is there something else I need to do??
Cheers!!
phil,
tiger might have replaced your apache config files. u might have to redo the step of editing the config files.
Is this only for setting up a test site, or is this the real deal – as in, once I have done this all, I will basically be hosting my site from my mac?
gavin stone,
i’m not sure why u are having a problem installing mysql. that’s the easiest part of the whole process. it woul help if u give us more info on the os version u have and what exactly r u trying to isntall.
david,
look again clearly.
From Text Wrangler, select “File > Open Hidden…” , make sure you enable “All Files” and navigate to the folder “/etc/httpd/users/” then open the file of the current logged in user. In my case it’s “melvin.conf”.
by the logged in user, i mean the user you are logged in as on your mac.
Melvin,
Great set of articles, but i’m still having trouble. I did all the editing you perscribed and even used all your files directories except for the part where I put my name. I go to System Preferences > Sharing > Services’ and Start ‘Personal Web Sharing, but the thing freezes by saying web sharing starting up. If I close system preferences and go back in web sharing is stopped. Something went wrong along the way and I really don’t know what I’m doing in the first place. help would be nice. Thanks
Gavin
if it’s freezing while trying to start apache then there must be an error in either the apache config file, the user apache file or the hosts file. double, i would say tripple check everything.
Melvin
I went through the steps again and the system preferences doesn’t freeze anymore, but when I go to test the sub-domain it gives me this:
Forbidden
You don’t have permission to access / on this server.
Apache/1.3.33 Server at wordpress.localhost Port 80
I don’t know if I need to authenticate somewhere or if this is normal. Thanks for the help.
Gavin