Install Apache, PHP and MySQL on Leopard with MacPorts

Running selfupdate on MacPorts is a good way to keep your MacPorts software up to date. The problem is when I did this, all my settings were overwritten. I should also mention that running selfupdate on my MacPorts install caused all my virtual hosts to get overwritten as well. I wrote a post last year on how to install Apache and PHP on Mac OS 10.5 with MacPorts, but following that post didn’t help me get up and running again. So I figured I would write a new one that would actually have the right information.

Here are the install instructions you need for installing Apache, PHP and MySQL with MacPorts. I had already installed Apache and PHP, but MySQL wasn’t working. I have MySQL server already installed and running, but PHP wasn’t finding it. I already had multiple databases set up, so I did not want to reinstall MySQL. All I had to do was follow the instructions in step 4. It fixed the problem, but there were a couple of settings that needed to be changed first.

After you install PHP, it gives you a 2 part message. Part 1,

Your php.ini contains a line that will prevent php5-mysql
and other PHP extensions from working. To fix this,
edit /opt/local/etc/php5/php.ini and delete this line:

extension_dir = "./"

is correct. Deleting that line is how you find the right extensions. Part 2,

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

did not work for me. For my MySQL server, that socket does not work. Instead, I found this article that tells you the correct socket on Leopard to set:

mysql.default_socket = /private/tmp/mysql.sock

That fixed everything for me, except for my virtual hosts. Again, your mileage may very. These instructions worked for me on my machine with the software I have.