z0d14c
z0d14c

Reputation: 1142

Include library without running composer dump-autoload for a Laravel 4.x project in production

I'm developing for a Laravel project and we've recently started working with our DevOps team to bring our WebApp up on a staging server.

The DevOps team is not familiar with Laravel and is fairly averse to running command line operations on the project to get it up and running. Between our last build and this build, we've added some new services in the app/ directory, and some new 3rd-party libraries in the vendor/ directory.

How can we include these services/facades in the app/ and vendor/ folders without using composer dump-autoload, so that they are usable in the project? Is it a reasonable solution or should I be working/expecting to convince DevOps that they need to learn to run composer commands from the CLI?

Thank you!

Upvotes: 0

Views: 2138

Answers (3)

Jens A. Koch
Jens A. Koch

Reputation: 41747

How can we include these services/facades in the app/ and vendor/ folders without using composer dump-autoload, so that they are usable in the project?

I'm reducing this question to a pure autoloading problem:

Adjust the autoloader of the application to load the newly added classes from their location.

This means to add your own autoloader to Laravel's stack of autoloaders at the position before Composer.

Laravel Autoloader Stack

1 Illuminate\Foundation\AliasLoader::load() 
2 YourApplicationLoader::load()              <---- load your services & whatnot
3 Composer\Autoload\ClassLoader::loadClass() 
4 Swift::autoload() 

If the libs are not loaded by Composer, because dump-autoloader wasn't run, then the application autoloader will load them.

For more: http://alanstorm.com/laravel_5_autoloader

Is it a reasonable solution or should I be working/expecting to convince DevOps that they need to learn to run composer commands from the CLI?

The "new" approach is to run Composer on production machines, too.

While the "old-school" approach is to package your application with all it's dependencies on the staging server. In other words: build a deployment ready archive, which you can simply extract on production.

Upvotes: 0

Sven
Sven

Reputation: 70863

Your DevOps people are right: You shouldn't need Composer to be run in production, on the production machine(s).

You have to think about a process to deploy your application. This usually means that you have a machine that is meant to do continuous integration, so every commit triggers the execution of the test suite and reports the results. Such a machine could be used to also do continuous deployment, for example to the staging machine.

What that means is that you have a machine that is able to put together all the different components that make up your application, and when all the parts have been gathered in that location, you move all the files over to the staging (and later production) system.

Because automation is king, you should create a script that does everything needed to get into that state of "completely assembled all needed files and done all necessary stuff". Why a script? Because doing these things likely will not only need one call to composer install --no-dev - for example, frontend components like Javascript are better managed using Bower or something that is NOT Composer. Composer is for managing PHP code.

When you have that deployment script, your DevOps guys will be happier: They can deploy the application by checking it out from the repository and then running one script. They do NOT need to install anything development related onto a production machine (note that every software that allows software development on a production machine is very useful for an attacker in case of security breaches).

All they need to do then is to copy files to make a new version live.

Upvotes: 0

user1544337
user1544337

Reputation:

You can mount the directory with FTP(S) or SFTP / SSHfs on your local machine, then run composer dump-autoload (or whatever command you'd like to run) in that local directory.

It depends on your operating system how to do that exactly.

But yeah, they should really get used to doing that themselves.

Upvotes: 2

Related Questions