How to Install WordPress on Mac OS X (Leopard)

July 8, 2009 · 13 comments

in How To

How to start and stop the Apache HTTP Server

  1. Go to: System Preferences -> Sharing
  2. To start the server, select Web Sharing. To stop the server, unselect it.

Install MySQL

  1. Download MySQL for Mac OS X. For my computer, I used the package format for Mac OS X 10.5 (x86).
  2. Verify package integrity using MD5 checksums or GnuPG.
  3. Follow the instructions for installing MySQL on Mac OS X. I recommend installing both the MySQL Startup Item and preference pane as well. These will make it possible to have MySQL start automatically during system startup and enable you to start and stop the MySQL server with a click of a button.
  4. Post-installation setup and testing.

Enable PHP

Mac OS X comes with the Apache HTTP Server and PHP installed. The PHP module needs to be enabled.

Find the location of httpd.conf, the main configuration file for the Apache HTTP Server, using the command, httpd -V.

Note: The $ at the beginning of the lines in the following examples is the command prompt.

$ httpd -V | grep SERVER_CONFIG_FILE
-D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

Beware. Proceed only if you know what you are doing. I expect that you have the technical ability of a software developer familiar with Unix.

Edit the httpd.conf file using root access with the sudo command and your favorite text editor. I use vi.

$ sudo vi /private/etc/apache2/httpd.conf

Uncomment the line:

# LoadModule php5_module

Save the file and exit.

Start the HTTP server and test that PHP is running by creating a file in your Web directory containing a call to the function phpinfo().

File: /Users/<username>/Sites/test.php

<?php phpinfo(); ?>

Navigate to the URL, http://localhost/~username/test.php .

Change MySQL socket

If you were to try to install WordPress now, you would probably run into this error:

Error establishing database connection

This error occurs because the PHP build that comes installed on Mac OS X (Leopard) is configured to look for the MySQL socket at /var/mysql/mysql.sock. In the current release of MySQL, the default socket is at /tmp/mysql.sock. Here is how to fix this.

Find the PHP configuration file path from the call to phpinfo() from earlier. It is probably /etc and this location is probably a symbolic link to /private/etc.

Create a php.ini file if it doesn’t already exist by copying the default configuration file, php.ini.default, using root access with the sudo command. Give the root user write permission on the file.

$ cd /private/etc
$ sudo cp php.ini.default php.ini
$ sudo chmod +w php.ini

In php.ini, edit the two lines for the parameters mysql.default_socket and mysqli.default_socket to be:

mysql.default_socket = /tmp/mysql.sock

mysqli.default_socket = /tmp/mysql.sock

Save the file and exit.

Enable .htaccess

If you want to use pretty permalinks in WordPress, you need to enable .htaccess. Otherwise you will see this error:

404 Not Found: The requested URL <URL> was not found on this server.

Edit the Apache configuration file to allow override. If you are using your Sites Web directory:

$ sudo vi /private/etc/apache2/users/<username>.conf

Find AllowOverride and change its value from None to All.

AllowOverride All

Save the file and exit.

Start Apache HTTP Server

Now that you have enabled PHP and .htaccess, restart the HTTP server.

Download and extract WordPress

Download and extract WordPress. To have WordPress automatically configure wp-config.php, before you proceed with Step #3 of the WordPress installation instructions, set the file permissions as follows.

Set file permissions

On Mac OS X (Leopard), the Apache HTTP Server runs under the user account, _www which belongs to the group _www. To allow WordPress to configure wp-config.php during installation, update files during upgrades, and update the .htaccess file for pretty permalinks, give the server write permission on the files.  I do not know if there are any security issues with this.  If you are more knowledgeable than I am on this matter, please chime in!

Updated February 17, 2010. My preferred way to do this is to change the group of the wordpress directory and its contents to _www and give write permissions to the group. Keep the owner as your <username>.

$ cd /Users/<username>/Sites
$ sudo chown -R <username>:_www wordpress
$ sudo chmod -R g+w wordpress

However, when I tried this, it did not work for automatic upgrades to newer versions of WordPress although it worked for automatically updating the .htaccess file for pretty permalinks.  End of update.

Another way to do this is to change the user of the wordpress directory and its contents to _www.  Keep the group as staff, a group to which your user account belongs and give write permissions to the group.

$ cd /Users/<username>/Sites
$ sudo chown -R _www wordpress
$ sudo chmod -R g+w wordpress

With both of these methods, the WordPress directories have a permission level of 775 and files have a permission level of 664. No file nor directory is world-writeable.

For reference, the Apache configuration file, httpd.conf, contains entries for the User and Group which the server will run as. The default setting is www for both.

For reference, on Mac OS X (Leopard), the user account information is located in the file:


This file shows that the _www and www name map to the same user account.

Install WordPress

Now resume the steps for installing WordPress. If you did not change the file permissions, you will need to edit the wp-config.php file yourself instead of having WordPress create it automatically.

Follow Symbolic Links

In some Apache server configurations, mod_rewrite requires FollowSymLinks to be enabled. Otherwise you might see this error:

403 Forbidden: You don’t have permission to access <URL> on this server.

Add this line to the top of your .htaccess file:

Options +FollowSymlinks

All done!



Please let me know if you find any errors or have anything to add.

{ 4 trackbacks }

{ 9 comments… read them below or add one }

scragz January 14, 2011 at 7:19 pm

If you are doing a local install and want to be able to update plugins more easily, you can:

`sudo chown -R :_www wordpress`

And the add the following to wp-config.php

define(‘FS_METHOD’, ‘direct’);

The routine it uses for deciding if it can use the direct method relies on owners, but you can be fine doing the permissions part with groups and telling WP it’s going to be okay.


Ted Dively October 4, 2010 at 2:22 pm

Just curious…Do you see any security drawback(s) by making Apache the owner of the WP directory and all its subfolders and files?


dancer October 8, 2010 at 7:34 pm

Thanks for your question. This was actually I question I had myself. I am going to update my post with this question.

If anyone is more knowledgeable about this, please chime in!


Robin September 15, 2010 at 7:20 am

I was struggling with my .htaccess file – add “Options +FollowSymlinks” to the top of the .htaccess file solved it – thank you! 🙂


staticnullvoid February 19, 2010 at 12:33 am

nice article, cheers.


JB November 15, 2009 at 6:37 pm

Thanks, I needed that .htaccess bit 🙂


Steffen September 4, 2009 at 2:17 am

Thanks for sharing… 🙂


z3cko August 16, 2009 at 6:08 am

$ sudo -R chmod g+w wordpress

should be changed to

$ sudo chmod -R g+w wordpress

nice article! thanks!


dancer August 24, 2009 at 11:10 pm

Thanks for letting me know about the mistake. That was probably the one line I didn’t test before writing it in the article.


Leave a Comment

Previous post:

Next post: