Local composer update fails with new heroku php buildpack - php

When moving from our own PHP custom buildpack to the supported Heroku one we are running into a problem. Heroku requires us to add certain extensions to the composer.json "require" part, but when you then try to update locally it fails because these packages do not exists in the repo.
Config file:
{
"config":{
"github-oauth":{
"github.com":""
}
},
"require": {
"php": "*",
"ext-newrelic": "*",
"ext-memcached": "*",
"aws/aws-sdk-php": "2.*",
"rollbar/rollbar": "*",
"yiisoft/yii": "1.1.15",
"cloudinary/cloudinary_php": "1.0.11",
"geoip/geoip": "v1.14",
"sendgrid/sendgrid": "2.1.1",
"swiftmailer/swiftmailer": "v5.2.1",
"crisu83/yiistrap": "dev-bs3"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
"phpunit/dbunit": ">=1.2",
"phpunit/php-invoker": "*",
"phpunit/phpunit-selenium": ">=1.2",
"phpunit/phpunit-story": "*",
"squizlabs/php_codesniffer": "1.*",
"phpmd/phpmd" : "1.4.*",
"phploc/phploc": "*",
"pdepend/pdepend" : "1.1.0",
"sebastian/phpcpd": "*",
"mayflower/php-codebrowser": "~1.1"
}
}
Error message:
11:08:55 {development} /Volumes/Development/web$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested PHP extension ext-newrelic * is missing from your system.
Problem 2
- The requested PHP extension ext-memcached * is missing from your system.
Any ideas ?

You need to install those extensions. The assumption is that you develop, run and test your code locally during development using roughly the same components and environment as in production, so if you use memcache in production, you also use it locally. That ensures you're not running into nasty surprises because different datastores behave differently etc. Also see http://12factor.net/dev-prod-parity
Exception to the rule: you don't need to install the New Relic extension; it's enabled automatically on push if you provision the New Relic add-on (by detecting NEW_RELIC_LICENSE_KEY env var), see https://devcenter.heroku.com/articles/php-support#extensions (it is of little use locally on a developer's box, and can be a bit troublesome to install).

