Composer installing packages for newer version - php

I run app in docker on my computer and I have a problem with updating php in composer. When I change php version in require composer updates packages to version higher that I specified and get syntax error.
I am updating php from 7.4 to 8.0, the steps i made were:
I change php require to this (i have tried "^8.0.0" and "~8.0.0" too)
"require": {
"php": "8.0.*",
...
then I change Dockerfile to pull from newer image FROM php:8.0-apache (i have checked php version inside the container and it is PHP 8.0.27 (cli))
next I run docker-compose exec -T app composer update --prefer-dist --ignore-platform-reqs
then new lock file is generated and there is for example this which was installed as dependency of another package, i dont have it as my require
{
"name": "monolog/monolog",
"version": "3.2.0",
...
"require": {
"php": ">=8.1",
...
},
when i check the package which has monolog as dependency there is this "monolog/monolog": "^1.17||^2.0||^3.0", so older version was available but newer was picked and installed even when it does not meet the requirements.
Can someone help and tell me what am I doing wrong please?

Related

WAMP php version is not recognized - composer error

I run Laravel 9 on Windows 10.
Everything worked find until installed this package:
https://spatie.be/docs/laravel-livewire-wizard/v1/introduction
and now I get this error in the browser when trying to browse my site:
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". You are running 8.0.13. in C:\wamp64\www\highland9.local\vendor\composer\platform_check.php on line 24
After googling it I check all of these:
php version on Wamp shows 8.1.0
phpinfo() shows 8.1.0
localhost in the browser shows php version 8.1.0
Windows path points to: c:\wamp64\bin\php8.1.0
cmd php -v shows: 8.1.0
In my composer.json file:
it was:
"require": {
"php": "^8.0.2",
I changed it to:
"php":"^8.1.0"
and ran composer update
I tried removing the package like this:
composer remove vendor/spatie/laravel-livewire-wizard
It said there's nothing to remove.
I renamed the folder to laravel-livewire-wizardDEL
I removed the line:
"spatie/laravel-livewire-wizard": "^1.1",
from composer.json and ran composer update
Nothing helps, still get this error.
Can someone please help?
Check if you've overwritten the PHP version under the platform key in your project's local composer.json or the global ~/.composer/composer.json.
Look for the following section:
{
"platform": {
"php": "8.0.13"
}
See: Documentation - Config - platform
Use the following commands to dump the current value:
composer config platform
composer config --global platform

Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.4.22

Locally I have installed php 8
my composer.json looks like this
"require": {
"php": "^8.0",
I deleted the composer.lock and run composer install and I get the above error.
I tried to add
platform-check:false
delete composer.lock
run composer install
but then I get an error because I use Constructor property promotion in my codebase
So it seems that when I add platform-check:false, for some reason it runs on php < 8
P.S I didn't have that problem before, I just cloned my git repo and tried to run my app.
Your phpinfo() maybe having different version than 8.0. If so
Try
sudo apt-get install libapache2-mod-php8.0
Then restart your web server

PHPUnit version does not match version in Composer

I'm trying to update my phpunit version, however it doesn't seem to be working with the regular composer install.
My composer.json file is as follows:
{
"require": {
...
},
"require-dev": {
"phpunit/phpunit": "4.*",
"phpunit/php-invoker": "^1.1",
"phpunit/dbunit": "^2.0"
}
}
And running both composer install and update as php composer.phar install and php composer.phar update (I don't have composer installed globally which might be the issue?) I get
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
When I check to see the phpunit version, I get
$ phpunit --version
PHPUnit 3.7.28 by Sebastian Bergmann.
My PHP version is 5.6 which does seem to rule out the solution from this very similar issue.
My best guess is that there is a global version of phpunit installed and overriding my local one. But I haven't been able to find any guidance as to how to fix this without making too many changes to the rest of the global environment.
The command by itself phpunit will search in your shell's path for a PHPUnit executable. A composer install will place it into the composer bin dir, which is vendor/bin by default. You can execute the script directly with ./vendor/bin/phpunit, or allow composer to execute it for you, resolving the proper path for your project with composer exec phpunit

How to Install mbstring Extension on Heroku?

How do I install/enable PHP extension mbstring?
Heroku on its documentation says it's shared by default, and should be enabled once a Composer package require it. I tried adding it in composer.json file but nothing changed.
This is my project's composer.json:
{
"require": {
"fabpot/goutte": "^3.2",
"guzzlehttp/guzzle": "^6.2",
"paquettg/php-html-parser": "^1.7",
"ext-mbstring": "*"
}
}
After adding last dependency, I ran:
heroku run composer update
This is the error message I got:
The requested PHP extension ext-mbstring * is missing from your system. Install or enable PHP's mbstring extension.
Thank you
Heroku's filesystem is ephemeral. Any changes you make to it after your Dyno spins up can be lost at any time. This happens at least once per day, and possibly much more frequently.
Additionally, composer update is something that I would advise against running on a server. This command installs the newest available version of each library (or specific ones if you only update specific libraries) that fits what's in composer.json. If you ask for ~1.2 in composer.json you might get 1.2.1 on your development machine, but 1.2.9 in production. This can lead to some tricky bugs.
The composer install command installs the exact versions that are defined in your composer.lock file. It is much safer to run on a server, but it does mean that you've got to update your lock file locally and push it to your server.
For both of these reasons you should run composer update locally. This will update composer.lock, which should then be committed and pushed to Heroku. Heroku will run composer install, and you should be all set.
(Alternatively, you should also be able to run composer update 'ext-mbstring' to leave the rest of your dependencies alone. Be careful with composer update, and try to get in the habit of using composer install unless you know you need to update some of your dependencies.)

ext-imagick * -> the requested PHP extension imagick is missing from your system

I have trouble installing devisephp for laravel. I am working on the latest version of homestead with php7. when i do composer update i get the following error.
Problem 1
- Installation request for devisephp/cms 1.4.* -> satisfiable by devisephp/cms[1.4.0].
- devisephp/cms 1.4.0 requires ext-imagick * -> the requested PHP extension imagick is missing from your system.
After having this message i installed imagick on my homestead environment added the extension to php.ini in cli and fpm and checked in homestead if imagick is working with a test file. Everything was working perfectly but on running composer update i still get the same error message from above. Does anyone have a clue what the problem can be.
The stange thing is that is kan git clone devisephp its bootstrap version completely working including image handling but when i add another package to laravel i again get the above message.
if you really can't install or don't want that extension to be validated you may skip it by supplying the
--ignore-platform-reqs
flag to your composer command
Please follow these steps
sudo apt-get install php-imagick
php -m | grep imagick // this should print 'imagick' it means installed correctly
sudo service apache2 restart //(if needed)
Try adding:
"ext-imagick": "*",
to your require block in your composer.json like so:
"license": "MIT",
"require": {
"ext-imagick": "*",
....
}
and run composer update
With the config.platform key in composer.js you can fake dependencies like php versions or extensions (you can't use an asterisk for the extension version, though!)
https://getcomposer.org/doc/06-config.md#platform
As a bonus, you can polyfill ext-imagick with this library: https://github.com/calcinai/php-imagick. it's not complete and relies on the command line ImageMagick. So far it works for me.
{
"require": {
"calcinai/php-imagick": "dev-master"
},
"config": {
"platform":{
"ext-imagick": "3.4.4"
}
}
}

Categories