Composer not available on PHP images

It looks like composer is missing from the image entirely - sudo find / -name '*composer*' returns no results. Too bad the default docs and setup are broken! For now, I’m manually adding composer to our jobs since it makes more sense to use the circleci images.

As a newbie to circleci (and docker) what command are you adding to the default config to install composer?

It’s more then one line, as composer recommends checking the signature before using it. Here’s the section: https://github.com/turnerlabs/validating-xml-encoder/blob/master/.circleci/config.yml#L18

Thank you for sharing

This slightly different method (still multiple lines) worked for me to get composer downloaded to the image and in the “right” place (/usr/local/bin/).

Might this just be an issue with some of our older PHP images? I ran some builds using the image tags currently listed in Docker Hub and Composer seems to be available in those. Just not in circleci/php:7.1.5-browsers as noted above.

2 Likes

@FelicianoTech That works.

It might be worth editing the default config.yml that circle-ci provides, as it doesn’t work. I had to use image: circleci/php:7.1-cli and run: vendor/bin/phpunit.

Can you point me to what specifically you followed that didn’t work?

Well, I created a new project and followed he wizard, which creates a config.yml file. That file referred an image, which doesn’t have composer, yet it tried to call composer and so fails. Changing the image to circleci/php:7.1-cli as you suggested, fixes that. It also tries to run phpunit, which - again - is missing. Using vendor/bin/phpunit obviously only works if I add phpunit to the composer.json file, so perhaps it would have been even better to install it globally.

@FelicianoTech, any update on having this bug fixed? As a new user to circleci, it was frustrating to have this come up almost immediately when trying out your product.

1 Like

Oy, and @FelicianoTech after changing to “latest,” it now errors out /bin/bash: phpunit: command not found

Seems like the lastest image doesn’t have php unit installed :frowning: Frustrating for those evaluating your product.

If you have gotten Composer to work, then could you just install PHPUnit as part of your build?

For what it’s worth, I’m using Docker anyway, so I install everything I need either in the CI config or inside my Docker image. It’s a bit more work up-front, but there is very little to go wrong in CI terms, so it means I can fix everything myself. Would that approach work for you?

I definitely know that if you’re using a up-to-date image from circleci/php, it has Composer. As for PHPUnit, I would be surprised if upstream installed it. @rohara Do we?

We sure do https://github.com/circleci/circleci-images/blob/master/php/generate-images#L11-L16

Not Composer, PHPUnit.

Oh. How do words even work?

No, we don’t install phpunit because it’s usually in something like vendor/phpunit/bin after composer install.

Sorry :smiley:

2 Likes

@jeremylights Please see rohara’s response above.

@FelicianoTech @rohara, ok, that makes sense, but then you shouldn’t have your default config list it if you’re not sure that your users will have it running yet, if at all (there are other options, though not popular). It should be commented out, or at least commented, e.g. “// Comment out the following line if you do not yet have PHP unit installed via composer”

Also doesn’t change the fact that your default config still doesn’t work because composer isn’t installed on that image, which was the main theme behind this thread :smile: You should definitely just change your template to something that works.

What are you talking about :smiley:
https://circleci.com/gh/CircleCI-Public/circleci-demo-php-laravel/17#config/containers/0