Laravel 5.3 - Clear config cache in shared hosting
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
Title: Laravel 5.3 - Overcoming Config Cache Challenges on Shared Hosting Environments
Body:
Working with shared hosting for your Laravel project is not an ideal solution, but it can be done. Unfortunately, some providers implement strict security measures that could limit the functionalities we are accustomed to using when working on a more advanced platform. One such limitation is the disabling of the escapeshellarg() function. This poses challenges when clearing the configuration cache with php artisan config:cache. So, how can you overcome this issue and ensure your Laravel application runs optimally? Let's walk through the process.
Approach 1: Using Composer's Scripts
If your shared hosting platform allows access to composer.json files, consider adding a post-update script that automatically clears the config cache. This option is straightforward and can be easily implemented. Here's how you can implement this approach: 1. Open your Laravel project's composer.json file. 2. Add the following code snippet beneath the "scripts" section:
"post-update-cmd": [
"php artisan optimize",
"php artisan config:cache",
]
The above script will run first the optimizer to clean up your application's autoloader and then execute the config cache clear command. Now, whenever you update your composer dependencies, this script will take care of clearing the config cache automatically.
Approach 2: Manual Cache Clearing
If you can't modify your composer.json file or don't want to use it for this purpose, you can manually clear the config cache using command line tools. To do this, follow these steps: 1. Create a bash script named "clear_cache.sh." 2. Add the following code snippet in the shell script:
#!/bin/bash
php artisan config:clear
3. Make the shell script executable by running chmod +x clear_cache.sh.
4. Save and upload the bash script to your shared hosting server, ensuring it is in the project root directory.
5. Execute the script using the command ./clear_cache.sh from the command line interface (CLI) of your terminal. This will clear your config cache.
Approach 3: Using a Scheduled Task or Cron Job
If you're hosting the Laravel application on shared hosting with limited access to the server environment, you can try using a cron job to clear the configuration cache at regular intervals. Follow these steps: 1. Create a new PHP script named "clear_cache_cron.php" in your Laravel project folder. 2. Include the following code snippet inside this file:
3. Save and upload the PHP script to your shared hosting server, ensuring it is in the project root directory.
4. Navigate to the cPanel or any other web-based control panel provided by your host. Locate the cron jobs section and create a new schedule for running your clear_cache_cron.php file at an appropriate time interval, such as once per hour.
5. Save the new cron job. Your configuration cache will now be cleared automatically at the specified intervals.