laravel 我如何在 cpanel 中运行工匠命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47711072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can i run artisan commands in cpanel
提问by Ronald Torres
How can i run these artisan commands in my application that is hosted in the net? Is there like a cmd in my cpanel where i can do these commands? Thanks in advance.
如何在托管在网络中的应用程序中运行这些工匠命令?我的 cpanel 中是否有一个 cmd 可以执行这些命令?提前致谢。
- php artisan clear:cache
- php artisan view:clear
- php工匠清除:缓存
- php工匠视图:清除
回答by Moslem Ch
You can make a personalized route, and call it when you need it:
您可以制定个性化路线,并在需要时调用:
Route::get('/clear-cache', function() {
$output = new \Symfony\Component\Console\Output\BufferedOutput;
\Artisan::call('cache:clear', $output);
dd($output->fetch());
});
Another solution is to access ssh to your server and to run the commands.
另一种解决方案是通过 ssh 访问您的服务器并运行命令。
回答by Mudassar045
Now in Laravel 5.8, you cannot pass objectto call()func. You must pass an array []as second argument to call() func.
现在在 Laravel 5.8 中,你不能将对象传递给call()函数。您必须将数组 []作为第二个参数传递给 call() func。
Route::get('/clear-cache', function() {
$output = [];
\Artisan::call('cache:clear', $output);
dd($output);
});
回答by Bogdan Stoica
You could create a simple bash script called clear-cache.sh like this:
您可以像这样创建一个名为 clear-cache.sh 的简单 bash 脚本:
#!/bin/sh
PHP=/path/to/your/php-binary
PATH=/path/to/your-artisan-install
cd $PATH
$PHP artisan clear:cache
$PHP artisan view:clear
Save the script and make it executable (chmod +x clear-cache.sh). Run it through a cronjob at specific intervals and configure the cron job to email you the output of those 2 commands. This way you'll get an email, every time the cron runs the script (basically the cron will automatically issue your two commands) and the ouput will be emailed to you.
保存脚本并使其可执行 (chmod +x clear-cache.sh)。以特定时间间隔通过 cronjob 运行它,并配置 cron 作业以通过电子邮件将这 2 个命令的输出发送给您。这样你会收到一封电子邮件,每次 cron 运行脚本(基本上 cron 会自动发出你的两个命令)并且输出将通过电子邮件发送给你。
Of course there are other methods as well like creating a php script and invoke it via web
当然还有其他方法,比如创建一个 php 脚本并通过 web 调用它
回答by Nazmul Hasan
Try this. You can clear all of laravel application cache hosted in shared hosting server that can not access ssh shell by the following code:
尝试这个。您可以通过以下代码清除无法访问 ssh shell 的共享托管服务器中托管的所有 Laravel 应用程序缓存:
Route::get('/cleareverything', function () {
$clearcache = Artisan::call('cache:clear');
echo "Cache cleared<br>";
$clearview = Artisan::call('view:clear');
echo "View cleared<br>";
$clearconfig = Artisan::call('config:cache');
echo "Config cleared<br>";
$cleardebugbar = Artisan::call('debugbar:clear');
echo "Debug Bar cleared<br>";
});
Now run yourdoamin.com/cleareverything
现在运行 yourdoamin.com/cleareverything
This code does not throw any error. I already used this code.
此代码不会引发任何错误。我已经使用了这个代码。
Ref : https://laravel.com/docs/5.2/artisan#calling-commands-via-code
参考:https: //laravel.com/docs/5.2/artisan#calling-commands-via-code