Apache/PHP/MySQL on Snow Leopard

php apache mysql on mac

Apache/PHP and MySQL are usually know as LAMP (Linux, Apache, MySQL, PHP). But on this page we will cover the SAMP (Snow Leopard, Apache, MySQL, PHP). In this tutorial you will learn how we can configure Apache/PHP/MySQL on Snow Leopard.

Apache and PHP by default installed in Snow Leopard so we don’t need to install these tools again. We only need to install MySQL. Now let’s install MySQL

Installing MySQL

  • Download the MySQL package for Mac OS (32 or 64 bits depending on your hardware)
  • After the downloading of MySQL package just double click on .dmg file a new window will be open in that window you will find mysql package, mysql startup_item package and MySQL_prefPane. You have have to install all of these packages one by one.
  • Start MySQL in the preference pane.
  • Test it’s working:
/usr/local/mysql/bin/mysql 

Configuring PHP

Create /etc/php.ini from php.ini.default

cd /etc
sudo cp php.ini.default php.ini

Edit php.ini, first of all we need to set our time zone so just locate ;date.timezone then set the time zone according to your locality e.g.

date.timezone =Asia/Karachi

Fix mysql socket location php easily communicate with mysql

  • You only need to replace the two occurrences of /var/mysql/mysql.sock by /tmp/mysql.sock
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

Configuring Apache

We need to enable php5_module in httpd.conf file so in /etc/apache2/httpd.conf, uncomment this line:

LoadModule php5_module        libexec/apache2/libphp5.so

After that just restart Apache

sudo apachectl start

That’s all everything is configured. Simply create index.php file in /Library/WebServer/Documents/ to check php is working and mysql modules is appear with its correct socket.

sudo vi /Library/WebServer/Documents/index.php

Just call the phpinfo() function in that file. PHPinfo command will show you your PHP version, path, and a alot of other information regarding system’s path, list of compiled extensions.

< ?php
phpinfo();
?>

Just save and exit from file and then check it form your browser e.g.

Check it’s working: http://localhost/index.php

Leave a Reply

Your email address will not be published. Required fields are marked *

*