-2

On my new Mac Air M2, I downloaded VSCode and then I downloaded XAMPP 7.4.3 in /Applications folder, because I wanted to use PHP 7.4.3.

Next, I downloaded Homebrew and installed PHP. It installed PHP 8.2.5.

So now the problem is my XAMPP is using PHP 7.4.3 and VSCode is using PHP 8.2.5.

I also downloaded composer from brew. My composer.json file requires minimum PHP 8.1.

However, I want to work in PHP 7.4.3.

When I run php -v in VSCode I get PHP 8.2.5, and when I save a file with php_info(); in htdocs and open with a browser, I get PHP 7.4.3.

So it is clear that XAMPP is using PHP 7.4.3 and VSCode is using PHP 8.2.5.

What should I do to make VSCode use PHP 7.4.3?

treckstar
  • 1,956
  • 5
  • 21
  • 26
  • 4
    So why did you download/install PHP 8.2? XAMPP comes with a version of PHP as part of it – RiggsFolly Apr 16 '23 at 10:04
  • If your composer.json requires a PHP version you don't want to use, why not change what you've written to your composer.json? But please keep in mind that PHP 7.4 is nearing its end of life, and PHP 7.4.3 itself is even older than the latest PHP 7.4 release – Nico Haase Apr 16 '23 at 13:04

1 Answers1

2

This is for a windows env, but I assume it will be similiar.

I have a launch.json file for each project as below, where I can select one of many versions of PHP that I have installed.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [        
        {
            "name": "Debug currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003,
            //"runtimeExecutable":"C:\\wamp64\\bin\\php\\php5.6.40\\php.exe",
            //"runtimeExecutable":"C:\\wamp64\\bin\\php\\php7.0.33\\php.exe",
            //"runtimeExecutable":"C:\\wamp64\\bin\\php\\php7.1.33\\php.exe",
            //"runtimeExecutable":"C:\\wamp64\\bin\\php\\php7.2.34\\php.exe",
            //"runtimeExecutable":"C:\\wamp64\\bin\\php\\php7.3.32\\php.exe",
            //"runtimeExecutable":"C:\\wamp64\\bin\\php\\php7.4.32\\php.exe",
            //"runtimeExecutable":"C:\\wamp64\\bin\\php\\php8.0.25\\php.exe", 
            //"runtimeExecutable":"C:\\wamp64\\bin\\php\\php8.1.14\\php.exe" 
            "runtimeExecutable":"C:\\wamp64\\bin\\php\\php8.2.4\\php.exe" 
        }
    ]
}

If you do something similiar in yours you can get VSCode to launch with any verions of PHP you have on your system

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149