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
Related
I am trying to ask the question as precisely as possible but I myself have lots of confusion about this. So please bear with me
Problem - We have a third party API (Recurly) installed in our site. That site was built with Laravel. The version of that API is now outdated and I want to update the version via composer.
From the Recurly I have got the following instruction to upgrade the version
In composer.json file update the line of code from "recurly/recurly-client": "2.8." to "recurly/recurly-client": "2.12. . And this will upgrade your client library AND your API version.
Once you do this, please run a composer update in your terminal->active directory w/ Recurly and it will update you:
I have updated the line inside composer.json file. But I dont understand the second part of the instruction. How to run a composer update. Shall I update the composer itself? But I want to update the Recurly API version. is it necessary to update the composer itself?
I have found this link: https://getcomposer.org/doc/03-cli.md#update-u
In this link its written
In order to get the latest versions of the dependencies and to update the composer.lock file, you should use the update command. This command is also aliased as upgrade as it does the same as upgrade does if you are thinking of apt-get or similar package managers.
php composer.phar update
I am not sure Is this the command I need?
Our webserver is with AWS. And we have WHM and cPanel installed to manage the web server.
I understand my question is not not precise as expected . but I cant figure out where to start actually. Please suggest me accordingly
As composer update command can create additional problem to the server hence i have run composer update only for Recurly as a root
composer update recurly/recurly-client
It is important to run the command from the directory where the composer.lock and composer.json files are
for an example if you have several sites under your server and if you run the command as root it may affect other sites as well.
To prevent that first you have to run
cd /home/websitefolder
then
composer update recurly/recurly-client
This way you can update only single package and it will not affect the rest of your site
There are two approaches to solving your problem,
Option A
as was stated, go to your composer.json and update the line
go to Terminal at the cpanel, should you not have terminal, use option 2
cd into your directory and run php composer update, (please before doing this, make sure to have a copy of your composer.json and the lock files.
Option B (No Terminal at cpanel)
Zip your directory and download
copy the file after unzipping to your wamp/xamp directory
edit the composer.json
and run php composer update (things can break here, I think the best is to run composer install rather than update)
zip and upload the file back.
I believe that should solve the problem
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 have two PC: A laptop and a desktop computer.
I was working two weeks on my Symfony 3 project with the desktop computer, and I defined some new parameters on my parameters.yml.dist
Today, I need to use my laptop, so I did a pull from my origin branch, and then I executed the following command to update my project:
php composer.phar update
This command updated successfully my project (parameters and vendor directory). With this, I can now run my project.
The problem is that now when I run:
git status
Lots of modified files appear in the vendor directory. Also composer.lockfile apperars, and I think that this is correct, but not the vendor files.
My .gitignorecontains, among others, the following line:
vendor/*
What I did wrong? And how can I solve it?
The problem is probably twofold.
You probably have checked in files from the vendor directory before adding it to the gitignore or maybe you accidentally added them with the --force flag which ignores the gitignore.
The other big problem is that you ran composer update this will not only install the dependencies in your composer.lock it will actually update them, meaning you might get different versions then the ones you were developing with before. Next time you should probably run composer install (even on a system where you already have vendors installed). This will do as advertised it will install all dependencies as defined in the composer.lock. Whenever you checkout a newer version of that file the install command will automatically update your local vendors to the versions defined there. This ensures that you always work with the same dependency versions.
Should you want to update your dependencies you might want to do it one by one using composer update <dependency-name> this will then again update your composer.lock which you should have checked into git.
In your case you might want to remove the vendor folder, but make sure you keep your composer.lock. Now you can commit this change to make sure you remove all checked in files vendor/. After that, your .gitignore should work again and running composer install should re-install everything as defined in the composer.lock and you should not see any changes in your work dir when running git status. If there are you might have to tweak your .gitignore, e.g. try /vendor instead of vendor/*.
I just started my laravel course with laracast. I dont quite understand yet all the enviornment-related things.
I know that Composer is a kind of a program that downloads pre-written scripts to use in your project. But where does it work? On my local machine or on my vagrant homestead box VM? On which of these is it supposed to be installed?
I installed myself vagrant homestead box already but does it contain composer? When I go ssh into my guest machine and go to vagrant#homestead:/vagrant$ path I can see composer.json and composer.lock files, but does it mean that I have composer installed?
Composer is a PHP package manager, like npm for javascript or pip for python. There are many examples of package managers. It's useful, because adding dependencies to your php projects can be a pain, but composer makes it really easy. You just add the dependency to composer.json and you can use it right off the bat.
Composer isn't laravel specific, you can use it in any php project, laravel uses it to manage it's dependencies, laravels dependencies use it to manage their dependencies and so forth.
If nothing else, the composer autoloader is great, so you can use it even if you don't plan on using external packages.
Homestead should come with composer installed. A composer.lock file is generated when you run a composer install or composer update. If you plan on creating or using other php projects on your machine, it's probably a good idea to have composer installed on your machine as well.
I have an old composer based symfony project, that I just updated with some changes of code. I tested in development everything works fine. I have got issue when deploying the composer asked to run composer.phar self-update to update the composer since the composer is outdated. After that I do the composer.phar install. I get this error -
[RuntimeException]
Your composer.lock was created before 2012-09-15, and is not supported anymore. Run "composer update" to generate a new one.
What if I don't want to update. I am okay this. How can I force it not to update.
The structure of the lock file was changed, and therefor you should upgrade your lock file. You can upgrade your lock file without actually upgrading any dependencies by executing:
composer update nothing
I would suggest you look at the composer.lock file and note any versions that are used there. Then copy these into the composer.json, delete the lock file and run a normal install.
Of course, you do this on a copy of your software to see if all the same versions do appear again.