I am developing PHP app on my Mac which is using PHP 7.3, but my server is running PHP 7.1. I commit both composer.json and composer.lock into git, and contains the lines
"require": {
"php": "^7.1.0",
However, when I run composer install on my local Mac, and composer.lock is filling with dependencies which is optimised for my local PHP 7.3, and when I copy the composer.lock to the server and run the composer install again, will it install the correct version? eg. PHP 7.1 instead of 7.3 dependencies?
Related
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?
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
I'm using Homestead to develop a site that will be on a server with PHP 7.0. I want to use .env files, so I ran this Composer command:
composer require vlucas/phpdotenv
When I perused the file, composer.lock, I noticed that a dependency, doctrine/annotations, was requiring PHP 7.1.
I tried adding this to my composer.json file:
"config": {
"platform": {
"php": "~7.0"
}
},
When I run composer update, I get this error:
[UnexpectedValueException]
Invalid version string "~7.0"
I realize that this is because PHP 7.2 is the default version on Homestead. How do I run Composer with PHP 7.0 instead of PHP 7.2?
Executing which composer will give you this output:
/usr/local/bin/composer
The Homestead documentation discusses the multiple PHP versions supported and how to call them from the command line for Artisan. Combining that with the composer path above allows you to do this:
php7.0 /usr/local/bin/composer update
Run the command php70 and that will set PHP 7.0 to the default system version of PHP, then you can run composer normally.
In my composer.json I have
"require": {
. . .
"unisharp/laravel-filemanager": "~1.8"
}
Currently, the latest version is v1.8.2.2 and after running the composer update command I have it installed on my localhost project (everything is OK).
I have pushed (git push origin master) from localhost to the remote repo on Bitbucket, and via SSH I have connected to the web server and cloned (git clone ...) it from that remote repo.
Now, when I run composer update (on web server) - it installs v1.8.0 which has some bug. After that, when I try again to run composer update - I get:
Nothing to install or update
... but it's still v1.8.0 (not v1.8.2.2 like it is on localhost).
So, I have identical project with identical composer.json on my localhost and on live server but, for some reason, localhost has the latest version of the package and live version has the old version with bug and composer update doesn't update it.
Do you know why this is happening and how can I solve it?
You should run composer update locally. This will update composer.lock with the versions of all the packages you have installed. You should commit your composer.lock file to your version control.
On your server, once you've updated your files you should then run a composer install so Composer can update its dependencies to match those specified in your composer.lock file.
I just spent two hours debugging this. Turns out the problem was that there was a "version" tag in the composer.json file.
When there is a version tag there, that version will be used in priority above any git tag version that you apply.
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.)