skip to Main Content

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.

  • php artisan clear:cache
  • php artisan view:clear

4

Answers


  1. You can make a personalized route, and call it when you need it:

    Route::get('/clear-cache', function() {
        $output = new SymfonyComponentConsoleOutputBufferedOutput;
        Artisan::call('cache:clear', $output);
        dd($output->fetch());
    });
    

    Another solution is to access ssh to your server and to run the commands.

    Login or Signup to reply.
  2. 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:

    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

    This code does not throw any error. I already used this code.

    Ref : https://laravel.com/docs/5.2/artisan#calling-commands-via-code

    Login or Signup to reply.
  3. You could create a simple bash script called clear-cache.sh like this:

    #!/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.

    Of course there are other methods as well like creating a php script and invoke it via web

    Login or Signup to reply.
  4. Now in Laravel 5.8, you cannot pass object to call() func. You must pass an array [] as second argument to call() func.

    Route::get('/clear-cache', function() {
        $output = [];
        Artisan::call('cache:clear', $output);
        dd($output);
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search