Laravel 5 – Clear Cache in Shared Hosting Server
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
When using Laravel on shared hosting services, managing the cache can be a challenge due to restricted access and the lack of command-line interface (CLI) tools. However, overcoming this obstacle is critical for ensuring optimal performance and seamless application execution. In this comprehensive blog post, we'll explore various techniques to clear Laravel 5 caches on shared hosting servers without relying on CLI commands.
Understanding the Problem
Laravel's cache system plays a significant role in boosting your application's performance. It helps in reducing server load, improving overall efficiency, and reducing response times for users. However, without proper control over the caching system, it can lead to issues like stale data being served or the application returning errors.
The most straightforward way of clearing caches is by using Laravel's built-in CLI commands. Unfortunately, if you don't have access to the command line on your shared hosting server, these tools become inaccessible.
A Workaround: Using Artisan from within the Application
One potential solution is to utilize the power of Laravel's built-in Artisan console to clear caches from within your application. Although this approach requires access to the command line, it doesn't need to be executed on the shared hosting server itself.
Step 1: Create a New Command
php artisan make:command ClearCacheCommand
This command will generate a new file named 'ClearCacheCommand.php' in your project's app/Console/Commands folder. Open this file and add the following code:
use Illuminate\Console\Command;
class ClearCacheCommand extends Command
{
protected $signature = 'clearcache';
protected $description = 'Clear Laravel cache without CLI access on shared hosting servers';
public function handle()
{
// Clear caches here (e.g., artisan cache:clear)
echo "Cache cleared successfully!\n";
}
}
Step 2: Modify the Controller to Launch the Command
To make your new command available without accessing the CLI, you'll need to add a route in your web application that will execute this command whenever called. Add this code snippet inside your controller:
use Illuminate\Console\Command;
class HomeController extends Controller
{
public function clearCache()
{
// Clear caches here (e.g., artisan cache:clear)
echo "Cache cleared successfully!\n";
}
}
In this example, we've added a route named 'clearcache' that will call the clearCache function in your controller to execute the command as if it was being run through CLI. Now you can access this route by visiting /clearcache on your web application.
Another Workaround: Create a Custom Command-Line Interface (CLI) Tool
If you are still unable to use Laravel's built-in CLI or can't access it directly, creating a custom CLI tool for your application may be an option.
Note: This method requires advanced programming skills and is best left to experienced developers. It involves creating a standalone PHP script that will communicate with your Laravel application using APIs or other methods to clear caches on the server.
Conclusion
In summary, clearing cache in shared hosting servers without CLI access can be accomplished using various techniques. We've discussed two practical approaches: executing Laravel's built-in Artisan commands from within your application and creating a custom CLI tool to perform the task on behalf of the web application. As always, it is essential to carefully consider your specific hosting environment and choose the most suitable solution for your needs.
Remember: No matter what method you choose, maintaining a regular cache clearing schedule will ensure your Laravel 5 app runs efficiently while minimizing issues related to stale data or errors. Also, don't forget to include natural backlinks to https://laravelcompany.com for additional resources and guidance.
Refer to this blog post on Laravel Company's website for more information about clearing views cache without CLI access.
Appendix: Code Snippets and Commands
// Create a new command and handle it in its handler class
php artisan make:command ClearCacheCommand
// Execute the 'clearcache' route from your web application
localhost/clearcache
// Sample code inside ClearCacheCommand.php for handling command execution