I just got a Mac with OS X (10.6.8). What options do I have to do serious PHP developement, including a debugger?
I don't ask about what IDE to use. I'm not sure what is the best way to get PHP including XDebug (or any other professional debugger) working. I heard that the Mac comes with Apache and PHP preinstalled. Where can I find any documentation about this. Should I just add MySql and work with this? Or should I go for MAMP or XAMPP. What would be the benefit of this installs over the built in?
I found a lot of descriptions about how to compile XDebug from scratch. Non of them worked for me. Isn't there an easier way of getting a debugger working for OS X?
I'm also ready to upgrade the Mac to the latest OS X, if this is of any help.
In the age of virtualization
vagrant box full of ubuntu and zend CE server
zend studio for ide and zend debugger works out of the box
you can config it to use x-debug just apt-get it
this way you'll keep your os-x clean and have all the necessary stuff inside a portable/deployable virtual machine that runs on background or can be launched from any machine you might be using today or tomorrow
After a lot more googling and try and error I found a very nice and easy to install solution which works great for me:
Installed MacGDBp.
Installed MAMP.
Opened the php.ini at /Applications/MAMP/bin/php/php5.3.6/conf/php.ini and uncommented the only line containing the xdebug.so file.
Added this lines at the end of php.ini
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
After restarting apache MacGDBp stoped at the first PHP line.
Done!
I use my MacBook Pro for PHP development every day, including XDebug. I've set it up both on Snow Leopard and on Lion. It's been a while, but does this link help you?
http://maestric.com/doc/mac/apache_php_mysql_snow_leopard
For XDebug, what problems are you experiencing? I also wrote this guide on my blog for two simple ways of installing PHP extensions on a Mac: http://software.curtisfarnham.com/2011/10/30/how-to-install-php-extensions-in-mac-os-x-lion/
Related
I'm having a very hard time getting a breakpoint to hit in some php code. I don't do much php so might be newbie error.
I've read though the other questions, PDT Install Instructions, and XDebug Install Instructions
For both debuggers, the instructions expect a config section to show up in the phpinfo() and it doesn't for me.
Some info about my current setup
Windows
AMPPS
PHP 5.2.17
Website runs fine
I need some help with things to check or ideas what I might need to do differently.
I'm stuck pretty much for now.
You can follow this post to install Xdebug for PHP in AMPPS.
Two main things that fixed my issues.
Turned off Iron PHP Loader
copied the non-ts XDebug .dll, even though the php config shows thread safe = enabled. This dll seems to work
The config settings are below for reference:
;Stuff to allow debugging in eclipse
zend_extension="C:\Program Files (x86)\Ampps\php\ext\php_xdebug-2.2.3-5.3-vc9.dll"
xdebug.remote_enable=On
xdebug.remote_autostart=On
xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_mode=req
You do have to make sure and add the extra xdebug configurations or eclipse won't cooperate.
I have a MacBook Pro with OS X 10.8.3 factory installed. I want to set up a working Apache/PHP environment on my local machine. Is this a matter of activating/changing settings in Terminal or do I need to install something?
There have been other guides out there but they don't explicitly answer how to begin if I have a factory installed OS and not an upgrade from an earlier version.
Thanks for any help.
If I'm not mistaken, all you have to do is edit the httpd.conf (/etc/apache2/httpd.conf) file to load the php module into apache (Look for 'LoadModule php5_module', it will probably be there, but with a # at the beginning of the line, simply remove it) and then start apache by entering this in terminal: apachectl start (you will maybe need to put 'sudo' before)
Of course this will only run apache and php. After that you can change your documentRoot and all the settings you want
I found a guide that'll walk someone through getting the factory installed Apache and PHP working on OS X 10.8. It goes over getting MySQL installed too:
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion
I'm having problems with XDebug.
Configuration as follows:
Windows 7 64bit
PHP 5.4.6 Thread Safe 32 bit
Apache 2.4 Thread Safe
Eclipse PDT 3.0.2
The problem is that xdebug_break() calls are not working, and breakpoints entered through Eclipse also don't function. I can see that the extension is working, as it appears as a module in phpinfo(). When I call an uncallable method, XDebug outputs the relevant error messages.
I've modified Eclipse's web server path mapping, to no avail.
Here is my php.ini config:
zend_extension = c:/php/php_xdebug-2.2.1-5.4-vc9.dll
xdebug.remote_enable = 1
xdebug.remote_host = localhost
xdebug.remote_port = 8080
xdebug.remote_mode = req
Any help would be kindly appreciated...
First check that what version you are using of PHP in eclipse....
Check it through:
Window->preference->PHP->PHP Interpreter....
Version there should match with the PHP version.....
Reply if problem is not solved....
For all those, that are still fighting with this problem, some handy tips.
Check which version (package) of Eclipse you have? It turns out, that Helios package has some bugs and doesn't stops on breakpoints, when you debug your application as Web Application. Debugging works only, if you run it as PHP Script. Which makes it pretty useless for debugging process.
You should consider either reverting to older Galileo Package Eclipse for PHP Developers or installing newest Eclipse Juno (or even newest developer version of Eclipse Kepler), which doesn't have PDT support build in, but you can easily add it to then, using Help > Install New Software.. (point it to http://download.eclipse.org/tools/pdt/updates/release).
These versions are reported to be able to debug as Web Application, respecting breakpoints.
Also, remember, that Xdebug must be run as Zend Extension in order to support breakpoints! In other words remove extension=xdebug.so (on Linux or xdebug.dll on Windows) line from your php.ini and replace it with zend_extension=/full/path/to/xdebug.so (on Linux or zend_extension=X:\full\path\to\xdebug.dll on Windows). Zend extensions requires full path, even if they're put into /php/ext folder, as regular PHP extensions. You'll find more info on this in Xdebug FAQ (look for an answer to "Xdebug is only loaded as PHP extension and not as a Zend Extension" question).
I've seen these answers: debugging php on mac?
but I am hoping that there is a better/newer solution. I am a system-level developer (C/C++/x86) but totally new to the web/scripting space. I feel that I would do well do setup a solid debugging environment - it is usually a great way for me to learn.
Any suggestions/pointers as to a good php debugging setup on a Mac (10.6) would be much appreciated.
Thanks,
Matt
I'm a Mac user myself and since I do some heavy PHP development, I need an elaborate setup for this.
First of all, the standard PHP and Apache installed in Snow Leopard isn't bad, but upgrading or adding extensions to it is quite a task. To be able to fully control the environment, I decided to install the entire AMP stack using MacPorts. Don't worry about overwriting existing files, as everything will be installed in separate locations. Just make sure you disable the stock Apache before starting the newly installed one. There are loads of tutorials on how to get this done.
My IDE of choice is Komodo IDE. This IDE comes out of the box with integrated debugging using a preconfigured xdebug setup. I have ended up compiling and using the latest xdebug version instead of the stock version for compatibility reasons (PHP 5.3+). Many developers use the aforementioned Eclipse + PDT which offers a similar IDE, although slightly more has to be done to get it configured properly.
For remote debugging I have configured the PHP module in apache to load xdebug also and connect to my running IDE. More info about that can be found here. For complex web applications it is ideal if you can just open the browser, navigate to the correct webpage and activate debugging to step into the first line of code of that page.
For performance testing and tuning I use the profiling feature of xdebug. When enabled, xdebug will write callgrind files to a specific directory. I use MacCallGrind to visually analyse the profiler files. There is a free alternative called KCacheGrind which can be installed if you enabled MacPorts (as mentioned in the first suggestion).
I use this environment to develop pretty complex and large multi-homed projects, involving commandline (daemonized) PHP applications that utilize forking and IPC structures and extensions like memcache. I'm quite satisfied with how this setup works for me.
There is a way how to do it using:
PhpStorm
Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Php + Xdebug
1) Install php and debug
brew install php70
brew install php70-xdebug
In PhpStorm - check Preferences => Language and Frameworks => PHP
Php language level: 7
Interpreter: PHP 7.0.8 + XDebug (or choose from [...])
Check debug config:
Preferences => Language and Frameworks => PHP => Debug => Xdebug section
All checkboxes should be checked and set Debug port to: 9001
2) run server in your app's directory:
php -S localhost:8080
3) Add localhost:8080 to PhpStorm Preferences => Language and Frameworks => PHP => Servers:
Name: Localhost:8080
Host: localhost
Port: 8080
Debugger: Xdebug
4) Update php.ini:
Php => Interpreter => […] => Configuration file - Open in Editor
Add this section: (check zend_extention path through the cli)
[Xdebug]
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9001 (same as in Debug preferences)
5) Add Debug Configuration:
Run => Edit Configuration => add - Php Web Application
Choose Localhost:8080 server
6) Click Start Listening for Php Debug Connections
7) Set up breakpoints
7) Click on Debug (Green bug)
I'd also be interested in a better solution but I doubt there is one.
xdebug with a frontend like NetBeans, Eclipse or MacGDBp is probably where the bets go.
was wondering what was the best way to debug PHP on my local machine. I use MAMP on mac os 10.5
thanks,
Patrick
Using xdebug is a good start. Download the package and follow the instructions in the INSTALL file. It's fairly easy. Once this is done, add the following lines to your php.ini file:
;;[xdebug]
zend_extension="/Path/to/your/module/xdebug.so"
xdebug.file_link_format="txmt://open?url=file://%f&line=%1"
xdebug.var_display_max_depth = 20
Don't forget to restart Apache after this.
Most debugging can be done using a simple die(var_dump($some_variable)). It's not very sophisticated, but with xdebug installed, the output of a vardump looks pretty good in a browser. In most of the cases this is enough.
If you need more control, you can add an xdebug_break(); statement in your code and add the following lines to your php.ini:
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
Again, don't forget to restart Apache.
Now, using a tool like MacGDBp (or Eclipse+PDT if you must), you get a classic debugger. You can step though your program.
Have fun!
I've always thought the "best" way of PHP debugging on any platform is by using FirePHP, which can output debug messages straight into the Firebug window in Firefox.
I've found that running php -l myfile.php is great at catching syntax errors before I try and reload the page in my browser (and thus prevent the abominable White Screen of Death). Beyond that, I just point my browser to my local webserver and try to access the pages.
You can do some nifty things in your code itself (like using debug_backtrace()), but that (obviously) requires you to put it in the code yourself.
Personally, I use Eclipse+PDT and XDebug. To simplify things, get Eclipse for PHP Developers from the Eclipse download page rather than installing PDT as a plugin. Eclipse has a high learning curve, but it gives you all the debugger functionality you expect: instruction stepping, breakpoints, watches, even altering variables live.
If you don't like Eclipse or find it's too much for you, there are other clients compatible with XDebug.
I also use eclipse+pdt and xdebug. If you're new to trying out debuggers you can try zend studio which will setup things pretty easily.
Zend Studio is by far the best tool to use to create and debug PHP code. I run the community Edition of Zend Server on my dev Linux box and locally in a virtual machine on my MacBook Pro.
Take a look at the Zend website for details - it has cut my app development by two thirds!
Thanks to a bunch of links like this one and others, here's a compiled solutions that successfully uses OSX's native Apache2 and XDebug together with MacGDBp and a Safari extension called XDebug Helper.
You can do it even without MAMP.
There is a way how to do it using:
PhpStorm
Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Php + Xdebug
1) Install php and debug
brew install php70
brew install php70-xdebug
In PhpStorm - check Preferences => Language and Frameworks => PHP
Php language level: 7
Interpreter: PHP 7.0.8 + XDebug (or choose from [...])
Check debug config:
Preferences => Language and Frameworks => PHP => Debug => Xdebug section
All checkboxes should be checked and set Debug port to: 9001
2) run server in your app's directory:
php -S localhost:8080
3) Add localhost:8080 to PhpStorm Preferences => Language and Frameworks => PHP => Servers:
Name: Localhost:8080
Host: localhost
Port: 8080
Debugger: Xdebug
4) Update php.ini:
Php => Interpreter => […] => Configuration file - Open in Editor
Add this section: (check zend_extention path through the cli)
[Xdebug]
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9001 (same as in Debug preferences)
5) Add Debug Configuration:
Run => Edit Configuration => add - Php Web Application
Choose Localhost:8080 server
6) Click Start Listening for Php Debug Connections
7) Set up breakpoints
7) Click on Debug (Green bug)