Showing posts with label MAMP. Show all posts
Showing posts with label MAMP. Show all posts

Friday, February 25, 2011

Integrating MAMP PHP and Eclipse PDT for CakePHP Debugging

There are a few steps necessary to get Eclipse PDT, MAMP, and a CakePHP app synchronized for debugging. Summarily, after adding the Zend Debugger to Eclipse, the php initialization file in MAMP must be modified so it can respond to Eclipse. MAMP is not pre-configured for use with Zend Debugger, so you must edit the php.ini file for MAMP. Find the location of this file in the phpinfo tab of MAMP (near the bottom in the screenshot):

Open this in a text editor such as vim, and you will find this info near the bottom (italicized configuration info added at this step):

[xdebug]
;zend_extension="/Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

[Zend]
zend_extension="/Applications/MAMP/Library/modules/zend/ZendDebugger.so"
zend_debugger.allow_hosts=127.0.0.1
; zend_debugger.expose_remotely=always


Now that you have detailed the location of ZendDebugger.so, you need to actually add a copy of the file in that location. Go ahead and put a copy of ZendDebugger.co (which either you have already downloaded into your Eclipse plugin filesystem, or you can download it as part of the Zend Debugger package ) into this directory. Incidentally, ZendDebugger.co can be where ever you like, so long as the path in php.ini resolves to it.

Comment out any references to zend in php.ini, other than the ones in italics above. In addition, comment out xdebug references if they are not already commented out.

Finally, restart MAMP and look for this confirmation in your restarted phpinfo():


If debugging in Eclipse succeeds, the debugger will halt at the first instruction. Be sure to step through a few instructions (F5) to ensure it is working properly. Here is a thoughtful and concise external resource to follow as a further guideline.

Incidentally, CakePHP:


As stated above, this guide will help you get debugging to work with CakePHP. That part of the process entails a further step. Once you are in Eclipse debugging a CakePHP project, you may find the debugger prompts you to resolve the location of core php files as it steps through them. This will happen, for instance, when you debug CakePHP apps you have created by using the cake bake CLI prompt.

To resolve these prompts, simply make sure the following conditions are met:
  1. Your CakePHP app is in a project folder in Eclipse ( it has to be! )
  2. Your CakePHP core library is in a project folder in Eclipse. This way, the files are available to the IDE so Eclipse can step through them in a debug process.
This is a unique requirement of CakePHP. Since you are building from an external core library and debugging involves the core, it has to be in the IDE.

Thursday, February 17, 2011

CakePHP Cake Bake is Awesome

After taking CakePHP's Cake Bake CLI for a spin, I find myself exclaiming aloud:
This is good cake.
Following loads of exploration in IDEs and PHP MVC options, I have CakePHP running on Eclipse, served by MAMP Apache and MySQL, and debug enabled by PDT. Incidentally, this how-to on CakePHP/Eclipse integration from power-user rynop is invaulable.

View along with me as I run through a friendly interactive prompt called Cake Bake from within the Eclipse console. This will summarily build out the underpinnings of my entire site structure - model, view and controller - along with push-button validation (!!):


Note: working CakePHP install in Eclipse. Menu is Run > External Tools > Cake bake


Says the interactive shell script:


---------------------------------------------------------------
Interactive Bake Shell
---------------------------------------------------------------
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
What would you like to Bake? (D/M/V/C/P/F/T/Q)


I can has cake - so simple!


Select validation options from the list


Look okay? *nods and pops open a beer*

So good! I will detail further on this. Gotta drink my beer now...

Wednesday, February 16, 2011

Zend Debugger for PDT

If you are attempting to debug in PHP, PDT is your answer. Listed in Software Updates as the Zend Debugger Feature, it can be plugged into your Eclipse build via the following address:

http://downloads.zend.com/pdt

It's free and it works seamlessly in conjunction with MAMP. When you run it, debug dialog is displayed in the panels in the Eclipse IDE. Objects can be halted via breakpoints for inspection.

Something else that is not free but I'm evaluating in response to upward trending: JetBrains PHPStorm IDE. On initial inspection, seems to offer the same web tools as Eclipse offers.

As a potential mid-weight candidate between TextMate and Eclipse, it could bust the whole thing wide open. After all, informative and easy's all I'm asking for, doesn't matter who provides it. Open source development is fine, but it tends to force platform specialization on the end user. I don't mind paying to avoid that.

Sunday, November 29, 2009

MAMP with mod_wsgi

Once you get a database set up, sqlite or otherwise, you can use it with Django applications. You can serve Django directly from a command line or through Apache. In either case you will need Django to be installed. From a command line, simply run the django server and browse to it:

django-admin.py runserver

If your production server is going to be Apache, your best bet is to run Django under Apache locally. To do this you need a helper library for Apache to use. The de facto solution is mod_wsgi.

mod_wsgi

To get started with mod_wsgi, typically you download mod_wsgi from Graham Dumpleton's Google Code repository, you go to your command line, you untar it, you configure it, you make it and you make install it. This makes the code library available to wsgi-enabled services, in effect allowing you to run Django on Apache.

When you make install mod_wsgi, it places the libraries in your /lib directory. Then it links to your Apache directory where OSX keeps it, /usr/libexec/apache2. Installation includes automatic detection, or you can use some optional flags to specify resource paths, detailed in the wsgi installation guidelines.

Now your OSX Apache has modwsgi installed, but the Apache version in MAMP does not. To verify this, try making a Django app and serving it via MAMP. First, make a new django app in an appropriate directory:

django-admin.py startproject myproject

Next, open and modify the config for your MAMP Apache app, located in /Applications/Mamp/conf/apache/httpd.conf. For that matter, have a look at what your OSX Apache instance has in its config file. It is private/etc/apache2/httpd.conf. Searching for wsgi in this file yields:

LoadModule wsgi_module libexec/apache2/mod_wsgi.so

Looks good even if the relative directory location may be an issue. Insert this info into the MAMP httpd.conf and test it. Actually, there is no need because it will not work. This is due to the structure of MAMP and its proprietary use of Apache. Unlike a full install of Apache, the folders in MAMP have a different structure and are optimized to run modularly. Consequently, you cannot append a flag to your configure command in this manner:

./configure --with-apxs=/usr/sbin/apxs2-worker

because the structure available to Apache is not in MAMP, so detection will fail.

This leaves a couple of options. Either reconstruct some of the MAMP Apache folders so detection will succeed or look for another solution. Considering the evident lack of general success from many Google searches, I am letting this fish off the hook. Feel free to leave a comment if you know a way to make it work.

As a final consideration, mod_python appears to be a lot quicker to set up with MAMP. That could be a candidate if you are in a pinch. Otherwise, if serving Python via Apache is your goal, I recommend using the resources included with OS X and skipping MAMP altogether.

MAMP with sqlite

If you want a local enviro to test in, MAMP for Mac is a good way to go. Right out of the box, you get Apache, MySQL, SQLite and PHP support. Also in the mix is python 2.5, which ship with OS X.

With several apps at the ready, how do you get your head around the new environment? Piece by piece. First let's look at SQLite.

SQLite

Have a good read at some typical command line options to get you up and running. Go ahead and try it out. See if you can create a db, add some values, retrieve the values.

When you store a database, it is stored in the current directory. You can see what that is by using the command pwd, aka print working directory. Further documentation is available on the SQLite site. If you decide command line is not your style, one option is the SQLite Manager for Firefox. It's not for remote db admin but it'll do for local scenarios.

In summary, getting up and running with sqlite is simple. MAMP comes with MySQL, so that is another available option.