WordPress on Mac Part 1: PHP & MySQL

This guide will help you run WordPress (the blog application that runs this website) in your own personal Mac for testing purposes or for backing up your blog. This Tutorial will cover installing PHP and MySQL, setting up local sub-domains and installing WordPress. Why would you want to do this? Well, because you can. Mac OS X is built on Unix which gives us access some very cool things like the Apache server. Local development is great because you can develop even when you don’t have an internet connection like when traveling on a plane.

Wordpress on your Mac


What’s in a name?
If you are unfamiliar with these terms, here’s a quick guide:

PHP: The web programming language WordPress is written in.
Apache: The web server that comes with Mac OS X.
MySQL:
The web database system used by WordPress.

Step 1: Installing PHP

Mac OS X comes with PHP out of the box but we’re going replace it with the most recent version. This will also give us access to some other technologies not supported on the default installation.

Choose a version of PHP based on your operating system and Download it.

Choose a PHP version

Double click the Disk Image that was downloaded.

PHP Disk Image File

From the Mounted Disk, Double Click the Installer Package.

PHP Installer Package

Choose the drive you want to install PHP in and install it. You need Administrator’s rights to perform this action.

Installing PHP

Go to the Finder’s top menu and select Apple > System Preferences. Under Internet and Network, select Sharing. Under the Services Tab start Web Sharing by selecting Personal Web Sharing and clicking the Start button.

Web Sharing

That’s it, PHP is installed! You can unmount the Mounted Disc from the Finder’s Sidebar and delete the Disk Image File.

Step 2: Installing MySQL

Go to the MySQL website and choose the Standard installer package based on your operating system. Download the file. Once downloaded, double click the DIsk Image.

MySQL Disk Image

From the newly mounted disk, double click the Installer Package.

MySQL Disc Contents

Select a hard drive to install MySQL in and run the installer.

MySQL Installing

Once finished, go back to the content of the Mounted Disk and double click the MySQL to run the Installer.

MySQL Startup Item

Once finished, go back to the content of the Mounted Disk and double click the PrefPane to install the Preference Pane.

MySQL Pref Pane Installer

From the MySQL Preference Pane click on Start MySQL Server and select the Automatically Start MySQL Server on Startup option.

MySQL Preference Pane

That’s it, MySQL is installed! You can unmount the Mounted Disc from the Finder’s Sidebar and delete the Disk Image File.

I got PHP and MySQL running, now what?

Point your browser to “http://localhost” without quotation marks. This should point you to your computer’s server located in your computer at /Library/WebServer/Documents. You can also do “http://localhost/~yourshortusername” to view your personal web site located in the Sites folder of your Home Directory.

Security: If you are concerned about anyone in your local network having access to your MySQL Database, password protect the root(master) user of MySQL by entering this in the Terminal Application “/usr/local/mysql/bin/mysqladmin -u root password new_password_here”.

On my next post, I’ll cover how to do local sub-domains and how to run WordPress Locally. In the meantime, you can check out PHPMyAdmin, a php script to manage MySQL databases if you want to play with both PHP and MySQL together. Your server address is “localhost” and your username is “root”.