Debugging a Slim Back End with Different Front End

Hi,

I’m new at this forum and hope someone can guide me in the right direction.

I’m building my website with an Angular front end and a Slim 4 back end. I use Rest Api’s to get data or post files to my back end from the Angular built front end. All work fine but I haven’t figured out how to debug my Slim Backend.

Till now I simply use Postman and echo back to debug but do not want to continue like that. So I hope someone can help me.

I develop on a Mac with VS Code/Angular and Netbeans/PHP (although I download PHPStorm also today to see their debug facilities and hope that will bring me further).

My front end runs on a locally defined webserver like “frontend.localhost.dev” and my Slim backend runs also locally defined webserver like “api.localhost.dev”. Both https but that doesn’t matter I believe.
This is a copy of my “production” environment. I have deployed it to my provider and all works, so no issues there.

What I need if a “listener” (XDEBUG? ZEND?) in my PHP IDE that will enable Step by Step debugging when I run my frontend in the browser and execute my http requests. (Hope I explained it clearly enough)

Can anyone help me to guide me what to do, to select and how to configure (any) IDE to make this work? It’s fine to run a separate or internal webserver in the IDE next to my locally defined backend. My front end is easily to be redirected to an different server path.

I hope someone can help me.

Cheers,
Jeroen

Learning Xdebug was a game changer for me. The setup will vary wildly depending on the webserver and IDE you are using so you will likely need to find some tutorials specific to your environment. I tend to use Bitnami which comes with the Xdebug extension ready to go and VS Code for an editor/IDE. I hear the setup for Xdebug 3 is a little easier, but I’m still working with version 2.x.

Thanks for the reply. I haven’t use MAMP and have configured my Apache, MySQL etc all manual, including creating the https certificates. If I would now use MAMP Bitnami, is the overwriting my configuration? Of do I “just” get a GUI that recognises my current config and “just” makes it easier to maintain?

Next to this I understand that on a mac I have to install a “local” php version with or Homebrew of PECL, than download xdebug, phpist and make xdebug before setting up my IDE. Is that correct?

Thanks in advance for your reply.

Why don’t you use any logger ? This is the best way to be kept in touch with anything that happens on the api’s side. Look at one of Odan’s tutorials:

Slim 4 - Logging

Logging can be useful, just as dump or echo can be. But a step debugger is often easier and less complicated to use, once setup.

You don’t need to use Bitnami for sure. It will not overwrite your existing PHP/MySQL setup at all. I personally just find it easier to keep a bunch of different PHP versions installed. I also use it some of my production environments which allows me to know that my dev environment is a very close match.

Your install steps sound correct to me, but I’ve never done it from scratch like that myself as Xdebug comes with the stack I use. You may want to check and see if you have the Xdebug extension already and perhaps it just needs to be turned on in your php.ini.

You can find your php.ini with a command like php --ini then look in there for any Xdebug configuration. cat php.ini | grep -i xdebug You may already have the extension but I don’t think it comes with PHP installed by macOS.

Comparing dump/echo with logging is a kind of an abuse. As logging being indispensable for a production environment there is no reason not to relay on it during a development.
Especially in case of APIs.

If that approach works best for you, that is great! We all look at things from different angles and come from unique experiences with different goals. We can all learn.

I find logging helps me figure out what happened, while a step debugger like Xdebug helps me figure out why something happened. I use all of these approaches to debug from time to time.

If someone whats to learn more debugging techniques from dump to logging to step debuggers, that is great!

1 Like

I am really glad you can see it this way. It is kind of rare attitude nowadays.
Respect.

Thanks for the feedback. I fully agree that logging is nice and works but especially when creating more complex code, step by step debugging is for me a far better method to debug.

I the mean time I’m looking around to setup php with Homebrew, but that doesn’t work because running the latest version of Big Sur.

@tflight I also looked at Bitnami to do this instead of with Homebrew, but can’t find a as simple install for PHP under my user with this package. I do not want to install any other packages, I just want to setup PHP, PECL PHPIZE and XDEBUG.

The XDEBUG wizard tells me to do the follwoing:

  1. Download xdebug-3.0.2.tgz
  2. Install the pre-requisites for compiling PHP extensions.
    On your Mac, we only support installations with ‘homebrew’, and brew install php && brew install autoconf should pull in the right packages.
  3. Unpack the downloaded file with tar -xvzf xdebug-3.0.2.tgz
  4. Run: cd xdebug-3.0.2
  5. Run: phpize (See the FAQ if you don’t have phpize ).As part of its output it should show:

Configuring for: … Zend Module Api No: 20180731 Zend Extension Api No: 320180731

If it does not, you are using the wrong phpize . Please follow this FAQ entry and skip the next step.
6. Run: ./configure
7. Run: make
8. Run: cp modules/xdebug.so
9. Update /etc/php.ini and change the line
zend_extension = xdebug.so
10. Restart the webserver

Giving me the next new problems :confused:

  1. ERROR The version xdebug-3.0.2.tgz is not published on there website.
  2. ERROR Homebrew can’t install PHP on the latest version of Big Sur
    And basically these errors prevent me to complete the next steps :frowning:

Any suggestion to install a “local” PHP on the latest version of Big Sur? Any other package where I just can select PHP to be installed and configured in my User folder?

Thanks in advance.

You can choose to install Bitnami apps/stacks under your user instead of the default /Applications if you wish, however you will get everything within the application/stack you pick. I don’t believe they have a standalone PHP installer except for PHP-FPM. I don’t know if that comes with Xdebug.

I am using the latest Big Sur, and Bitnami does ask you for the install location when you run the installer, but yes aside from choosing the frameworks you want or don’t want, it will also install a version of Apache, MySQL, etc. This approach works great (for me) as I’ve got PHP 5.6, 7.0, 7.1, 7.2, 7.3, and 7.4 all available to me and can easily stitch between then. But I also use their Apache and MySQL, etc. I’ve used their installers for so long it has been many years since I’ve installed PHP any other way. But for sure, this approach may not be for you.

I found this website with in my view great instructions:

I absolutely see the advantage of setting up my mac differently with having Apache, PHP and XDEBUG configured under my usr folders. So changing now from standard to usr setup. The website expains clearly how to do it. Maybe it’s me but always like to understand what’s happening before installing via packages.

For other users: Even though when validating the versions the CLT (command line tools are already installed, use “Software Update” to install updates) showed that I was on the latest versions, brew still reported a warning and indeed after removing the CLT (sudo rm -rf /Library/Developer/CommandLineTools) and reinstalling them ( sudo xcode-select --install) I could install via brew.

Continuing my installation journey now first by installing Apache, PHP and XDEBUG and hope to be able to make XDEBUG work.

1 Like