For a while, I've been wanting to install wordpress on Mac OS X, so that when I modify themes I can do this offline for testing. I also want to have the theme modifications automatically upload to the servers and to mirror the site database on my local copy. The information how to do this is 'out there' - but I thought it would be good to collect it all in one place. Much of this could be adapted for other platforms such as windows or Unix. Pick and mix what you need, this is what I've done.
As always with this sort of thing, it's your own responsibility if you mess up - understand each command before you type it. If in doubt, type man command, e.g. man rf )
Local WordPress Install
All of the above isn't essential - but I liked it. My next task was to install WordPress. I did try this with MySQL directly, but got to the end and found I couldn't get a connection to the database - this is some relatively small error, but I couldn't fix it, so I used 'MAMP' instead.
MAMP stands for Mac, Apache, MySQL and PHP - it can be obtained here. It's a big download, so I'll assume that you're going to have a wait - and I'll move on to something else. When the .dmg has downloaded, drag MAMP to the applications folder and it will install.
I prepped WordPress using 'subversion'. I opened a terminal, and typed the following:
[sourcecode language="bash"] cd ~/Sites mkdir wptrunk cd wptrunk svn co http://core.svn.wordpress.org/trunk/ . [/sourcecode]
(that last . matters)
This downloads the latest WordPress - which might be unstable.
I wanted to use the stable version, so I typed
[sourcecode language="bash"] cd ~/Sites mkdir wpstable cd wpstable svn co http://core.svn.wordpress.org/tags/2.9.1 . [/sourcecode]
(Note, 2.9.1 is not the most up to date as you read this - WordPress itself will tell you that when you log in).
To update to a new version, type
[sourcecode language="bash"] svn sw http://core.svn.wordpress.org/tags/2.9.2/ . [/sourcecode]
Obviously, replacing 2.9.2 with the latest version number.
I now had two WordPress versions, wptrunk and wpstable. For simplicity, I'll assume only 'wpstable' is used.
As subversion was used, to update the wordpress files, just open terminal, go to the directory and type
[sourcecode language="bash"] svn up [/sourcecode]
(you can use the wordpress updater, but a later use of subversion may revert you to an earlier copy)
You may want to add your own files, which'll clutter you up when typing 'svn status'. For example, I made a file called 'UPGRADEREADME' containing the instructions in svn sw given above.
To ignore this file, I typed
[sourcecode language="bash"] svn propset svn:ignore UPGRADEREADME . [/sourcecode]
WordPress was ready, and by now MAMP had downloaded and installed.
I ran MAMP and started the servers. Then I went to the MAMP start page, in safari: http://localhost:8888/MAMP/?language=English. This showed me it was working.
In the MAMP window (not on the webpage), I clicked 'preferences' - this allowed me to change the php version, I didn't. The WordPress files can all be placed in /Applications/MAMP/htdocs - but that's a little out-of-the-way, and I'd already put them in ~/Sites. It's better to have user files in the user hierarchy. Therefore I prefered to use a symbolic link.
[sourcecode language="bash"] cd /Applications/MAMP/htdocs ln -s /Users/USERNAME/Sites/wpstable wpstable [/sourcecode]
This creates a symbolic link in htdocs, so for all intents and purposes, it behaves like a copy of ~/Sites/wpstable - but you've actually only got one copy of those files (it's not a backup!)
Now, in MAMP's web interface, I went to phpmyadmin and typed a name for the database - I used utf8_unicode_ci as the collation. MAMP adds a default user automatically, the info is on the MAMP webpage.
In my terminal window I typed
[sourcecode language="bash"] cd /Applications/MAMP/htdocs/wpstable cp wp-config-sample.php wp-config.php [/sourcecode]
then I edited wp-config.php to change database name and user login info (MAMP's SQL user is root/root - that's okay as it's not public-facing). As I want to have a stable and trunk installation, I edited the wordpress table prefix. Also, I followed the instructions in wp-config regarding authentication keys.
My new site was at http://localhost:8888/wpstable/. I went through the WordPress setup and had a working local installation of wordpress.
I got thematic by typing
[sourcecode language="bash"] cd ~/Sites/wpstable/wp-content/themes svn checkout http://thematic.googlecode.com/svn/trunk/ thematic [/sourcecode]
This is a subversion repository inside a subversion repository, but it seems to be playing well, so I'm not going to worry about it.
Grabbing the database
The next thing was to write a script to grab the database. I want to write a script to automatically grab the database, change it so that the internal links etc. are appropriate for the mirror (i.e. internally consistent) as well as change the table names. I haven't worked all that out - so I used the conventional WordPress export and then imported to me local mirror (the main purpose is for testing my child themes, so it's not critical).
I then made a child theme in wp-content/themes, copying the sample child theme from the thematic folder. I started editing. This process is beyond the scope of this article.
The result isn't yet ready to be applied to this site, but when I do, I shall write a script to upload the files for me using scp or rsync, so that I can change and then update the site with a single command.
My child theme is actually managed in a subversion repository, but that's detail....