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.
Related
So I know there are alot of simmular issues but none if them are exactly the same,
I want to start my first laravel project but, my terminal tells me command not found,
I installed composer from the website and when I run composer I can see that it works perfectally with no issue, when running composer global require "laravel/installer" I get this in response :
Info from https://repo.packagist.org: #StandWithUkraine
Using version ^4.2 for laravel/installer
./composer.json has been updated
Running composer update laravel/installer
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
9 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
This tells me that laravel is indeed installed but has not updates but when I run command laravel the response is laravel: command not found,
I have added composer to my $PATH already.
This is why I am posting this issue because all the posts I find says to add composer to your $PATH but mine is already but its still a issue.
PHP is also installed on my machine
I am running linux Ubuntu 22.04 LTS
I'll write the answer here so you can close the question. As #geertjanknapen said in the comment if you can install your project the run
composer create-project laravel/laravel your-app-name
cd /your-app-name
php artisan serve
You must have a local server running also, once you have run php artisan serve then just go to http://127.0.0.1:8000/ and you'll see Laravel's home screen. (NOTE 8000 is the default port, so put yours there if you've changed it).
I am familiar with the concept that, when composer.lock file is present, composer install command runs the packages from this file.
So when I add (manually put a vendor/pkg list) to "require" in composer.json, and run command install then only those packages locked in composer.lock files get installed.
But this understanding of mine got conflicted, when I found composer.lock file being git-ignored by my senior developers.
When any update on composer.json file is pushed to deployment server, command install is being run and it seems to "install" the updated packages.
What got me confusing is, since there's no mention of that newly added package in the composer.lock file in the deployment server, how is it being installed?
I tried the same on my local:
first added vendor/pkg in require of composer.json.
tried running command install.
And got this warning instead:
warning: the lock file is not up to date with the latest changes....
nothing to install or update.
So my question is :
why two different behaviors are being shown?
How are the newly added packages in .json and not in .lock are being installed in the deployment server and not in local?
I have been researching on this for a while, and its bugging me.
Maybe I am getting it wrong. Anyone there to clear this out?
There are a few options:
Add vendors with composer require vendor/pkg
Add in composer.json as you did, but then run composer update vendor/pkg (Running composer update without the package name will update all of them)
I'm working on a project based on PHP7 and Laravel. Unfortunately, there was a problem with dependencies and package versions.
I guessed that the previous developer working on the project started updating packages by calling
composer update
on his local dev environment.
Therefore, a new composer.lock file has been generated and everything has been pushed to the production server - however, the composer update command has not been called on the production...
There is a problem with the incompatibility of the PHP version and other errors in dependencies.
This is a very large project and I wouldn't like to migrate now to higher versions on the production server.
I am currently preparing a development environment and I care about maintaining the maximum compatibility of all package versions with what is on production.
By calling:
composer install
on local environment, I'm receiving a series of errors related to the incompatibility of the package versions.
Is there any way to regenerate / restore composer.json and composer.lock based on what is currently installed on the production server? Unfortunately, at this moment composer.lock on production doesn't completely reflect the current state of actually installed versions.
What is a safe and good way to recreate locally a cloned project from a repository on a production server - and maintain full compatibility of all package versions, the correct form of composer.json and composer.lock?
Thanks in advance for your help!
To run composer update and composer install
You can run with this code
composer install --ignore-platform-reqs
Or for update
composer update --ignore-platform-reqs
I found https://www.wuhaiqiao.com/2020/11/24/329.html
No, there is no way to recreate composer.json file based on what is already installed in /vendor. You can look for /vendor/composer/installed.json file as a reference for installed versions of all packages.
What you need to do in this case is:
Make sure your local environment is exactly the same as your production one. You can fake it if needed in your composer.json too by using platform configuration.
Your composer.lock file is of no use. Get /vendor/composer/installed.json file from your production. Delete your /vendor folder.
Run composer install. Write down all packages that have issues and check provided solutions by Composer.
Start downgrading the versions in your composer.json for packages that have issues based to the solutions provided by Composer. Be sure to look into those packages yourself - developers aren't always very strict with the way they maintain dependencies and versioning of their packages. You can always just take package version from production's /vendor/composer/installed.json and place that specific version in your composer.json.
Repeat steps 3-4 until you can finally generate new composer.lock file. Make sure your composer.json and composer.lock files are tracked by your VCS and fixate the changes.
I need to discus a very important thing for me (probably for all users who uses composer in their projects). I am working on laravel. Whenever i work on my local machine, i run composer update after adding new library in vendor.
Now it works fine on local machine. But when i upload these files on my server, it shoots error like "Undefine class ....". I dont know how to run composer update command on server (Also it might be not safe).
So may i just know which files are updated by using composer update on cmd. What other files needed to go live to avoid this error??
You may:
Run composer update on your local server only, whenever you want.
Commit/push every files (including composer.lock) but the vendor directory
Deliver to your production server (without vendor, with composer.lock)
Then run composer install on your production server. It will update all your dependencies according to your composer.lock(so the exact same versions as your last update on your local server).
So in other words: you should not run composer update on your server, just composer install on every delivery (and you will need to keep your composer.lock)
Hope it will help you.
run composer dump-autoload before composer update. If still doesn't work then try to clear composer cache using composer clear-cache
composer update will update the version of every package from you vendor folder.
normally if you can not ensure you need update all the version of every package, you should use composer install
the reason of error "undefined class" is normally caused from app.php.Because service provider is defined in app.php, but the class(package) not been installed.
in order to solve your problem, try do this in three ways:
composer install --no-scripts;
comment the service providers which not been installed already from app.php, then composer install
composer dump-autoload
The project is set-up via composer.phar install --prefer-source and contains quite some modules which are kept in git.
I manage all these modules and their git repositories in my IDE (PhpStorm) and so might commit some changes to some of the modules in the vendor/ folder - directly to the source git repository.
How can I make sure now, that my co-workers get my recent module version when doing a composer.phar install (composer.lock is in the repo)?
If I make a local composer.phar update it looks like the composer.lock is not updated, because I already have the latest version (as I just made the commit directly in the vendor folder)
Commit the changes in the modules repos you've updated.
Push the changes to all respective remote repos.
Tag the new changes with appropriate versions.
Run composer update vendor1/package1 vendor2/package2 (or just composer update if you don't need to be explicit).
Commit and push the updated composer.lock file.
Your co-workers need to pull the updated composer.lock file and run composer install (install latest package versions from lock file).
If you have specified versions restrictions such as "vendor/package": "3.5.*" in your composer.json and you have tagged a new version like 3.6.0 you will need to update your composer.json file accordingly before step 4..
P.S. It is very good you use such a workflow with --prefer-source. Please do not use * or dev-master version restrictions in your composer.json. I would recommend always use versions even if they are in the zero major version range (0.X.X).