Setting up a native AMP stack
AMP stands for Apache, MySQL, and PHP. Apache and PHP are built into OS X 10.7 and we will walk through the setup and installation of MySQL.
You can verify your native installation of Apache and PHP and obtain the version information with these commands from Terminal.app (/Applications/Utilities/Terminal):
And you’ll see something like this:
PHP 5.3.8 with Suhosin-Patch (cli) (built: Nov 15 2011 15:33:15) Copyright (c) 1997-2011 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies with Zend Debugger v5.2, Copyright (c) 1999-2009, by Zend Technologies
Results in something like this:
Server version: Apache/2.2.21 (Unix) Server built: Nov 15 2011 15:12:57
You can start and stop Apache from System Preferences » Sharing. Just check the box labeled “Web Sharing.”
Or from Terminal you can control the Apache daemon startup, shutdown, and restart, respectively:
sudo apachectl start sudo apachectl stop sudo apachectl graceful
PHP is installed but not enabled. To enable it we run some more commands from Terminal. The sudo command will cause a prompt for your password. You can use whatever text editor you would like, but nano is quick and easy
cd /etc/apache2/ sudo nano httpd.conf
Around line 115 you will find the php5 module and the line is commented out with a hash “#” symbol. Remove the hash to uncomment the line.
Press Ctrl-x and then y to save and exit from nano. Then restart Apache.
sudo apachectl graceful
Point your browser at dev.mysql.com and choose Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive
Upon downloading the .dmg file and opening the disk image, you will see three main installable items. It is very important the order in which you install these items! First install the mysql package file (.pkg), then the MySQLStartupItem.pkg, and finally the MySQL.prefPane. You will find the MySQL preferences now under System Preferences » Other (toward the bottom).
Now we need to add MySQL to the bash shell path.
cd ~ nano .bash_profile
Add this line and press Ctrl-x and y to exit and save:
export PATH="/usr/local/mysql/bin:$PATH" source ~/.bash_profile
To test whether or not this worked try this command again:
mysql -v mysqladmin -u root password '[yourpassword]'
Point your browser to http://localhost/~[your user name] and you should see “It works!”
Download from here: phpMyAdmin. Uncompress and rename the folder to phpMyAdmin, then move it to /Users/[your username]/Sites/
There are some bash (Terminal) commands to run (set up a symbolic link to the Mac OS X 10.7.x location of mysql.sock and set some permissions):
sudo mkdir /var/mysql sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock mkdir ~/Sites/phpMyAdmin/config chmod o+w ~/Sites/phpMyAdmin/config
Navigate to http://localhost/~[your username]/phpmyadmin/setup/. Click on New server, Fill in the authentication tab with your username and password. Click save, and again on the intial screen when it reloads. When upgrading phpMyAdmin in the future, be sure to keep the config.inc.php file from your old installation with your localhost server settings.
Setting up a PHPIDE with debugging capabilities
Download Eclipse for PHP Developers here: Eclipse Helios. You can simply uncompress it and move the folder to /Applications or ~/Applications.
Now to setup debugging, first download and uncompress the Zend Debugger plug-in for Eclipse. It will uncompress to a folder called Eclipse. Inside are two folders, features and plugins. Copy the contents of these folders to your main Eclipse folder in the corresponding folders there. Now, we need the Zend debugger executable, available here: Zend Studio Web Debugger. You’ll want the 64 bit version of “Studio Web Debugger.” Uncompress the gzipped tarball and you should see this folder:
We want the ZendDebugger.so file inside the 53x_comp folder. From Finder, with this folder window open, press Shift-⌘-G and enter /usr/lib/php/extensions/ into the dialog box. Move the ZendDebugger.so file inside /usr/lib/php/extensions/ (Authenticate if necessary). Edit the /etc/php.ini file by adding these lines to the bottom:
[Zend Modules] zend_extension=/usr/lib/php/extensions/ZendDebugger.so zend_debugger.allow_hosts=127.0.0.1/32,192.168.*.*,10.*.*.* zend_debugger.connector_port=10000 zend_debugger.expose_remotely=always
Restart Apache & Verify installation:
sudo apachectl graceful php -m
You should see the following at the bottom:
[Zend Modules] Zend Debugger
The next step is to setup Eclipse to use the debugger. Go to Preferences » PHP. We need to add Mac OS x’s PHP 5.3.8 executable and make it the default.
Next, setup the debugger…
As a last, but purely optional step, I installed the Aptana Studio 2 (not 3) plugin for now, until Aptana Studio 3’s PHP debugger is finished(PHP Debugger). From the Eclipse Help menu select Install New Software, paste this url — http://download.aptana.com/tools/studio/plugin/install/studio — into the Work With field and press return. Follow the prompts to install the Aptana Studio 2 Eclipse plugin for additional PHP coding features.
One last thing, if you want to change the browser from the default system web browser (like Firefox so you can use Firebug), here is what you do — under Preferences » General » Web Browser, add the following. Then be sure to highlight it and set as default when you are done.
Now to debug a php script locally, all you have to do is right click and select Debug As » PHP Web Page. You now have a powerful local test environment and IDE in which to develop PHP projects. Congratulations!