composer / windows-setup

The Windows installer for the Composer PHP Dependency Manager
MIT License
144 stars 69 forks source link

Chocolatey: Composer has a PHP dependency which is disrupting my workflow #158

Closed grandeljay closed 6 months ago

grandeljay commented 6 months ago

Hello!

I couldn't fit what I wanted to say into the issue template so I hope you will excuse me for not using it.

I am using Laragon on Windows which already comes bundled with PHP. When installing composer, it automatically installs PHP to C:\tools. Alternatively, I can specify an already installed PHP but it must be an .exe file.

Composer Setup on Windows

This is already not possible with my setup, since I need to switch between different PHP version frequently, depending on which project I am working on and as such, I have created a .bat file, to point to the desired php executable I would like to use (and I set it in my PATH environment variable).

When Composer (or more specifically PHP) is updating, it keeps adding the environment variable to C:\tools, and so when I use the CLI, it's often set to the newest PHP version, instead of the version I want to use.

Extracting 64-bit C:\ProgramData\chocolatey\lib\php\tools\php-8.3.6-nts-Win32-vs16-x64.zip to C:\tools\php83...
C:\tools\php83
PATH environment variable does not have C:\tools\php83 in it. Adding...
Please make sure you have CGI installed in IIS for local hosting
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 The upgrade of php was successful.
  Software installed to 'C:\tools\php83'

Right now, I always need to remove the PHP executable from my PATH environment variable after every composer/php update.

An ideal solution for me would be any of the following options:

  1. Installing composer without a PHP dependency
  2. Installing composer and being able to add a .bat file as a PHP-executable
  3. Installing composer/php without environment variables being set automatically

Is my setup just weird/wrong or is this an issue with composer or php?

In any case, your advice is very appreciated!

Thank you for your eye balls.

Seldaek commented 6 months ago

Moved to windows-setup repo, maybe @johnstevenson has a clue. I'd tend towards "your setup is weird" but I am not familiar with Laragon and I haven't been running php outside of WSL in quite a few years now so 🤷🏻

johnstevenson commented 6 months ago

Right now, I always need to remove the PHP executable from my PATH environment variable after every composer/php update.

To update Composer you should use the command composer self-update. Running an update through Chocolately will also install the latest PHP, because the Chocolatey Composer package has a dependency on it.

I suggest that you uninstall the Choclolatey Composer package and do a manual installation, as described in the docs: https://getcomposer.org/doc/00-intro.md#using-the-installer

grandeljay commented 6 months ago

Thank you both for your valuable feedback!

I think I will try a compromise and pin the composer package (so chocolatey stops updating it) and I will simply use the composer self-update command in the future.