Getting WordPress up and running on Mac OS X Lion


This post briefly describes the steps necessary for setting up WordPress on Mac OS X Lion.

I know I’m quite low on detail here, please leave a comment if You’d like me to clarify anything.

  1. Download MySQL from mysql.org (choose the latest .dmg-package, for me it was “Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive” even though I’m on Mac OS X 10.7)
  2. Install MySQL as well as the MySQL preferences thing which comes with it (both are installed by double-clicking the .dmg-image—thereby mounting it—and double-clicking the files therein)
  3. Start MySQL via “System Preferences”→”MySQL” (click “Start MySQL Server”)
  4. Enable PHP in Apache by uncommenting the LoadModule php5 line in /etc/apache2/httpd.conf, at the same time add “index.php” to the DirectoryIndex directive
  5. (Unsure about this one, I don’t remember the default config, but in the Apache config file(s) You might need to allow .htaccess files to override the server settings)
  6. Start/restart the web server via “System Preferences”→”Sharing” (uncheck and recheck the tick box beside “Web Sharing”)
  7. Download WordPress from wordpress.org
  8. To prepare location/Fix permissions for easier development (I’m setting up WordPress in the “Computer Website Folder” – /Library/WebServer/Documents), in Terminal, execute:
    cd /Library/WebServer/Documents
    sudo chown `whoami`:staff .
    mkdir wordpress
  9. Unpack WordPress to the newly created wordpress folder: /Library/WebServer/Documents/wordpress (I don’t want the wordpress files directly in the web root since I later might want to have other stuff there as well, see for instance Giving WordPress Its Own Directory)
  10. In order to have the WordPress site shown on the site root even though its stored in a subfolder, copy the index.php file with the following command:
    cd /Library/WebServer/Documents
    cp wordpress/index.php .

    …and, with your favorite text editor, change the line “require(‘./wp-blog-header.php’);” to “require(‘./wordpress/wp-blog-header.php’);”.

  11. To create a configuration file from the sample one, execute:
    cd /Library/WebServer/Documents/wordpress/
    cp wp-config-sample.php wp-config.php
  12. I want a tidier database than what WordPress by default creates, hence I disable multiple revisions of articles by adding the following code in the top part of the wp-config.php file:
    define('WP_POST_REVISIONS', false);

    …as well as adjusted the database parameters* (DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET) and the authentication keys and salts.

    * Default MySQL user is “root” with empty password, this is however NOT recommended—you should have a separate database user.

  13. In Safari, opened http://localhost/, performed the WordPress install process and thereafter logged in to the dashboard via http://localhost/wordpress/wp-admin/
  14. In the WordPress Dashboard: Move the only comment to the trash, and empty the trash
  15. In Terminal (this creates the upload directory, where images and such are stored, and creates a .htaccess file which You soon will fill with content):
    cd /Library/WebServer/Documents
    mkdir wordpress/wp-content/uploads
    chmod 0777  wordpress/wp-content/uploads
    touch .htaccess

    However, please note it might be unwise to use chmod 0777 on a production server, here’s why.

  16. In Dashboard: Settings->Permalink settings: “/blog/%postname%-%post_id%/” (without the quotes) and click Save Changes. Copy the text which WordPress says you need to have in your .htaccess file.
  17. Using your favorite text editor, paste the text into the /Library/WebServer/Documents/.htaccess, after which the file might look like:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
  18. I also installed the FancyBox for WordPress plugin by unzipping it into /Library/WebServer/Documents/wordpress/wp-content/plugins and activating it via the Dashboard “Plugins” page.
  19. I missed having the right sidebar in single article pages, so I downloaded and installed the Twenty Eleven Child with Sidebar Support 1.1 by Chris Aprea theme.
  20. Modify the functions.php file in the theme to prevent some SPAM comments/trackbacks, add:
    // prevents some spamming from bots which direct address the posting target
    function verify_comment_referer() {
        if (!wp_get_referer()) {
            wp_die( __('You cannot post comment at this time, 
    may be you need to enable referrers in your browser.') );
        }
    }
    add_action('check_comment_flood', 'verify_comment_referer');

    Read more at Spare 10 Seconds To Avoid Spam Comments Entering Your WordPress.

  21. Done. Be sure to test out your site.

Later on you might want to move the WordPress site to a public web server, due to the way WordPress sets links etcetera this will require some modifications to the database (in addition to copying it from your local machine to the one used by your web hosting account) according to How to Move WordPress Blog to New Domain or Location.

Useful plugins for the public site:

,