WordPress on Mac Part 2: Sub-Domains

Posted on Tuesday, August 23rd, 2005 at 8:02 am under Mac Geekery, Tutorials, Web, Wordpress.

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.

WordPress on sub-domain

Technorati Tags: , , ,



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.

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”.

Open Hidden File

Open Apache User File

Apache User File

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:

Open Apache Config File

Rewrite Log

# 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

# 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:

Open Hosts File

Add Hosts

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.

Restart Apache

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

Not Found Error

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.

Pings are open Comments are open Comments RSS

42 Responses to “WordPress on Mac Part 2: Sub-Domains”

  1. gravatar Flag Jon Trainer
    Aug 23rd, 2005 at 8:51 am

    Nice set of articles. Thanks for putting this together. It’ll work as a nice reference for getting all this worked out for local development and testing.

  2. gravatar Flag nga
    Aug 23rd, 2005 at 2:40 pm

    sorry, i don’t have the time to write more — but to make it short: there is a much easier way to get wp or any other php/mysql thing running on a mac : MAMP (= Macintosh, Apache, Mysql and PHP). It’s a very easy solution — you don’ need any configuration. A user (James) at macupdate about it: «Drag a single folder to your applications folder, [that's it!] […] Note : it leaves the standard mac os X apache alone - so php will only work when ynu access the pages on the port 8888 (that is the default for MALP but im sure it is easy to change to 80 if you wish) webpages go in a sub folder in the same folder»

  3. gravatar Flag Melvin - All Forces
    Aug 23rd, 2005 at 3:17 pm

    nga,
    the way i described to install php and mysql is by the use of two installers. the configuration files need to be edited for specific features that would make it possible to mimic a public website. specifically sub-domains and mod-rewrite.

  4. gravatar Flag Justin Halsall
    Aug 23rd, 2005 at 3:26 pm

    I’m using Apache 2, and a separate install of php ect.
    But unfortunatly adding a sub domain doesn’t work :(
    Changing the folder standard folder does work:
    # localhost

    ServerName localhost
    DocumentRoot /Users/justin/Sites/

    but this:
    # test.localhost

    ServerName test.localhost
    DocumentRoot /Users/justin/Sites/test/

    doesn’t :(

    do you know what is wrong?
    Its probably got something to do with not being able to add
    127.0.0.1 wordpress.localhost
    cause the hosts file doesn’t seem to exists on apache 2

    Can anyone save my day?? plz :)

  5. gravatar Flag Justin Halsall
    Aug 23rd, 2005 at 3:31 pm

    ok scrap that :)
    if you want it to work just add it to the regular hosts file then it will work.
    (the one in etc/ )

  6. gravatar Flag iGav
    Aug 24th, 2005 at 2:02 am

    Great set of articles. Have only just started dipping my toe in the water of Wordpress by downloading and installing - nice to see there are some articles around by and for other OS XC users

    Looking forward to the rest in the series

  7. gravatar Flag Justin Halsall
    Aug 24th, 2005 at 7:02 am

    Oh wait this is great!
    I now use the real url of the sites but instead of .com or something else I use .x

    Its very easy
    just add stuff like this:
    127.0.0.1 test.x

    # test.x

    ServerName test.x
    DocumentRoot /Users/myusername/Sites/test/

    Very very very easy and it saves me typing localhost everytime

  8. gravatar Flag Zach Forrester
    Aug 26th, 2005 at 12:08 pm

    little problem, here, Melvin. My httpd.conf file only goes up to line 118, and when I do a search in the file for “# begin custom edit,” it comes up blank.
    whatsup?

  9. gravatar Flag Melvin - All Forces
    Aug 26th, 2005 at 12:30 pm

    Zach, you are doing good. I added the “#begin custom” part at the end of the document. it was not there before.

  10. gravatar Flag Zach Forrester
    Aug 26th, 2005 at 7:30 pm

    ohhhhhh. duh. i feel like a monkey, it’s right there…. “Go to the end of the file and add the following code:”
    sheesh. Great tutorials, melvin, hopefully I’ll read them a little closer ; )

  11. gravatar Flag Gavin Stone
    Sep 1st, 2005 at 10:52 am

    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?

  12. gravatar Flag David
    Sep 26th, 2005 at 11:28 am

    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.

  13. gravatar Flag Phil Bowell
    Oct 4th, 2005 at 9:50 am

    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!!

  14. gravatar Flag Melvin - All Forces
    Oct 4th, 2005 at 10:09 am

    phil,
    tiger might have replaced your apache config files. u might have to redo the step of editing the config files.

  15. gravatar Flag Jeremy
    Oct 26th, 2005 at 2:31 am

    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?

  16. gravatar Flag Melvin - All Forces
    Nov 8th, 2005 at 10:24 pm

    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.

  17. gravatar Flag Melvin - All Forces
    Nov 8th, 2005 at 10:28 pm

    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.

  18. gravatar Flag Gavin
    Nov 11th, 2005 at 1:44 am

    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

  19. gravatar Flag Melvin - All Forces
    Nov 11th, 2005 at 9:12 am

    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.

  20. gravatar Flag Gavin
    Nov 11th, 2005 at 3:14 pm

    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

  21. gravatar Flag Gavin
    Nov 11th, 2005 at 3:26 pm

    If I try to re test the sub-domain name it gives me the apache test screen. again I don’t know if this is a green light to proceed

  22. gravatar Flag Melvin - All Forces
    Nov 11th, 2005 at 3:30 pm

    gaving, the forbidden error might stoem from a lack of an index file or bad permissions. is the site somewhere withing the Sites folder?

  23. gravatar Flag Melvin - All Forces
    Nov 11th, 2005 at 3:31 pm

    what’s the apache test screen?

  24. gravatar Flag Gavin
    Nov 11th, 2005 at 4:37 pm

    Melvin

    this is what I get now when itry to test my sub-domain name

    If you can see this, it means that the installation of the Apache web server software on this system was successful. You may now add content to this directory and replace this page.

    Seeing this instead of the website you expected?

    This page is here because the site administrator has changed the configuration of this web server. Please contact the person responsible for maintaining this server with questions. The Apache Software Foundation, which wrote the web server software this site administrator is using, has nothing to do with maintaining this site and cannot help resolve configuration issues.

    The Apache documentation has been included with this distribution.

    You are free to use the image below on an Apache-powered web server. Thanks for using Apache!

    Gavin

  25. gravatar Flag Justin Halsall
    Nov 14th, 2005 at 3:20 am

    Melvin do you know how to get a DNS server running so that everyone on the network can access that domain?

  26. gravatar Flag David
    Nov 15th, 2005 at 7:15 am

    For the record, I got it working. I had to add a user to my system. For some reason it wasn’t recognizing my current login as a valid user for this purpose.

    Still don’t know why.

  27. gravatar Flag Kurzurlaub Karibik
    Dec 8th, 2005 at 10:23 am

    i googled for something completely different, but found your page… and have to say thanks. i like your site.

  28. gravatar Flag jon
    Dec 16th, 2005 at 9:15 am

    mamp is a development environment, if you look at the site the developers even specidy that it is not recommended for live use. webserverx kit is a one click installer that is better suited.

  29. gravatar Flag Tom
    Dec 28th, 2005 at 11:28 am

    Killer guide, I’m just using your tips for local testing of our upgraded wordpress installation. Cheers!

  30. gravatar Flag cubchai
    Jan 6th, 2006 at 12:42 pm

    When i try to access wordpress.local , an error occurred.
    “The requested URL could not be retrieved

    While trying to retrieve the URL: http://wordpress.local/

    The following error was encountered:

    Unable to determine IP address from host name for wordpress.local

    The dnsserver returned:

    Name Error: The domain name does not exist.

    This means that:

    The cache was not able to resolve the hostname presented in the URL.
    Check if the address is correct.

    Your cache administrator is cachemaster.
    Generated Fri, 06 Jan 2006 20:41:29 GMT by lister.herts.ac.uk (squid/2.5.STABLE6) ”
    I am behind a proxy.

  31. gravatar Flag S Kumora
    Jan 22nd, 2006 at 7:32 am

    I am still trying to figure out how to install a blog using b2evolution platform in a subdomain. Where do I copy the files. Can anyone post a comment?

  32. gravatar Flag Russia visa
    Mar 16th, 2006 at 12:05 pm

    We are trying to install wordpress to server, different subdomains under one location - can anyone comment on that?

    Thanks.

  33. gravatar Flag ZhuQing
    Feb 5th, 2007 at 10:14 pm

    Great! Thank you for your info!

  34. gravatar Flag lucio
    Feb 27th, 2007 at 4:00 pm

    melvin,

    i’ve tried to do as per these directions and get the same page as ‘Gavin’ (If you can see this, it means that the installation of the Apache web server software on this system was successful. You may now add content to this directory and replace this page).

    I’ve double and triple checked thigns and they seem to be okay. perhaps my possible problem lies in the ‘wordpress.localhost’ as a sub-domaine name. i have used this exactly. please advise. thanks!

    lucio

  35. gravatar Flag Chris
    Jun 1st, 2007 at 11:35 pm

    Hi Melvin

    I’m in the smae category as Gavin and Lucio - do you know what could be the problem??

    Thanks heaps!

    Chris

  36. gravatar Flag Justin Halsall
    Jun 4th, 2007 at 5:34 am

    Chris, Gavin & Lucio,

    Is it the same thing you get when you go to http://localhost/ ??
    It might be that the only thing that worked was that the hosts file worked,
    but that adding the virtual hosts didn’t work.

    Did you make sure that your apache file looks like the one in the text wrangler image??

  37. gravatar Flag crj
    Sep 6th, 2007 at 11:33 pm

    Melvin,
    I’ve installed the same php and mysql packages as per your tutorial but I am using apache2 server. When it comes to the httpd configure is the setup different to that which you described since the layout of the httpd.conf file is different.

    Thanks,
    CRJ

  38. gravatar Flag emhr
    Dec 3rd, 2007 at 1:37 pm

    Thanks for the sweet tutorial. I’ve had WP up and running on Tiger for a while thanks to you. Any chance you might amend this series for Leopard. I’m having difficulty making this work with the file paths on a clean install of Leopard.

  39. gravatar Flag eric
    Dec 15th, 2007 at 7:04 am

    I have the same problem as Chris, Gavin and Lucio. I think I have everything set up correctly, but when I try the subdomain, I get the apache page in localhost (the weserver folder in library…) There’s an httpd.conf file in etc/apache2. I tried that one, but it didn’t work.

  40. gravatar Flag eric
    Dec 15th, 2007 at 10:56 am

    It’s working now. I had to edit the httpd.conf that’s in the apache2 folder, not the one in the private/etc folder…

    Thanks for the tutorial!

  41. gravatar Flag WordPress on Mac Part 3: Installing WordPress | IDGLabs.COM
    Apr 6th, 2008 at 9:26 am

    [...] the contents of the WordPress folder to the location you specified in the sub-domain. Check out WordPress on Mac Part 2: Sub-Domains if you haven’t read it yet. In our example, we created a sub-domain called [...]

  42. gravatar Flag Emil
    Aug 14th, 2008 at 11:24 am

    I had the same problem as Gavin and Lucio. like Eric I found editing the /Private/etc/apache2/httpd.conf file in the same way as described in the article does the trick.

    Great Article Melvin. Super helpful

Leave a Reply

(not published)


For a personalized fancy icon, sign up at Gravatar.com