luddinus's avatar

Composer require on production, best way?

Hi. I want to try some package locally and then upload to production. Which is the best way to install in production?

I was thinking to upload the entire vendor folder (and make a copy of production vendor directory, just in case).

Other way I read, like upload the composer.lock file and the run "composer install"... but my site is already on production, I don't know when to run the command without any bad surprises.

Is there a better way? Thanks.

0 likes
6 replies
drewdan's avatar

Copy the composer lock file up and install. With the version numbers, you should get exactly what you expect in your vendor file.

Maybe it would be worth creating a staging server too, that way you could test things on the staging server before going to production?

luddinus's avatar

@drewdan Yes I have a staging server. My question is? When I run "composer install", do I have to delete de vendor directory first? Other issue is that sometimes I receive memory error, but I fixed applying some swap to the server. (aws micro instance).

drewdan's avatar

The composer install command installs, upgrades or deletes as per what is in the composer.lock file. So you do not need to touch the vendor file, just run composer install, if you change a version number to one of the packages, and run composer install, only the one package will be updated and the rest will remain untouched. If you removed a package from the composer.lock file, and ran composer install, the package would be removed.

Composer.lock is like a snapshot of your packages at that example moment you first installed them, if you deleted your vendor folder, and ran composer install a month later and did not change the composer.lock file, composer would install the exact same packages at the exact same version as when you deleted the vendor folder.

1 like
drewdan's avatar

With regards to the memory problem, might be time for a bigger box :p

RamjithAp's avatar

Apart from your memory issue. You no need to delete your vendor folder before composer require it will automatically update.

1 like

Please or to participate in this conversation.