Tumblr is where tens of millions of creative people around the world share and follow the things they love.Sign up to find more cool stuff to follow
Debugging CakePHP in Netbeans with MAMP
Setting up remote php debugging in Netbeans with MAMP and CakePHP is actually quite easy.
- Netbeans 7.0.1
- MAMP Pro 2.0.5
- CakePHP 2.0
- Mac OSX Lion
This should work just as well with previous versions of Netbeans and Cake, MAMP configurations may be slightly different.
You’ll need to alter MAMP’s PHP configuration files:
In MAMP go to File->Edit Template->PHP->PHP 5.X.XX (whichever version you’d like to edit)
Scroll to the bottom of the ini file you should see a line like this:
Simply uncomment this line by removing the semicolon:zend_extension=”/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so”
Next you’ll need to add some Netbeans specific parameters:
xdebug.remote_enable = On
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost (or your hostname)
xdebug.remote_port = 9000
Add These right below the zend_extension line above.
Again you’ll need to do this for each version of PHP that you want to debug with.
Save the php files and restart your MAMP servers. Hit http://localhost:8888/MAMP/phpinfo.php in your browser, you should now have an xdebug section toward the end of your info file.
Now for the Netbeans configuration.
Create a cakephp project as you normally would in Netbeans. Once you have the project configured and running (database is set up, tmp directory is writable etc) right click on the project name in the Projects navigator.
Select Properties, then choose Sources. For Web Root choose your cake application’s webroot directory ex: app/webroot.
Then go to Run Configuration. For project url enter the url of your MAMP site, ex: http://localhost:9001. Push the advanced button
That’s it, you should now be able to launch the debugger.
In Netbeans go to Debug->Debug Project(Project Name), a new browser window will pop up. At first it will be blank as the debugger will stop PHP on the first line of index.php. You can then step through your code, or continue to your next break point.
Your mileage may vary, but please let me know if you have any trouble following these instructions or if you know of a better way to do any of this.
Pain staking process
So I just went through a pain staking process of setting up a local MAMP stack on a mac lion machine. And I just wanted to post about two pit falls that I came across.
MAMP 2.0 upgrade MySQL won't start
Upon upgrading to MAMP 2.0 I discovered that MySQL was no longer loading. After much digging around I found a post that describes a harsh fix. Essentially it amounts to shutting down or killing the mysqld process and restarting servers from the MAMP console. The “fix” seems to have worked for me. The instructions below might be a bit clearer for more novice users:
Try the first approach before attempting the second less harsh fix.
Quit the MAMP console. Open the terminal window and type the following commands:
$ cd /Applications/MAMP/bin $ sudo chmod +x *.sh $ ./stopMysql.sh
Then restart MAMP and all should be normal again. If that doesn’t work try this second approach:
This approach involves catting the contents of the mysql.pid file. The PID stands for process ID and represents a number which can be used to identify a process.
$: cat /Applications/MAMP/tmp/mysql/mysql.pid
Use the number that’s returned in a kill command. In my case 35938 was returned.
$: kill -9 35938
i just screwed up the MySQL part of my MAMP installation, trying to install a local copy of Drupal. I tried reinstalling MAMP, it didn’t work. I am at total loss about what to do, I am in no way technically skilled enough to go on the interwebz and google for help, because I am certain that I will not understand anything I read on the matter.
Yesterday I failed at baking. Today I fail at computing. This is clearly not my week.
# cd /Application/MAMP/Library/bin
# ./mysql -uroot -p
MAMP + Intl + Lion
Since I have started using Symfony2 on some projects I have been meaning to install the intl extension that Symfony recommends you install. I have tried several different methods, but believe that the one I listed below is easier and makes less of a mess than others.
First, get the ICU libraries. Then expand them and build the library:
tar xzvf icu4c-4_8_1_1-src.tgz cd icu/source ./runConfigureICU MacOSX make sudo make install
If you have followed from my previous steps, you should have the php headers installed in the standard MAMP directory. We need to go to the intl ext folder:
From here, let’s build the intl.so file that we need to enable the extension:
phpize ./configure --enable-intl make
Now we just need to copy the extension to the correct location and add an entry to our php.ini file:
cp modules/intl.so /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/ echo "extension=intl.so" >> /Applications/MAMP/bin/php/php5.3.6/conf/php.ini
Restart the MAMP servers and now you have the intl extension enabled!
adding virtual hosts in when using MAMP
I use MAMP Pro for my freelance work and its awesome, it takes care of my virtual hosts for me inside of MAMP. MAMP Pro has a slick interface (not the best, but it works) for adding virtual host and the related document root.
Fast forward 10 minutes, my morning commute time, and I’m at my regular 9to5er job where I’m in charge of programming/building and maintaining our exteral website, philanthropic websites, and bunch sites we use for internal use. So I download MAMP and wait a sec, you mean to tell me that the company that I work for that has more money than me wont spend $60 for me on a tool that makes at least one aspect of my job easier?
Fine then, I’ll get the free version, I don’t mind that much (if anyone wants to donate to a good cause, now would be a good time).
When I’m testing sites though, I like to have a clean URL like golf.localhost, not 127.0.0.1/golf/index.php or localhost/golf/index.php, so anyways, I found that it is fairly simple to use virtual hosts with the free version of MAMP.
So I’m assuming you have MAMP installed and ready to go.
- Make sure you set MAMP to use the default ports 80/3306 (apache/mysql)
- open Terminal.app (I’m on a mac remember?)
- type: sudo cp /etc/hosts /etc/hosts.bak
- type: sudo emac /etc/hosts
- using your keyboard, arrow down to the bottom of the file, or last line of the file
- add: 127.0.0.1 myTestSiteName.localhost
- while holding ctrl, press x then s (saves file)
- while holding ctrl (again), press x then c (closes file)
- stop holding breath for two seconds
one more thing to do…
- open httpd.conf in /Applications/MAMP/conf/apache/ (use your favorite text editor)
- at the very bottom of the file add this:
NameVirtualHost * <VirtualHost *> DocumentRoot "/Applications/MAMP/htdocs/testFolder" ServerName myTestSiteName.localhost </VirtualHost>
- save and close httpd.conf
- restart the MAMP servers (stop then start)
Then when you navigate to myTestSiteName.localhost/ in your web browser you have your test site. Sweet! A little more work if you don’t have MAMP Pro, but in the end it works.
MAMP & Memcached
I recently had to work on an app the was going to use Memcache as its caching engine and need to get my local environment up to speed. I use MAMP for my local dev so I had to find a way to marry the two. After about a minute of searching, I happened up the following post which proved extremely helpful.
Check it out if you find yourself in the same boat.