Help needed with messed up PHP setup on MAC

Hi there,

I am desperately searching for a nice IDE for PHP allowing me to debug. Therefore I am currently evaluating PHPStorm. As soon as I have manged to get the setup running, I will buy a license.

Basically, I have a html file with jsvascript embedded. This js calls the PHP files within the same project. I would of course like to debug both js and PHP but I would be very happy if at least the IDE would stop at the breakpoint in the PHP as soon as I am calling the PHP script.

As I tried several IDEs before, my MAC seems to be messed up. I therefore need some help.

I have MAMP running with PHP 5.5.3 on port 8888. The files I am copying into its htdocs folder are successfully executed. Calling phpinfo() in one of these pages returns the PHP info page with the following settings:

PHP Version 5.5.3

Configure Command './configure' '--with-mysql=/Applications/MAMP/Library' '--with-apxs2=/Applications/MAMP/Library/bin/apxs' '--with-gd' '--with-jpeg-dir=/Applications/MAMP/Library' '--with-png-dir=/Applications/MAMP/Library' '--with-zlib' '--with-freetype-dir=/Applications/MAMP/Library' '--prefix=/Applications/MAMP/bin/php/php5.5.3' '--exec-prefix=/Applications/MAMP/bin/php/php5.5.3' '--sysconfdir=/Applications/MAMP/bin/php/php5.5.3/conf' '--with-config-file-path=/Applications/MAMP/bin/php/php5.5.3/conf' '--enable-ftp' '--enable-gd-native-ttf' '--with-bz2=/usr' '--with-ldap' '--with-mysqli=/Applications/MAMP/Library/bin/mysql_config' '--with-t1lib=/Applications/MAMP/Library' '--enable-mbstring=all' '--with-curl=/Applications/MAMP/Library' '--enable-sockets' '--enable-bcmath' '--with-imap=shared,/Applications/MAMP/Library/lib/imap-2007f' '--enable-soap' '--with-kerberos' '--enable-calendar' '--with-pgsql=shared,/Applications/MAMP/Library/pg' '--enable-exif' '--with-libxml-dir=/Applications/MAMP/Library' '--with-gettext=shared,/Applications/MAMP/Library' '--with-xsl=/Applications/MAMP/Library' '--with-pdo-mysql=shared,/Applications/MAMP/Library' '--with-pdo-pgsql=shared,/Applications/MAMP/Library/pg' '--with-mcrypt=shared,/Applications/MAMP/Library' '--with-openssl' '--enable-zip' '--with-iconv=/Applications/MAMP/Library' '--enable-opcache'
Server API Apache 2.0 Handler
Virtual Directory Support disabled
Configuration File (php.ini) Path /Applications/MAMP/bin/php/php5.5.3/conf
Loaded Configuration File /Applications/MAMP/bin/php/php5.5.3/conf/php.ini


The php.ini file mentioned (at /Applications/MAMP/bin/php/php5.5.3/conf/php.ini) states the following:

; Directory in which the loadable extensions (modules) reside.

extension_dir = "/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/"

[OPcache]

zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"

  opcache.memory_consumption=128

  opcache.interned_strings_buffer=8

  opcache.max_accelerated_files=4000

  opcache.revalidate_freq=60

  opcache.fast_shutdown=1

  opcache.enable_cli=1

[xdebug]

zend_extension="/Applications/MAMP/bin/php/php5.5.3/bin/xdebug.so"

The file xdebug.so can be found at this location but I don't know how to test if its the right version.

In PHPStorm, I have set the PHP version to 5.5 (language level) and the interpreter to 5.5.3 in the preferences and the PHP home points to "/Applications/MAMP/bin/php/php5.5.3/bin". The PHP version is recognized and the debugger as well - it states "Xdebug 2.2.3 - komodo".

Clicking on the info button next to this, the PHP info is displayed:


PHP version: 5.5.3


Loaded extensions:
bcmath, bz2, calendar, Core, ctype, curl,        date, dom, ereg, exif, fileinfo, filter, ftp, gd, gettext, hash, iconv,        imap, json, ldap, libxml, mbstring, mcrypt, mysql, mysqli, openssl,        pcre, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix,        Reflection, session, SimpleXML, soap, sockets, SPL, sqlite3, standard,        tokenizer, xdebug, xml, xmlreader, xmlwriter, xsl, yaz, Zend OPcache,        zip, zlib

Nothing else is specified on the dialog.

In  the IDE, I am able to set a breakpoint in the PHP script and I have created a debug configuration:

Section: JavaScript Debug
URL: /Applications/MAMP/htdocs/MobileTool/index.html
Browser: Chrome

When I start this debugging configuration, Chrome is started, telling that "JetBrains IDE support is debugging this tab" and pointing to "file:///Applications/MAMP/htdocs/MobileTool/index.html" but it keeps waiting for localhost.

Please assist!

Thanks

7 comments
Comment actions Permalink

Hi there,

1. So .. whch debug does not work: JavaScript or PHP?It's not clear (for me, at least) at all.

2. Also -- screenshots please (lots of them):
     1) your Run/Debug configuration that you are using;
     2) that "waiting for localhost" message;
     3) Places where you are placing breakpoints

Before going to PHP debug I need a prove that JavaScript debug works (since you want to debug both).


