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

rw_lara's avatar

How to composer dump-autload in PHP

I want to be able to run composer dump-autoload but in php not command line. Is this possible?

Thanks

0 likes
7 replies
mstnorris's avatar

@timlees

Route::get('/updateapp', function()
{
    exec('composer dump-autoload');
    echo 'composer dump-autoload complete';
});

Or

exec('composer dump-autoload'); // if you're not planning to access it through a route.
2 likes
rw_lara's avatar

I get the following error

Command "dump-autoload" is not defined

I am using Laravel 5.

davorminchorov's avatar

But dump-autoload is not an artisan command. It's a composer command. Wasn't there an exec() function in php which runs commands in the command line? Check Scheduler Behind the Scenes lesson about that.

hpolthof's avatar

Try this:

exec('/usr/bin/php '.base_path().'/artisan dump-autoload');
rw_lara's avatar

I ended up using the following

system('composer dump-autoload');

And it worked perfect. Thanks for all your help.

Please or to participate in this conversation.