Activating PHP and MySQL on Mac OS 10.6-10.8: A Step-by-Step Guide

Dec 08, 2025 · Programming · 9 views · 7.8

Keywords: Mac OS | PHP activation | MySQL installation | Apache configuration | local development environment

Abstract: This article provides a comprehensive guide to activating PHP and MySQL on Mac OS 10.6 (Snow Leopard), 10.7 (Lion), and 10.8 (Mountain Lion). By leveraging built-in Apache and PHP modules alongside the official MySQL installer, it offers a solution without third-party integrated environments like MAMP. Covering configuration file modifications, MySQL installation, service startup, and addressing common issues such as MySQL socket path configuration, it is designed for developers comfortable with command-line operations.

System Environment and Prerequisites

Mac OS X versions 10.6 through 10.8 include built-in Apache web server and PHP modules, forming the foundation for local development environments. This guide assumes familiarity with Terminal command-line operations and a preference for using native system components over third-party tools. This approach offers configuration closer to production environments while avoiding additional software dependencies.

Enabling the PHP Module

First, activate the PHP5 module in Apache. Open the Apache configuration file using a text editor (e.g., TextMate, TextWrangler, vi, or nano):

/etc/apache2/httpd.conf

Locate the following line in the configuration file:

#LoadModule php5_module libexec/apache2/libphp5.so

Remove the comment symbol # at the beginning to enable the module. The modified line should read:

LoadModule php5_module libexec/apache2/libphp5.so

This step allows Apache to parse PHP script files.

Installing and Configuring MySQL

While PHP modules are built-in, MySQL requires separate installation. Download the latest version for Mac OS X from the official MySQL website. Select based on processor architecture:

During installation, select all components. After installation, start the MySQL service via the MySQL panel in System Preferences. Ensure the service status shows as running.

Enabling Web Services

In the Sharing panel of System Preferences, enable Web Sharing. If Web Sharing is already enabled, it is recommended to disable and re-enable it to ensure configuration changes take effect. At this point, the Apache server will start automatically, working in conjunction with the PHP module and MySQL service.

Verification and Testing

Create a test file <code>info.php</code> in the web root directory (typically <code>/Library/WebServer/Documents/</code>) with the following content:

<?php
phpinfo();
?>

Access <code>http://localhost/info.php</code> via a web browser. This should display the PHP configuration information page, including the status of the MySQL module.

Common Issues and Additional Notes

In earlier Mac OS versions (10.4-10.5), manual configuration of the <code>php.ini</code> file was required to specify the MySQL socket path. Although version 10.6 claimed to fix this issue, some users may still encounter connection errors. If MySQL connection problems arise, check the following configurations in <code>/etc/php.ini</code> or <code>/etc/php.ini.default</code>:

mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

Ensure the path matches the actual MySQL socket file location. Use the MySQL command-line tool <code>mysql_config --socket</code> to query the current socket path.

Advanced Configuration Recommendations

For users requiring custom PHP extensions or adjustments to Apache virtual hosts, further edits to relevant configuration files are possible:

After modifications, restart the Apache service: <code>sudo apachectl restart</code>.

Conclusion

By combining built-in system components with the official MySQL installer, a PHP+MySQL development environment can be quickly established on Mac OS 10.6-10.8. This method maintains system simplicity while providing full LAMP stack functionality. Key steps include enabling the PHP module, installing MySQL, and configuring service interoperability. Advanced users can further customize configurations to meet specific development needs.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.