Run artisan commands on shared hosting server (Laravel)

| By Webner

Run artisan commands on shared hosting server (Laravel)

Laravel is a popular and excellent framework of php. It provides many functionalities out of the box like authentication, events, job queues, artisan commands and many more.

A problem on shared hosting- When we deploy our laravel project on a shared hosting then we are unable to run artisan commands of the laravel. We need to clear configurations and cache of the project whenever we change the configurations of the project. Otherwise, we need to reupload the project to the server and it is difficult to upload the project again and again on the server.
If we use a dedicated server for laravel project like EC2 or any other server, we do not need to worry about these things because we can run the commands on server as we can run on local machine.

Solution- We can handle this problem and can clear configurations and cache without uploading the whole project. We can run the artisan commands from the browser. Follow the below steps and we are good to run the artisan commands.

1. Open the web.php file which is in the “route” folder of your project and paste the below code.

//Clear configurations:
			Route::get('/config-clear', function() {
				$status = Artisan::call('config:clear');
				return '<h1>Configurations cleared</h1>';

//Clear cache:
			Route::get('/cache-clear', function() {
				$status = Artisan::call('cache:clear');
				return '<h1>Cache cleared</h1>';

//Clear configuration cache:
			Route::get('/config-cache', function() {
				$status = Artisan::call('config:Cache');
				return '<h1>Configurations cache cleared</h1>';

2. Now save this and hit the defined routes in the browser and these will run the artisan command and will clear the configuration, cache and configuration cache. Now you do not need to re-upload the whole project.

If you want to run any other command, just do an entry in the web.php and assign it a route and hit that route in your browser.


Leave a Reply

Your email address will not be published. Required fields are marked *