Installing the extensions fixed this for me (the newrelic extension is giving me trouble but that's another question.)
(Answer was posted here, but the person removed it again.)

Related

How to configure symfony check:requirements?

I am using Symfony for an application. This application needs particulars PHP extensions to work, such as PHP GD, which are not listed in the base Symfony requirements.
I would like to know if it's possible to kind of edit the base list of requirements to add those extensions for my application to have them listed under the symfony check:requirements console output.
This requirements will NOT be tested when you launch symfony check:requirements, because this command doesn't depend of your application, it only checks the capacity to use symfony on the server.
This command will always return the same result, even if you launch it in a directory where there is no composer.yaml file.
But, you can add the needed extension by updating the composer.json file:
...
"require": {
"php": "^7.2",
...
"ext-gd": "*",
"ext-json": "*",
...
"foo/bar-bundle": "^1.3",
...
}
So, if the GD extension isn't installed on your server, installation of your application will not start.

PHP deploy on heroku - push failed

I have been trying to deploy a php app on heroku but I keep getting this error:
-----> PHP app detected
-----> Bootstrapping...
-----> Installing platform packages...
ERROR: neither your composer.json 'require' section nor any
dependency therein requires a runtime version, but 'require-dev'
or a dependency therein does. Heroku cannot automatically select
a default runtime version in this case.
Please add a version requirement for 'php' to section 'require'
in composer.json, 'composer update', commit, and deploy again.
! ERROR: Couldn't load 'composer.lock'; it must be a valid lock
file generated by Composer and be in a consistent state.
Check above for any parse errors and address them if necessary.
Run 'composer update', add/commit the change, then push again.
! Push rejected, failed to compile PHP app.
! Push failed
anyone know how I can solve it?
So this is what I would look at, and sorry if any of these assumptions are wrong, or I am going through stuff you have already done.
Your composer.json should be divided up into require and require-dev. Require would be installed in production with require-dev added locally.
{
"name": "something/something",
"description": "A description of my project",
"type": "project",
"require": {
"php": ">=5.5.9",
"doctrine/cache": "1.4.*",
"elasticsearch/elasticsearch": "~2.0",
"monolog/monolog": "~1.0",
"knplabs/github-api": "~1.2",
"ezyang/htmlpurifier": "~4.6",
"easyrdf/easyrdf": "0.9.*",
"hoa/compiler": "~2.15",
"hoa/visitor": "~1.15",
"collectiveaccess/service-wrapper": "v1.1",
"phpoffice/phppresentation": "dev-master",
"phpoffice/phpword": "v0.13.*"
},
"require-dev": {
"phpunit/phpunit": "4.3.*",
"maximebf/debugbar": ">=1.0.0"
}
}
If you have not got composer installed you need to do so. https://www.hostinger.com/tutorials/how-to-install-composer
Run php composer install in the first instance of php composer update later on to install your dependencies.
Please commit everything except, the vendor files and any cache or logging. This would include composer.lock which is a list of installed dependencies and the versions you are using.
Heroku will install these dependencies in production making sure it uses the same version as specified in the lock file.

Is it possible to tell composer to always choose lower package version, when there are more then one matching requiremnets

I have a package which uses "satooshi/php-coveralls" package to calculate coverage on TravisCI. Coveralls composer.json requires:
"require": {
"php": ">=5.3.3",
"ext-json": "*",
"ext-simplexml": "*",
"guzzle/guzzle": "^2.8|^3.0",
"psr/log": "^1.0",
"symfony/config": "^2.1|^3.0",
"symfony/console": "^2.1|^3.0",
"symfony/stopwatch": "^2.0|^3.0",
"symfony/yaml": "^2.0|^3.0"
},
My package doesn't use any of those packages directly, but I am supporting PHP 5.4 which in turn requires that lower version of all them are used. Is there a way to tell composer to use guzzle/guzzle: ^2.8 rather then ^3.0, symfony/config: ^2.1 rather then ^3.0 etc. Currently when I run composer install, higher versions are installed so the build fails on PHP 5.4
There is a prefer-lowest option when running composer. Here are more details
https://evertpot.com/testing-composer-prefer-lowest/
You can use ~ ("tilde") for that..
"guzzle/guzzle": "~2.8",
which means
>= 2.8 < 3.0.0
also
"guzzle/guzzle": "^2.8",
should work
evenmore any higher versions of 2. but less than 3.
"guzzle/guzzle": "^2.*",
or
"guzzle/guzzle": "~2.*",
https://getcomposer.org/doc/articles/versions.md

Install one package without checking all requirements with composer

I have a composer.json like this:
{
"require": {
"symfony/yaml" : "dev-master",
"symfony/console" : "dev-master",
"ebuildy/ebuildy" : "dev-master",
"keboola/php-encryption": "dev-master",
"pear-pear.php.net/mail_mime" : "*",
"pear-pear.php.net/http_request2" : "*",
"pear-pear.php.net/mail_mimedecode" : "*",
"microsoft/windowsazure": "*",
"rollbar/rollbar": "dev-master",
"facebook/php-sdk-v4" : "4.0.*",
"happyr/linkedin-api-client": "dev-master",
"zircote/swagger-php" : "dev-master",
"google/apiclient" : "dev-master"
},
"autoload": {
"psr-0": {
"bizlunch": "src/"
}
},
"minimum-stability": "dev"
}
Just added "google/apiclient", I want to install this new package without checking other packages requirements (because on my dev machine "keboola/php-encryption" complains about crypt ext missing and other stuff).
What is the right command? Tried already update PACKAGE, but this fails:
$root: php composer.phar update google/apiclient
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- keboola/php-encryption dev-master requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.
If you want to ignore the specifics of your local system, you can use --ignore-platform-reqs flag. Keep in mind that it may result in unusable lockfile in production.
Let's show it on imaginary scenario:
you don't have ext-crypt locally and neither in production.
there is package cryptX that
in cryptX:1.0 uses lib-crypt-polyfill (that does what ext-crypt does using PHP code)
but in cryptX:2.0 they changed the dependency to ext-crypt.
Now if you were to install it normally, you'd get version 1 (which is the only one meeting the dependencies). But with --ignore-platform-reqs it just works as if whatever it wants is available in your system. So it happily installs version 2, which does not work on you machine, but what's more it won't work on you production server neither.
As easy as
php composer.phar update google/apiclient
or you can specify several individual packages as
php composer.phar update google/apiclient zircote/swagger-php rollbar/rollbar
Maybe PHP extension mcrypt isn't installed on your machine. See how to install it here http://php.net/manual/en/mcrypt.setup.php
In an Ubuntu machine run :
apt-get install php5-mcrypt
php5enmod mcrypt
service apache2 restart

PHP composer install PHPUnit runner

I am trying to install PHPUnit/Runner/Version.php using PHP composer and I get the following error.
The requested package phpunit/phpunit-runner could not be found in any version, there may be a typo in the package name.
I am not sure if I am install the wrong package or what. The following is what I have in my composer.json file.
{
"require-dev": {
"phpunit/phpunit": "4.1.*",
"phpunit/php-invoker": "*",
"phpunit/dbunit": ">=1.2",
"phpunit/phpunit-selenium": ">=1.2",
"phpunit/phpunit-story": "*",
"phpunit/phpunit-runner": "*" - with this removed that file is unavailable
}
}
Any help would be great.
The class PHPUnit_Runner_Version is part of the core PHPUnit package phpunit/phpunit in any version.
So there is no need to require it seperately because the package name you invented does not exist.
You probably have a different problem you didn't ask in this question about some software not being able to require this class, but this likely isn't being solved this way.

Categories