Deploying Composer project to Web

2.7k views Asked by At

I am new to composer and would like to know how do you guys deploy a project to the production server using composer?

In deploying, would composer also push the dependency packages needed to the server?

Would/ Can composer build the application with minification process?

2

There are 2 answers

1
Sven On

I think the current best practice is to not run Composer on the target production server. The regular process of deploying a web application usually requires several independent steps, and Composer is only suitable for some of them, regardless of what people make it do additionally.

You mention minification, and I would add the process of pulling in JavaScript dependencies in general. This is no domain for Composer. It has been done in the past to offer Composer packages that contain Jquery, but this requires additional work to put Jquery in the right directory afterwards, adding the need to run post install scripts or add installers that need configuration. I guess the right way to do it would be to use Bower for this.

So the deployment would be at least a three step process.

  • Use composer to install PHP dependencies.
  • use bower to install JavaScript dependencies.
  • Use rsync, SFTP, SCP or FTP(S) to move all the files to the server.

Any optimization steps would be done prior to moving the files onto the server inside the deployment script.

And if anything fails during the collection of dependencies, be it an unsuspected downtime of Github, or your deployment server running out of disk space, you don't end up with a halfway deployed new website version. You can stop the deployment script before syncing if anything is missing or gone wrong.

0
rui tian On

yes, composer install get all dependencies in your test server, check it, if everything work ok, then sync all the files to your production server, which can save you from the unexpected problem running composer install on your production server.

other way is to sign all the files from your test server after composer install, then use composer install to get all dependencies in your production server, sign the files, now you must check two signs separately generated in test and production server, if it match, congratulations, the deploy is ok.