Linux commands through Laravel

Asked

Viewed 395 times

0

I’m creating some custom commands in Laravel as per the documentation: https://laravel.com/docs/5.4/artisan

ex:

php artisan gestao:config

This command allows me to automatically configure some things in my application, such as migrate and Seeds of my application.

What I would like to know is if it is possible to run in addition to the Artisan commands, some native linux commands, for example: sudo chmod -R 775 /var/www/laravel/storage

1 answer

1

You can do it using the "process" component (Laravel 5) http://symfony.com/doc/current/components/process.html

You can also invoke PHP’s own functions
http://php.net/manual/en/function.exec.php,
http://php.net/manual/en/function.shell-exec.php

Or, in Laravel (4.2), the component SSH

Obviously, any of the means you choose requires levels of execution permission. This depends on the permissions in the Operating System.
I comment on this due to sudo in the command he presented in the question.

Which option to choose? It depends on what you want to do. There is no rule that forces you to use Artisan or condemns it for using PHP’s own functions.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.