P.S.
Big advice -- instead of trying to debug your real project (especially since you do have problems to make it work) ... try to debug some very simple (2-3 simple files) brand new project (5-10 lines of code per file will do the job just fine).

0
Comment actions Permalink

Hi Andriy,

I did as you requested and created a new empty project with one single html file:

<!DOCTYPE html>
<html><head>
    <meta http-equiv='X-UA-Compatible' content='IE=edge' />
    <title>Hello World</title>

    <script id='sap-ui-bootstrap'
            src='resources/sap-ui-core.js'
            data-sap-ui-theme='sap_bluecrystal'
            data-sap-ui-libs='sap.ui.commons'></script>

    <script>
        var btn = new sap.ui.commons.Button({
            text:'Press me!',
            press: function() {
                $.ajax({ url: 'service.php',
                    data: {action: 'test'},
                    type: 'post',
                    success: function(output) {
                        alert(output);
                    }
                });
            }
        });
        btn.placeAt('content');
    </script>

</head>
<body class='sapUiBody'>
<div id='content'></div>
</body>
</html>

The php is also very simple:

<?php
/**
* Created by PhpStorm.
* Date: 06/03/14
* Time: 14:11
*/

echo "Works!";

?>

When I am putting a breakpoint at line with the alert in the js part, the dubugger stops perfectly. But at the second breakpoint, which is one the line with the echo in the php, it does not stop.

The debug config looks like this:

Snip20140306_3.png

Debugging js is not that important to me as I could do that in the browser, but I would like to get the debugging for PHP.

0
Comment actions Permalink
When I am putting a breakpoint at line with the alert in the js part, the dubugger stops perfectly. But at the second breakpoint, which is one the line with the echo in the php, it does not stop.

Well ... have you configured IDE for PHP debug?
What is your xdebug settings (from php.ini as well as xdebug part from output of phpinfo(); )?

If all what you have done is configured IDE for debugging JS... then it will obviously not work for PHP as it is a bit different thing.


Check these links -- it will give you enough info to do PHP debugging:


For such combined JS+PHP debug the best option (IMO) would be xdebug.remote_autostart=1 in php.ini + "phone handle" icon (as described in zero-config debug article) -- this will tell xdebug to attempt to debug every single PHP script automatically so no external trigger is required (bookmarklet/browser extension/cookie etc). I have tested such approach in the past with 2 test projects (AngularJS+PHP as well as jQuery+PHP) and it worked just fine (still have them as part of the big TestIDE test project).

P.S.
Before doing JS+PHP debug -- make sure that you can debug PHP.

0
Comment actions Permalink

Hi Andriy,

I followed this guide but it seems as if the PHP config is medded up. When I call "php --version" in folder "/Applications/MAMP/bin/php/php5.5.3/bin", it says:

ls /Applications/MAMP/bin/php/php5.5.3/bin
php --version

Failed loading /usr/lib/php/extensions/no-debugno-debug-non-zts-20100525/xdebug.so:  dlopen(/usr/lib/php/extensions/no-debugno-debug-non-zts-20100525/xdebug.so, 9): image not found

PHP 5.4.24 (cli) (built: Jan 19 2014 21:32:15)

Copyright (c) 1997-2013 The PHP Group

Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

Please recognize the typo extensions/no-debugno-debug-non-zts-20100...

But when I call the command with the folder in front, it works:

/Applications/MAMP/bin/php/php5.5.3/bin/php --version

PHP 5.5.3 (cli) (built: Sep 18 2013 14:31:13)

Copyright (c) 1997-2013 The PHP Group

Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies

    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies

    with Xdebug v2.2.3-komodo, Copyright (c) 2002-2013, by Derick Rethans

The PHP version differ, too. When I call phpinfo via http://localhost:8888/MAMP/?language=English, PHP 5.5.3 is correctly displayed and it also says something about xdebug:

http://www.zend.com/

This program makes use of the Zend Scripting Language Engine:

Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies

    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies

    with Xdebug v2.2.3-komodo, Copyright (c) 2002-2013, by Derick Rethans

???

0
Comment actions Permalink

1) Since you are debugging web project, you will be using your MAMP, which, based on the info, works fine. This is important as this is the one that will be used together with PhpStorm. The path to php.ini is "/Applications/MAMP/bin/php/php5.5.3/conf/php.ini"

2) The one from command line -- you seems to have more than one version of PHP installed on your Mac (system wide and MAMP one) and the one from /usr/bin folder (or whatever the proper path is on Mac -- not a Mac user here) is used here. I think "which php" command (or very similar) should give you some info.

P.S.
Check this out -- should be useful -- 5 Step Tutorial: PHPStorm + MAMP PRO 2

P.P.S.
Not 100% sure, but quite likely you will need to restart Apache after making changes to php.ini (it all depends how PHP is run by Apache)

0
Comment actions Permalink

I'd like to suggest you to use Vagrant to configure proper independent (production-like) environment for PHP.

0
Comment actions Permalink

Don't ask me why and how but after days of fiddling, the debugger finally stops at the php breakpoints. Maybe the installation of PHPUnit did the trick, I am not sure.

Thanks to anyone who tried to assist me!

0

Please sign in to leave a comment.