The software platform which markwilson.it runs on is in desperate need of an updated but there is only me to make it happen (supported by ascomi) and if I make a mistake then it may take some time for me to get the site back online (time which I don’t have!). As a result, I really needed a development version of the site to work with.
I thought that it would also be handy if that development version of the site would run offline – i.e. if it were served from a web server on one of my computers. I could run Windows, IIS (or Apache), MySQL and PHP but as the live site runs on CentOS, Apache, MySQL and PHP it makes sense to at least use something similar and my Mac fits the bill nicely, as a default installation of OS X already includes Apache and PHP.
I should note that there are alternative stacks available for running a web server on a Mac (MAMP and XAMPP are examples); however my machine is not a full web server serving hundreds of users, it’s a development workstation serving one user, so the built in tools should be fine. The rest of this post explains what I did to get WordPress 2.7 up and running on OS X 10.5.5.
- Open the System Preferences and select the Sharing pane, then enable Web Access.
- Test access by browsing to the default Apache website at
http://computername/
and a personal site athttp://computername/~username/
. - Download the latest version of MySQL Community Server (I used mysql-5.1.31-osx10.5-x86_64) and run the corresponding packaged installer (for me that was
mysql-5.1.31-osx10.5-x86_64.pkg
). - After the MySQL installation is completed, copy MySQL.PreferencePane to /Library/PreferencePanes and verify that it is visible in System Preferences (in the Other group).
- Launch the MySQL preference pane and start MySQL Server (if prompted by the firewall to allow mysqld to allow incoming connections, allow this). Optionally, select automatic startup for MySQL.
- Optionally, add
/usr/local/mysql/bin
to the path (I didn’t do this, as creating a .profile file containingexport PATH="$PATH:/usr/local/mysql/bin"
seemed to mess up my path somehow – it just means that I need to specify the full path when running mysql commands) and test access to MySQL by running/usr/local/mysql/bin/mysql
. - Enable PHP by editing /etc/apache2/httpd.conf (e.g. by running
sudo nano /etc/apache2/httpd.conf
) to remove the#
in front ofLoadModule php5_module libexec/apache2/libphp5.so
. - Test the PHP configuration by creating a text file named phpinfo.php containing
<?php phpinfo(); ?>
and browse tohttp://localhost/~username/phpinfo
. - With Mac OS X, Apache, MySQL and PHP enabled, start to work on the configuration by by running
/usr/local/mysql/bin/mysql
and entering the following commands to secure MySQL:
drop database test;
delete from mysql.user where user = '';
flush privileges;
set password for root@localhost = password('{newrootpassword}');
set password for root@127.0.0.1 = password('{newrootpassword}');
set password for 'root'@'{hostname}.local' = password('{newrootpassword}');
quit - Test access to MySQL. using the new password with
/usr/local/mysql/bin/mysql -u root -p
and entering newrootpassword when prompted. - Whilst still logged in to MySQL, enter the following commands to create a database for WordPress and grant permissions (I’m not convinced that all of these commands are required and I do not know what foo is!):
create database wpdatabasename;
grant all privileges on wpdatabasename.* to wpuser@localhost identified by 'foo';
set password for wpuser@localhost = old_password('wppassword');
quit - Download the latest version of WordPress and extract it to ~username/Sites/ (i chose to put my copy in a subfolder called blog, as it is on the live site).
- Configure WordPress to use the database created earlier by copying wordpressdirectory/wp_config_sample.php to wordpressdirectorywp_config.php and editing the following lines:
define('DB_NAME', 'wpdatabasename');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'wppassword');
define('DB_HOST', 'localhost:/tmp/mysql.sock'); - Restart Apache using
sudo apachectl restart
. - If WordPress is running in it’s own subdirectory, copy wordpressdirectory/index.php and wordpressdirectory/.htaccess to ~/Sites/ and then edit index.php so that WordPress can locate it’s environment and templates (
require('./wordpressdirectory/wp-blog-header.php');
). - Browse to
http://localhost/~username/wordpressdirectory/wp-admin/install.php
and follow the “five minute WordPress installation process”. - After installation, the dashboard for the new WordPress site should be available at
http://localhost/~username/wordpressdirectory/wp-admin/
. - The site may be accessed at
http://localhost/~username/wordpressdirectory/
.
Credits
I found the following articles extremely useful whilst I was researching this post:
- Leopard: How to Install WordPress (TechRecipes).
- Installing MySQL on Mac OS X (MySQL Documentation).
- WordPress OS X Install Tips (Dave Warker).
- How to edit httpd.conf on MacOS (Anuj Gakhar).
One thought on “Installing WordPress on a Mac”