Per Søderlind

I code for fun

Running WordPress locally on Mac OS X Lion, Mountain Lion and Mavericks

Apple and WordPressWant to run WordPress on OSX? I’ve wanted to do it for a long time and finally got a round to do it.

Multisite: See notes below if you plan to run a Network of WordPress (aka multisite) on your Mac.

New: Here’s an alternative, take a look at WordPress on Pow (includes a “how-to add MySQL, PHP5.4.9 and Ruby 1.9.3“)


Update: Mountain Lion and Mavericks

Web Sharing in Mountain Lion is removed from System Preferences->Sharing (no idea why), so to start the web server, open Terminal (or iTerm) and enter:
 

apachectl main commands are: start, stop and restart. You can learn more about apachectl by entering the following in Terminal

apachectl is sufficient when you need to start, restart or stop the server while testing, but if you want the web server to start automatically after a reboot, you’ll have to enable the launch daemon for the server:

Create /var/mysql/mysql.sock if it doesn’t exist (or replace /var/mysql/mysql.sock with /tmp/mysql.sock further below)

Also, If you followed the instructions below earlier and upgraded your Lion to Mountain Lion, you’ll have to reenable PHP:

How I installed MAMP + WordPress

1 ) Installed Apache, MySQL and PHP on my Mac. I followed this excellent guide: OS X 10.7 Lion Development: Native MAMP with MySQL installer. Here’s the /Users/<username>/Sites/httpd-vhosts.conf I made:

2) Installed WordPress in /Users/<username>/Sites/wordpress

When I tried to install the first plugin, I got the dreaded FTP Connection Information required :/

Luckily, Google to the rescue, I found this fix to allow WordPress automatic plugin installation/update:

A) Changed the owner and permissions for the entire WordPress installation, assuming you installed WordPress in /Users/<username>/Sites:

B) Added the following to /Users/<username>/Sites/wordpress/wp-config.php:


How to create a WordPress multisite locally

1) Follow the instructions above, and create a separate database per multisite

Easiest is to create a path-based (that is use sub-directories) multisite. My multisite virtual host looks like this:

2) When WordPress is up and running, follow steps 2 – 6 in the Create a Network guide.

If you have any questions, please don’t hesitate to ask below. I’ll try to answer as soon as possible.

Previous

Upgraded to WordPress 3.2 and nothing worked (internal error …)

Next

Front-end editor in WordPress 3.3 is easy

30 Comments

  1. bananaaus

    You legend!

  2. Jarratt

    Hello,
    I’m just setting up a local installation of WordPress on my Mac with OSX Lion. I’ve managed to install it but I can’t update any plugins, import my blog etc (I’m new to all this so flying blind so to speak).

    I have read something about changing my FTP permissions? I don’t really understand what the article above is saying, could you please give some further info for me?

    Thanks a lot, hopefully you can help!
    Jarratt

    • PerS

      You have to do the following:

      A) Changed the owner and permissions for the entire WordPress installation, assuming you installed WordPress in /Users/<username>/Sites:

      [code lang=”shell” light=”false”]
      $ cd /Users/<username>/Sites
      $ sudo chown -R :_www wordpress
      $ sudo chmod -R g+w wordpress
      [/code]

      B) Added the following to /Users/<username>/Sites/wordpress/wp-config.php:

  3. Jarratt

    Hi again,
    That’s great, all up an running now. Thanks a lot!

  4. Nick

    So I am having a problem with permalinks after setting up my dev environment on OSX Lion. I have AllowOveride All in my httpd.conf and in my vhosts file as you show, mod_rewrite is enabled… Any ideas?

    Thanks!

    • PerS

      Is your .htaccess writeable by wordpress ? Mine looks like this (and permalinks works):

  5. blah blah

    seems like alot of trouble to me,

    i use mamp pro & coda,

    std mamp install and wordpress into a wordpress directory in the sites folder,no need for all that messing around for the same result, oh and everything works like its on a live server, mail,permalinks,updates for wordpress & plugins, .htaccess writeable etc etc

  6. chapman welch

    Thanks for the tip. You saved me a few hours of pain and suffering!

  7. Senica

    Thanks for posting. Was driving me crazy.

  8. This is absolutely awesome! I’ve been having to manually install/update WordPress, my framework, and my plugins. Thanks to this tutorial, this evil hassle has been reduced to a few simple clicks.

  9. PakPenyo

    solution for me is change both user and group:

    sudo chown -R _www:_www wordpress

    thanks.

    • PerS

      That’s fine, as long as you are member of the group _www, otherwise you (as in your user) can’t edit the files.

  10. Yanns

    thank you very much, however there is a question.. should I care for anything when I migrate the local site to public? Should I remove the last like from wp-config.php?

    • PerS

      I use http://ithemes.com/purchase/backupbuddy/ when I migrate a site from localhost to production. It does the necessary changes to wp-config.php

      • Yanns

        yes but do you think making changes to wp-config.php is enough? I haven’t done it before on WP but I think we need to fix other things as well before it go live. Such as links etc..
        maybe my question was silly but ok, I will get the grip of it a day ;)

      • ..and does the backupbuddy take care of the access rights we gave with the commands above? I mean to make them back to normal. I wouldn’t want have any problem with access rights when the website is online..

  11. Yanns

    in my command line (lion) it says:
    -bash: Users//Site/lookup/folders: No such file or directory

    the path is just an example. I tried to find where the path breaks, trying the command $cd in small chunks but there’s again the same issue.
    what should i do?

    • PerS

      You must replace <username> in the examples above with your username.

      • Yeah, I had done that. what I did was to illustrate you the path.

        Finally, the problem was caused by a silly thing I had done: I had put spaces in the filenames so the terminal couldn’t find the folder..

        Another problem was that I wasn’t writing the correct filepath. so I looked it up and I found that you can write the first 1-2 letters of your filename and then press Ctrl+tab (for mac it is the same, ex.Ctrl+tab, and command+tab won’t work). After you do it, the terminal will write the filename for you!..

        Last, another problem was that I was writing ..sudo chown -R:_www wordpress
        My mistake:
        I had to write the parent folder name of the file.. I thought that wordpress was part of the command. So the correct one is:

        sudo chown -R:_www exampleFilename
        (ofcourse same goes for chmod)
        Cheers!

  12. Excellent! Thanks for posting this. I was having a time with this one and this did the trick right away thanks !

  13. Phil

    Installed WP but had probs when uploading media due to permissions problems. Hunted for ages to find a solution. Your site sorted it immediately. Cheers.

  14. PerS

    Adian and Phil,

    Glad I could help. Please tell others using twitter etc.

  15. Hello,
    i have an error during plugin installation. Before folder access denied problem, i have new error message :
    “The package could not be installed. PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature”
    What does it mean ?
    thanks for help

  16. steve

    It should be possible to install plugins locally by only changing the the group to _www for wp-content and adding write permissions to group, then adding the define(‘FS_METHOD’, ‘direct’); line to your wp-config.

  17. Jarod Taylor

    After changing the permissions it rendered my localhost/~username directory 404 Page not found.

  18. Thanks very much :)

Leave a Reply

Powered by WordPress & Theme by Anders Norén