0

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!

0

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Are you saying that I (or another engineer) could basically run the commands myself remotely through SSH/FTP? Btw, I wasn't aware you could issue commands through FTP/SFTP.
@z0d14c no, you won't run the commands remotely. You have a directory on your own machine which is (automatically) synchronized with the server through FTP, SFTP, etc. Then, you run the commands locally. Your own machine downloads the new services, updates the dependencies, and does everything that needs to be done. Automatically, the file system makes sure the files you modify locally are synchronized with the server. So, in a nutshell: you run the commands locally on a synchronized directory.
So in effect, I would build the autoload files locally and then they should work on the deployment server?
Thank you! This might be the "quick and dirty" type of solution that we can use without making DevOps learn anything.
@z0d14c no problem. Also have a look at what Sven has to say though. This works, but it's not preferable for a long term solution.
0

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.

3 Comments

Ok, I like this answer but I should mention that I am an intern so I don't know how much credibility I have to affect the processes-- but I will do my best to see if we can utilize a deployment script. BTW I do not quite understand the "machine that is able to put together all the different components" part-- what purpose does this serve that simply unzipping a tarball onto the production server does not? Is it a step in the right direction for DevOps to simply unzip a tarball onto production, and then run our script?
Unzipping a tarball is one way to get the files on the machine. But then my next question is: If you have the need to run Composer on the target machine, why didn't you run it before creating that tarball? That's what I was trying to point out: Composer doesn't do any magic that requires to be run on a certain machine. You should run it before creating that tarball, then only use that to distribute the software.
Ahhh I see, that makes sense -- I'm a bit of a novice, just beginning to understand that autoloader is basically a static thing that doesn't need to be run on deployment. I think we can create tarball first, and then there will be no need to run any composer commands.
0

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.

5 Comments

I think you miss the bigger case of devops deployment questions here.
The question was "How can we include". I just gave a simply answer to the problem.
I thought composer was the autoloader, if not then what is "autoloader of the application"? I'm guessing you are referring to laravel's app.php which loads some services and what-not.
Yes, they rely heavily on Composer as the autoloader, but you may still add a custom autoloader in the boostrap.
Composer creates an autoloader. It has the ability to write files that contain a PHP script that does the autoloading. Composer itself will never be contained in the final application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.