I’ve recently started working on a website project using WordPress. I’ve got a production environment where I run this blog on my ubuntu server (VPS) hosted by slicehost. But because I’m going to muck around with themes and plugins I decided that I’m better off doing that locally on my Mac. So this is the first of a series of blog posts for getting WordPress up and running on my local machine.
I have macports already installed and I prefer its packages over the packages shipped with OSX. Mostly because they are more up to date and there is more variety. Plus it feels more native to working with my VPS. Before we get started, lets ensure that our MacPorts is up to date:
---> Updating the ports tree
---> Updating MacPorts base sources using rsync
MacPorts base version 1.8.1 installed,
MacPorts base version 1.8.1 downloaded.
---> MacPorts base is already the latest version
There will be four parts to this series:
- Installing MySQL
- Installing Apache2
- Installing PHP along with MySQL support
- Installing WordPress
I like to chunk these up rather than merge them all into one article as the temptation is to mix information together and then its harder to see where one step stops and the next one starts. Also it means that you can look at the entries in isolation and they should still make sense.
Installing MySQL
I had a binary distribution of MySQL on machine which I needed to remove before installing the macports distro, this thread was useful as it isn’t particularly clear what to do:
http://forums.mysql.com/read.php?11,75256,255851#msg-255851
The following article was my main source of inspiration, I’ve pretty much followed these steps:
http://2tbsp.com/content/install_and_configure_mysql_5_macports
Install the port and setup the mysql system database
$ sudo -u mysql mysql_install_db5
Setup some handy aliases in your shell
alias mysqlstop='/opt/local/bin/mysqladmin5 -u root -p shutdown'
Start the server and set the root password
$ /opt/local/lib/mysql5/bin/mysqladmin -u root password 'root'
$ /opt/local/lib/mysql5/bin/mysqladmin -u root -p -h localhost password 'root'
(Not sure what this second step is for!)
Now we can use the
alias because the password has been set.
And we’re all done!
Installing Apache2
Source of inspiration for this entry is from here:
http://2tbsp.com/content/install_apache_2_and_php_5_macports
Enabled virtual hosts in main config
Include conf/extra/httpd-vhosts.conf
Updated virtual hosts config
The directory part is important as Apache 2.2 directories are by default not browsable so ensure that you enable them!
ServerAdmin webmaster@myapp.local
DocumentRoot "/Users/tgmcclen/workspace/myapp/htdocs/site"
ServerName myapp.local
ServerAlias www.myapp.local
ErrorLog "/Users/tgmcclen/workspace/myapp/logs/error_log"
CustomLog "/Users/tgmcclen/workspace/myapp/logs/access_log" common
<Directory "/Users/tgmcclen/workspace/myapp/htdocs/site">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Setup an alias for controlling apache and start
$ apache2ctl start
Add an entry in the hosts file for the virtual host
Now place files in the
directory and browse to them in a browser:
http://myapp.local/hello.html
Installing PHP along with MySQL support
...
Note: php5 installs files outside the common directory structure.
---> Installing php5 @5.3.0_3+apache2+darwin_10+macosx+mysql5+pear+sqlite
---> Activating php5 @5.3.0_3+apache2+darwin_10+macosx+mysql5+pear+sqlite
To customize php, copy
/opt/local/etc/php5/php.ini-development (if this is a development server) or
/opt/local/etc/php5/php.ini-production (if this is a production server) to
/opt/local/etc/php5/php.ini and then make changes.
$ sudo cp /opt/local/etc/php5/php.ini-development /opt/local/etc/php5/php.ini
Now enable PHP module with apache2
$ sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
and add directives for
and
in the virtual host entry:
ServerAdmin webmaster@myapp.local
DocumentRoot "/Users/tgmcclen/workspace/myapp/htdocs"
ServerName myapp.local
ServerAlias www.myapp.local
ErrorLog "/Users/tgmcclen/workspace/myapp/logs/error_log"
CustomLog "/Users/tgmcclen/workspace/myapp/logs/access_log" common
<Directory "/Users/tgmcclen/workspace/myapp/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<IfModule mime_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</VirtualHost>
And then restart Apache to get going…
Installing MySQL support for PHP
---> Computing dependencies for php5-mysql
---> Fetching php5-mysql
---> Verifying checksum(s) for php5-mysql
---> Extracting php5-mysql
---> Configuring php5-mysql
---> Building php5-mysql
---> Staging php5-mysql into destroot
---> Installing php5-mysql @5.3.0_0+mysqlnd
To use mysqlnd with a local MySQL server, edit /opt/local/etc/php5/php.ini and set
mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket
to /opt/local/var/run/mysql5/mysqld.sock
---> Activating php5-mysql @5.3.0_0+mysqlnd
---> Cleaning php5-mysql
$ sudo mate /opt/local/etc/php5/php.ini
; MySQL defaults.
; http://php.net/pdo_mysql.default-socket
pdo_mysql.default_socket=/opt/local/var/run/mysql5/mysqld.sock
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
; http://php.net/mysql.default-socket
mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
; http://php.net/mysqli.default-socket
mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock
Installing WordPress
Inspiration for instructions from here:
http://codex.wordpress.org/Installing/Updating_WordPress_with_Subversion
http://codex.wordpress.org/Installing_WordPress
Inside your
directory:
(Latest tag will in URL on page, otherwise just browse to tags dir in folder to determine)
Create the database in MySQL
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.40 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE DATABASE mydb;
Query OK, 1 row affected (0.05 sec)
mysql> GRANT ALL PRIVILEGES ON myname.* TO "mydb"@"localhost" IDENTIFIED BY "mypassword";
Query OK, 0 rows affected (0.58 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> EXIT
Bye
Now setup configuration
/** The name of the database for WordPress */
define('DB_NAME', 'mydb');
/** MySQL database username */
define('DB_USER', 'myname');
/** MySQL database password */
define('DB_PASSWORD', 'mypassword');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
Open a browser and continue the install:
http://myapp.local/wp-admin/install.php
You’ll most likely notice that you’re getting lots of errors and warnings on the pages, these can be turned off:
; Development Value: On
; Production Value: Off
; http://php.net/display-errors
display_errors = Off
Now you’re good to WordPress away!



Very nice! I searched for info on Macports Apache/PHP/MySQL installation/configuration last night and found a ton of blog posts from the last 4 years with varying level of detail.
When I searched for “php.ini pdo_mysql.default-socket settings” I found yours, which sums everything I slogged through last night into a nice package. Now I just need to see if following your process can help me get it working.
Thanks!
when i execute sudo port install apache2 it is giving error like Computing dependencies for apache2Error: Unable to execute port: invalid command name “supported_archs”.how can i resolve this.
I had similar problems when I upgraded from Leopard to Snow Leopard. In the end I gave up on MacPorts and moved over to Homebrew. I’d suggest checking it out:
http://mxcl.github.com/homebrew/