Bundled PHP and MySQL on Mac OS X: A Terminal-First Approach
When setting up a local development environment on Mac OS X versions 10.6 through 10.8, the default system installation often lacks the necessary web server stack. While third-party bundles like MAMP offer an all-in-one package, they introduce unnecessary dependencies if you are comfortable navigating the command line. Furthermore, relying on official downloads from MySQL or PHP.net can be cumbersome due to versioning conflicts and signature verification hurdles that plague older OS versions.
The most pragmatic solution for these legacy operating systems is leveraging the built-in php and mysql binaries provided by Apple's Xcode Command Line Tools. These tools are pre-installed on developer machines or easily installed via the App Store, offering a clean slate without the baggage of bundled applications.
Verifying System Binaries
Before attempting to install anything, you must confirm which versions of PHP and MySQL are already present on your system. Open Terminal and run:
which php
php -v
which mysql
mysql --version
On Snow Leopard (10.6) and Lion (10.7), these binaries often reside in /usr/bin. On Mountain Lion (10.8), they might be located in /usr/local/bin depending on your Xcode installation. If the commands return a version number, you have a starting point. However, these system versions are frequently outdated and may lack modern extensions required for contemporary frameworks like Laravel.
Configuring MySQL for Web Services
The default MySQL configuration is tuned for local administrative use, not web servers. You need to ensure the server is listening on the standard port and that user permissions are correctly set up for remote or local web connections.
First, start the MySQL server:
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
Note: The --skip-grant-tables flag is a security risk in production but acceptable for isolated development environments on older OS versions.
Once the server is running, log in without a password and reset the root user's authentication plugin to the legacy mysql_native_password. This step is crucial because newer PHP versions may refuse to connect if the MySQL root user uses the default caching_sha2_password plugin.
USE mysql;
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
FLUSH PRIVILEGES;
EXIT;
After resetting the password scheme, restart MySQL normally:
sudo /usr/local/mysql/bin/mysql.server start
Integrating PHP with Apache
The system-installed PHP binary does not automatically serve files via Apache. You must enable the PHP module and configure the document root. Edit the Apache configuration file, typically found at /etc/apache2/httpd.conf or within a site-specific config in /private/etc/apache2/.
Add the following line to load the PHP module:
LoadModule php5_module libexec/apache2/libphp5.so
Important: Ensure you are loading libphp5.so. Loading a version-mismatched module (e.g., trying to use a PHP 7 module on an OS with only PHP 5 installed) will crash Apache. Verify the correct library path using:
ls -la /usr/libexec/apache2/
Next, configure the DirectoryIndex directive to include index.php:
DirectoryIndex index.html index.htm index.php
Finally, ensure that your document root points to a writable directory, such as /Library/WebServer/Documents. Create a test file to verify the integration:
sudo nano /Library/WebServer/Documents/info.php
Add the following content and save:
<?php phpinfo(); ?>
Access http://localhost/info.php in your browser. If the detailed PHP information page loads, the stack is functional. If you see a "403 Forbidden" error, check that the _www user has read permissions on the directory.
Trade-offs and Limitations
Using system binaries offers simplicity but comes with constraints. The versions of PHP and MySQL bundled with Xcode Command Line Tools are often several major versions behind current standards. For instance, a machine running Mountain Lion might only support PHP 5.6, which lacks many modern language features and security patches available in later releases.
Additionally, while this method avoids the overhead of MAMP, it does not provide an isolated MySQL data directory. Your database files will reside in /var/mysql, meaning any accidental deletion could impact system integrity if you are not careful. Always back up your data before performing major configuration changes.
If your specific project requirements demand a newer PHP version or a specific MySQL architecture that the system binaries cannot support, moving to Homebrew becomes the next logical step. However, for basic activation on Snow Leopard through Mountain Lion without external dependencies, the Xcode tools provide the most direct path forward.
