Home » Run php artisan Commands On Shared Hosting Servers

Run php artisan Commands On Shared Hosting Servers

Last updated on June 12, 2020 by

Often, the developer struggles to run php artisan commands on shared hosting servers because shared hosting does not provide any terminal or command-line tool to run a php artisan commands. So let’s see how to do it.

Table of Contents
1. When Do You Need To Run php artisan Commands On Hosting?
2. Run php artisan Commands Using Route
3. Run config:clear in Shared Hosting Server
4. Run config:cache in Shared Hosting Server
5. Clear Cache in Shared Hosting Server
6. Clear View in Shared Hosting Server
7. How To Test Commands?

When Do You Need To Run php artisan Commands On Hosting?

Well, we all know that we can easily run all php artisan commands in our local development environment using different command-line tools, but it seems tough to remove the cache, compiled views, routes, etc. on the shared hosting servers because they do not provide a shell, terminal or any other command-line tool. While all that you get into the dedicated hosting and VPS servers.

Let’s crack it together. We presume that you know all about the Laravel basics.

Run php artisan Commands Using Route

To run any php artisan commands by using route you just need to create a route and need to add command by using the following syntax:

Artisan::call(your-command);

01 Run config:clear in Shared Hosting Server

Route::get('/config-clear', function() {
    Artisan::call('config:clear');
    // Do whatever you want either a print a message or exit
});

02 Run config:cache in Shared Hosting Server

Route::get('/config-cache', function() {
    Artisan::call('config:cache');
    // Do whatever you want either a print a message or exit
});

03 Clear Cache in Shared Hosting Server

Route::get('/cache-clear', function() {
    Artisan::call('cache:clear');
    // Do whatever you want either print a message or exit
});

04 Clear View in Shared Hosting Server

Route::get('/view-clear', function() {
    Artisan::call('view:clear');
    // Do whatever you want either print a message or exit
});

How To Test Commands?

Let’s assume that your website domain is example.com, then If you want to clear the cache then you need to run example.com/cache-clear as defined above.

A blank screen will appear as per the above examples and if you add any messages, dd(), exit(), etc. in the above routes then it will behave according to that.

Additionally, Check out our guide: Best Way to Remove Public from URL in Laravel

That’s it for now. We hope this article helped you to learn how to run php artisan commands on live servers.

Please let us know in the comments if everything worked as expected, your issues, or any questions. If you think this article saved your time & money, please do comment, share, like & subscribe. Thank you in advance 🙂. Keep Smiling! Happy Coding!

 
 

Leave a Comment