Running multiple PHP+MySQL sites locally on Mac OS X 10.6 Snow Leopard

Enabling PHP

1. Goto System Preferences>Sharing.

2. Enable "Web Sharing".

3. Open Terminal.app. Enter "sudo apachectl restart".

4. Navigate to "localhost" in a web browser. You should see the welcome page.

5. To make sure PHP is working, create phpinfo.php in /Users/Sites. *** There is a way to create phpinfo.php in command line, but I forget how to do it. ***

6. Create php.ini. In terminal, type:

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

Virtual Hosts

1. In Terminal, enter "sudo nano /etc/hosts".

2. Look for the line starts with "1127.0.0.1 localhost". Move the cursor to the end, press Tab, add the name of the virtual host. Add as many as you want, save the file by pressing "Control + X". At the last step, nano will ask if you want to change the file name, ignore it and just press "Enter"

3. In Terminal, enter "sudo nano /etc/apache2/users/[USERNAME].conf" where [USERNAME] is your username in OSX. The file should look like this

NameVirtualHost *:80
<Directory "/Users/desmond.liang/Sites/">
Options Indexes MultiViews Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>


<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/desmond.liang/Sites
</VirtualHost>

To add a virtual host, append this code to the file:

<VirtualHost *:80>
ServerName [HOST]
DocumentRoot [PATH]
</VirtualHost>

Where [HOST] is the domain name, [PATH] is the document root. [HOST] should be what you just added to /etc/hosts.

Installing MySQL

If you’re comfortable with installing applications on your Mac and are reasonably familiar with MySQL, installing MySQL on Snow Leopard should be relatively simple.

Download the Mac OSX disk image from the MySQL website:

http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg

I used the mysql-5.1.42-osx10.5-x86_64.dmg disk image, which seems to work fine. The image contains 4 files including a ReadMe file.
Install the following packages found in the disk image to the default location and with the default options:


mysql-5.1.42-osx10.5-x86_64.pkg MySQLStartupItem.pkg

Install the following profile found in the disk image to the default location and with the default options:

MySQL.prefPanel

Start the MySQL service in the System Preferences panel and check the Automatically Start the MySQL Service on Startup option.

That is all you need to do. However, if you’re working with PHP, you will need to correctly reference the mysql.sock file in your php.ini file. To do this, find the following line and ensure the reference is correct:

mysql.default_socket = /tmp/mysql.sock

(Remember to restart Apache if you make changes to your php.ini file.)

You may want to use phpMyadmin to manage your MySQL database. If phpMyAdmin prompts "mcrypt" module is missing, follow the step in "Plgging mcrypt into PHP, on Mac OSX 10.6 Snow Leopard". You can find the article at this url:

http://michaelgracie.com/2009/09/23/plugging-mcrypt-into-php-on-mac-os-x...

blog comments powered by Disqus