Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kay899's avatar

Run composer via Artisan Command or Job?

Hi,

I need to run a "composer update" or "composer require" via an Artisan Bommand or (better) in a Job.

After several hours I can't find a solution for this. Just tried to use shell_exec('composer update); but this will not tun.

The Artisan Command or Job should be executed in an installation on a Digital Ocean Server.

Does someone has an idea how to do that?

Thanks kay899

0 likes
9 replies
Snapey's avatar

You need to know the full path to composer.

But I don't think it's a good idea if this is to update your project as you will need to give your Web server elevated permissions

kay899's avatar

I only want to add required packages to an existing package. Not really update my whole project.

click's avatar

Not sure if it is a good idea but this would work:

$command = "composer install" 
$path = base_path();
exec("cd {$path} && {$command}");

It moves first to your root directory and run composer from there.

kay899's avatar

Just to show what I am doing:

https://paste.laravel.io/e225868e-572d-413e-b73d-192f5ddad8b7

I work with October CMS, but this is based on Laravel and what I see Jobs is nearly the same.

I go to my folder, clone the Plugin I need. This Plugin has a composer.json with some required Laravel Plugins. So I try to perform the composer updtae to load them.

But composer does not run. I also do not get any real error message, so I have no idea what is happening.

click's avatar

@kay899 see my comment. Depending on your requirements you first need to go to the correct path, than execute the command. The same way you do a git clone in your example code.

martinbean's avatar

@kay899 Why are you trying to run Composer like this? What happens if Composer updates a package to a version that’s incompatible with your application and introduces a bug?

kay899's avatar

I know that this is a risk, but in the moment I don't see another solution.

AsI said I am working with October CMS and the use of Private Plugins is sometimes very hard. As long as they don't have any dependencies with other packages it's ok juts to install and update them with git.

But now I have a Vouchershop package which needs a " gloudemans/shoppingcart" plugin. I have added this to composer.json of my Package and now I somehow have to start the process to load this package.

martinbean's avatar

@KAY899 - @kay899 If you’re installing a plugin, install it and run composer update then? You only need to do this once: when you’re installing the package.

You should not but updating packages on a schedule. For example, if a package changes location or is removed from its repository, the next time your scheduled tasks updates dependencies, it’s either going to error or remove that package from your server. Either way, your application is going to crash if it depends on it.

Please or to participate in this conversation.