Composer not available on PHP images

composer
php
2.0

#1

I’m trying to set up an existing PHP project with circleCI 2.0, but the default template fails because composer is not installed in the system:

/bin/bash: composer: command not found 
Exited with code 127

Am I missing something, or is this an issue with the docker image or the template?


#2

Same here using the - image: circleci/php:7.1.5-browsers and - image: circleci/php:7.0.4-browsers images. I’m going to back to 1.0.

From CircleCI demo project, the fix seems to be not using CircleCI images :smile:


#3

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.


#4

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


#5

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


#6

Thank you for sharing


#7

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/).


#8

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.


#9

@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.


#10

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


#11

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.


#12

@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.


#13

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.


#14

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?


#15

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?


#16

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


#17

Not Composer, PHPUnit.


#18

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:


#19

@jeremylights Please see rohara’s response above.


#20

@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”