How to run symfony cli command with --webapp using local composer.phar?

542 Views Asked by At

I run different versions of Symfony and PHP on my Mac for various apps I have to work on (sorry that our clients are so slow to get to upgrade), and I'm trying to install the LTS version of Symfony through the CLI documentation recommendations, but I'm trying to get it to use a composer.phar in the folder I run the command in... it keeps defaulting to the globally-installed one.

Sure I could just go change composer's execution path or upgrade/downgrade it temporarily whenever I want to run the cli for x version of PHP, but that's gonna drive me crazy and I'd rather see how to tell it to run a certain composer.phar file. I'm not seeing in the documentation how to do this to get the benefits of the --webapp option.

The documentation is weird on it anyway; I can't tell if running composer directly (as composer.phar) will give me the benefits of the --webapp option using the symfony command (because the composer commands are identical for 'traditional web application' and 'console application or API'):

https://symfony.com/doc/5.4/setup.html#creating-symfony-applications

# run this if you are building a traditional web application
$ symfony new my_project_directory --version=5.4 --webapp

# run this if you are building a microservice, console application or API
$ symfony new my_project_directory --version=5.4

# run this if you are building a traditional web application
$ composer create-project symfony/skeleton:"^5.4" my_project_directory
$ cd my_project_directory
$ composer require webapp

# run this if you are building a microservice, console application or API
$ composer create-project symfony/skeleton:"^5.4" my_project_directory

When I run the install through composer directly, I can't tell if I'm getting the benefits of the symfony command --webapp option... and I'm not seeing an option for the symfony command to specify to use the folder's composer.phar.

1

There are 1 best solutions below

0
On

I had to cheat a little bit: I installed the latest composer using the instructions here to a composer.phar file:

https://getcomposer.org/download/

I then created a console alias like php composer.phar, ran the Symfony create composer command with that alias, which created the symfony-5 folder no problem, then I copied the composer.phar file to the new folder and run the alias for any other composer commands, like with require webapp, which is working! Kind of nice to freeze a version of composer for any similar repos.

Maybe not the best answer, but it's working.

Also I discovered that I could just run composer self-update to get the latest version, which worked, then composer self-update [whatever version number] to get back to one I need that works with other repos (since certain version ranges just do not work with certain version ranges of PHP). Annoying, but functional.

Ultimately I think moving forward, it's best to make a copy of composer.phar at a compatible version range for your older PHP apps, depending on their versions, and use those in an alias, rather than totally rely on a global composer version, which has proven not completely workable for my work.