I tried this command
Route::get('/updateapp', function()
{
\Artisan::call('dump-autoload');
echo 'dump-autoload complete';
});
and the page display this error:
The command "dump-autoload" does not exist.
I can't use exec() system() so I need to create this method/command.
I reviewed other questions but I'm confused help me please! I'm newbie
\Artisan::call('dump-autoload');
This command called above command
php artisan dump-autoload
You must use from command
And write in anywhere from php script
exec('composer dump-autoload');
Related
I need to execute shell commands from controller , but not only for files inside the project , ex. system('rm /var/www/html/test.html') or system('sudo unzip /var/www/html/test.zip');
I call the function but nothing happen , any idea how to execute external shell commands from controller like removing one file in another directory?
system('rm /var/www/html/test.html');
//or
exec('rm /var/www/html/test.html')
If you're wanting to run commands from your PHP application I would recommend using the Symfony Process Component:
Run composer require symfony/process
Import the class in to your file with use Symfony\Component\Process\Process;
Execute your command:
$process = new Process(['rm', '/var/www/html/test.html']);
$process->run();
If you're using Laravel, you should be able to skip Step 1.
Alternatively, (if the process running php has the correct permissions) you could simply use PHP's unlink() function to delete the file:
unlink('/var/www/html/test.html');
I would do this with what the framework already provide:
1) First generate a command class:
php artisan make:command TestClean
This will generate a command class in App\Console\Commands
Then inside the handle method of that command class write:
#unlink('/var/www/html/test.html');
Give your command a name and description and run:
php artisan list
Just to confirm your command is listed.
2) In your controller import Artisan facade.
use Artisan;
3) In your controller then write the following:
Artisan::call('test:clean');
Please refer to the docs for further uses:
https://laravel.com/docs/5.7/artisan#generating-commands
Use fromShellCommandline to use direct shell command:
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
Process::fromShellCommandline('rm /var/www/html/test.html');
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
When you use php artisan in the command line you get a list of all commands. Are there any opportunity to get all Laravel artisan commands programmatically? I need it for example to use it in a select field in the interface.
To get all command objects:
\Artisan::all()
To get all command names:
array_keys(\Artisan::all())
use Illuminate\Contracts\Console\Kernel;
...
$commands = resolve(Kernel::class)->all();
Use shell-exec command.
http://php.net/manual/en/function.shell-exec.php
$output = shell_exec('php artisan');
echo $output;
if I understand the query correctly, you can use CLI (eg bash in debian) to:
&& for individual calls - each subsequent call will be made after the previous performance, eg:
php artisan migrate:fresh && php artisan fixtures:up && php artisan db:seed && php artisan serv
aliases entered in .bash_profile
alias migrate = "php artisan migrate"
and using command migrate in Laravel project.
info: https://gist.github.com/JeffreyWay/5542264
You can put them in your routes like this:
Route::get('/foo', function()
{
$exitCode = Artisan::call('command:name', ['--option' => 'foo']);
//
});
https://laravel.com/docs/5.0/artisan#calling-commands-outside-of-cli
I'm developing a Symfony project and I've 4 commands which allows me to update telephony and emails data thanks to OVH' Api. When I use my terminal on local ( php bin/console converseo:updateTelephony ) the command works fine.
Now, I want to put these commands in crontab with the cron interface from Ovh. I made a php file test.php :
<?php
shell_exec("sh test.sh");
?>
And test.sh :
#!/bin/bash
/usr/local/php5.6/bin/php /homez.number/mysite/www/bin/console converseo:updateBilling
And I get the error :
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "converseo:updateBilling" is not defined.
Did you mean one of these?
converseo:updateBilling
converseo:updateEmailCount
converseo:updateTelephony
converseo:updateEmail
The lines are EXACTLY the sames, I don't understand why I get this error.
Thanks a lot for yours answers !
I've tried this:
php /home/public_html/artisan command:foo test
and I get this error:
No input file specified.
how can I get the exact path to my artisan to execute this??
This is what worked for me:
/usr/local/bin/php public_html/artisan foo
I am trying to run a command on windows which is the follwing :
sfm+pmvs C:\\xampp\\htdocs\\temp\\$filename/ hello.nvm
I have done this but it wont work for me :
exec("C:\\xampp\\htdocs\\temp\\draw\\VisualSFM_win32.exe sfm+pmvs C:\\xampp\\htdocs\\temp\\$filename/ hello.nvm");
when I do the following :
exec("C:\\xampp\\htdocs\\temp\\draw\\VisualSFM_win32.exe");
it works just fine but I need the other paramters to be included in the command line
how could that be done in php and is there any way to open a cmd.exe and to run the command above ?
thanks in advance
Exec() just running in cmd command which you wrote as first argument of exec(). If VisualSFM_win32.exe not support arguments by run via cmd, you cannot run it as you want. Sorry for my english =)
You asked me for exapmle. My example below.
I am not sure it is 100% right because i don't use windows last 3 years.
#echo off
cd "C:\xampp\htdocs\temp\draw\"
start VisualSFM_win32.exe sfm+pmvs C:\xampp\htdocs\temp\%1/ hello.nvm
and in php
exec("C:\\test.bat " . $filename);