Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wonder95's avatar

XDebug won't run in PHPStorm 2024.1.1 on Mac M2 when installed/configured

I have a fancy new MacBook Pro M2, and I installed PHP via Homebrew as I usually do. However, for some reason, even though I ran brew install php@82, it installed both the php(aka8.3) and [email protected],and therefore both /opt/homebrew/etc/php/8.3*and/opt/homebrew/etc/php/8.2*, with 8.3as the one actually being used. I also need to run XDebug, so, per the instructions, I installed it viapecl. However, since I need 8.2, I unlinked/uninstalled the phppackage, and manually deleted all of the8.3` files and directories.

Now, if I do php --version from the command line, it shows me 8.2 as it should, and if I do php -i | grep xdebug, it shows xdebug installed and reading my opt/homebrew/etc/php/8.2/conf.d/xdebug.ini file. I have XDebug configured in PHPStorm 2024.1.1, and I can turn it on and debug an artisan command just fine. However, when I look at phpinfo() from a web page (by putting phpinfo(); in index.php), it shows it still reading all of the 8.3 files (e.g. /opt/homebrew/etc/php/8.3/php.ini), even though they don't exist. I ran brew doctor and it said to run brew cleanup to get rid of the broken symlinks, and they were deleted. However, when I run brew restart services [email protected] it still shows the 8.3 files being read.

I went back and looked at brew doctor output, and it tells me

Warning: Some installed formulae are missing dependencies.
You should `brew install` the missing dependencies:
  brew install php

so I re-run brew install php, and of course, it makes 8.3 the default. I run brew unlink php and brew link [email protected], and it does.

However, phpinfo() still shows the 8.3 files being read, and my step debugger in phpStorm won't work (and yes, I have the cookie set via XDebug helper, it's turned on in PHPStorm, CLI Interpreters is set and shows xdebug installed., etc).

What am I missing so that I can get xdebug working in PHPStorm?

0 likes
5 replies
LaryAI's avatar
Level 58

It sounds like there are a few issues at play here, primarily related to the PHP version being used by your web server versus the CLI. Here’s a step-by-step guide to ensure that your web server is using the correct PHP version and that XDebug is properly configured.

Step 1: Verify PHP Version for CLI

First, ensure that your CLI is using the correct PHP version:

php --version

This should show PHP 8.2.

Step 2: Verify PHP Version for Web Server

Your web server (likely Apache or Nginx) might still be using PHP 8.3. To check this, create a phpinfo.php file in your web server's root directory with the following content:

<?php phpinfo(); ?>

Access this file via your web browser and check the PHP version displayed.

Step 3: Configure Web Server to Use PHP 8.2

If the web server is using PHP 8.3, you need to configure it to use PHP 8.2. Here’s how you can do it for both Apache and Nginx.

For Apache:

  1. Disable PHP 8.3 Module:

    sudo a2dismod php8.3
    
  2. Enable PHP 8.2 Module:

    sudo a2enmod php8.2
    
  3. Restart Apache:

    sudo service apache2 restart
    

For Nginx:

  1. Update Nginx Configuration: Open your Nginx configuration file (usually located at /etc/nginx/sites-available/default or similar) and update the fastcgi_pass directive to point to the PHP 8.2 FPM socket. It might look something like this:

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
    }
    
  2. Restart Nginx:

    sudo service nginx restart
    

Step 4: Verify XDebug Configuration

Ensure that XDebug is correctly configured in your php.ini or xdebug.ini file. Here’s a basic configuration:

[xdebug]
zend_extension="xdebug.so"
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003

Step 5: Verify XDebug in PHPStorm

  1. Check PHPStorm Settings:

    • Go to Preferences > Languages & Frameworks > PHP > Debug.
    • Ensure the Debug port matches the one in your xdebug.ini (default is 9003).
  2. Check CLI Interpreter:

    • Go to Preferences > Languages & Frameworks > PHP.
    • Ensure the CLI Interpreter is set to PHP 8.2 and that XDebug is listed as an installed extension.
  3. Set Breakpoints and Start Listening:

    • Set breakpoints in your code.
    • Click the "Start Listening for PHP Debug Connections" button in PHPStorm.

Step 6: Restart Services

Finally, restart all related services to ensure changes take effect:

brew services restart [email protected]
sudo service apache2 restart  # or sudo service nginx restart

Step 7: Test Debugging

Access your web application in the browser and trigger the code that should hit your breakpoints. PHPStorm should now catch the XDebug connection and allow you to debug.

By following these steps, you should be able to ensure that your web server is using PHP 8.2 and that XDebug is properly configured and working in PHPStorm.

wonder95's avatar

So I went back and deleted everything in homebrew (php, composer, node) and re-installed from scratch. For now, I'm just running with PHP 8.3.7. I also deleted and re-installed xdebug via pecl. Doing both php -i from the command line and running phpinfo() in the browser show xdebug installed and configured. This is all identical to the setup I have on my other M2 MacBook. I have even invalidated all the caches in PHPStorm.

What else could I be missing?

rpickz's avatar

@wonder95 Did you find a solution to this issue?

I have hit the same problem.

LinboLen's avatar

it works when i config as following

xdebug.mode = debug xdebug.discover_client_host = true

Please or to participate in this conversation.