- Mac OS X 10.6 Snow Leopard/10.7 Mountain Lion
- MAMP 2.2
- Ruby - rvm
- Aptana Studio 3.4.2
- [Dropbox for manual sync between two computers (e.g. desktop & laptop)]
- I develop/maintain a number of applications in Ruby and PHP, and I prefer to use the same tool for both languages.
- Install MAMP. Start it, open start page to verify it works.
for Mac OS X
Create a PHP project
- Create a project on Aptana with your PHP application.
- I typically use File->Import-> Existing Folder as New Project
- Let's assume you use the folder /Users/myuser/Workspace/PHPProject
- If you haven't created a Mercurial repository, you can do it now from the terminal:
cd /Users/myuser/Workspace/PHPProject/ hg initOpen the project on Aptana (right click) and you should see:
- For this example let's create a public/ folder and a index.php file in it with the following content:
<?php header("Content-Type: text/plain"); echo "Hi, I'm your newborn PHP project";
- Add a virtual host in apache. Edit /Applications/MAMP/conf/apache/httpd.conf
& uncomment the line:
# Virtual host Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
- Edit /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
- We will use the first sample entry, dummy-host.example.com
- Change the DocumentRoot directive to point to the public folder of this project.
- Also change port 80 to 8888
NameVirtualHost *:8888 <VirtualHost *:8888> ServerAdmin email@example.com DocumentRoot "/Users/myuser/Workspace/PHPProject/" ServerName dummy-host.example.com ServerAlias www.dummy-host.example.com ErrorLog "logs/dummy-host.example.com-error_log" CustomLog "logs/dummy-host.example.com-access_log" common </VirtualHost>
- Add dummy-host.example.com to
127.0.0.1 dummy-host.example.com localhost
- Verify it works
$ ping dummy-host.example.com PING dummy-host.example.com (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.063 ms 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.022 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.112 ms ^C
- On MAMP stop & start servers
- point your browser to http://dummy-host.example.com:8888/
- It should show:
Hi, I'm your newborn PHP project
This is our first version of this application. We commit it to the Mercurial repository: Right click, Team, Commit...
- Uncomment at the end of the php.ini (see its location in the
phpInfo page), plus add the line below to enable "remote"
[xdebug] zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so" xdebug.remote_enable = On
- Restart MAMP, refresh phpInfo page and verify that now an xdebug section appears.
- Window -> Open Perspective -> Debug
- Bug Icon, Debug preferences, New_configuration
- Set PHP server:
- Set the starting PHP script index.php, unset "Auto
Generate" and empty the field at right
Now we can set a breakpoint, and debug again; execution should stop at the breakpoint (browser window waiting) and should finish by pressing F5.