HI,
I’m running the Grav CMS on shared hosting, so there is no possibility to run the command “bin/grav clear-cache“
Has someone used the PHP script to clear the cache on shared hosting?
HI,
I’m running the Grav CMS on shared hosting, so there is no possibility to run the command “bin/grav clear-cache“
Has someone used the PHP script to clear the cache on shared hosting?
There is a clean cache button in the BE. Just look closer or read the manuals
Read carefully: “Clear cache with CLI on a shared hosting”
Of course I know about the button on backend, it’s not related to my question
But your main question was:
That button calls a PHP script. Just check the endpoint
You mean Admin plugin front end, I think. And there’s nothing wrong with this suggestion since OP did not explain why CLI is required. The question seems oxymoronic to me.
So feel free to tell us what kind of shared hosting and whether you have something like CPanel available. I think if you have one of those webmin server front end thingies that shared hosts use, you can often run PHP scripts with arguments like clear-cache from their Cron front ends. You might need to set up a job for a specific date and time and then reset its time each time you want to run it. Some of them have a “run now” button, and some of them let you keep the job saved in a disabled state. Would have been good to have more details from you.
Hi,
In my CPanel, I’m able to run the PHP script, which could trigger further operations.
So, I need a php script which could launch the clear cache regular process
I’m surprised to only see a URL field here. Usually there’s a “command” field instead.
Maybe first try to grab the endpoint address as @Karmalakas suggested and put that into the field. However, I am pretty sure that won’t run outside of being logged into Admin.
With a “command” cron field on shared hosts, it would be something like /path/to/grav-root/bin/grav cache-clear.
But .. we still don’t why you’ve framed this question requiring CLI. You don’t have to tell us but it seems like useful context.
I would use Grav’s scheduler to run regular cache clearing. It’s actually all outlined in the docs including that exact task. As described, you will need to set up a cron task on your shared host to trigger Grav’s scheduler.
Thanks, but that’s exactly my point — on shared hosting I can’t run CLI commands like bin/grav cache-clear or bin/grav scheduler.
The only thing I can do is execute a PHP script from inside CPanel (for example, through a web-accessible file or cron job that just runs php script.php).
That’s why I’m looking for a pure PHP solution that could internally trigger Grav’s cache clear mechanism — basically something equivalent to what the Admin plugin does when pressing the “Clear cache” button, but callable without logging into Admin.
The Scheduler is great, but since it still requires a CLI trigger, it doesn’t solve the limitation of shared hosting.
Either I’m missing something or you are, here ..
(Often it’s me that missed something!)
You don’t need CLI to run Grav’s scheduler as long as your webmin supports running commands as the web user (www-data or whatever, which it usually does, or sometimes shared hosts configure webservers to run as your user account).
You should be able to configure your scheduler task to run cache-clear either through Admin or by editing user/config/scheduler.yaml.
Then you just need to add Grav’s scheduler to your cron with their webmin tool. It might be a bit of trial and error to get the right parameters for the fields since you can’t run bin/grav scheduler -i. (If you have direct file access to edit your user crontab tool, that might be simpler.) But you’ll want something equivalent to * * * * * cd /Users/andym/grav;/usr/local/bin/php bin/grav scheduler 1>> /dev/null 2>&1 as per the example. (A lot of the example looks local Mac-centric to me.)
That’s assuming you have a cron front end field to run a command and not just “URL”. Maybe that’s what I didn’t follow.
@01K, Is running $ bin/grav cache really nescessary?
All it does is removing one or more folders (depending on options) from directory /cache.
Can’t you run:
rm -rf ./cache/*, or with a specific directory?unlink?I think the misunderstanding is here:
On my shared hosting, the cron tool does not allow running commands like php bin/grav scheduler — there’s no command field, only a URL field (as shown in my screenshot).
That means I can only trigger a PHP script or URL, not execute anything via CLI.
So the question is specifically about how to trigger Grav’s cache clear process from a PHP script, without using CLI and without being logged into Admin.
I totally understand how the Scheduler works and how to configure it — but since I can’t call bin/grav scheduler, it’s unfortunately not an option in this hosting setup.
That’s why I’m looking for a small internal PHP script that calls the cache clear function directly (the same thing Admin does when pressing “Clear cache”).
Since I can’t run shell commands on this shared hosting, a small PHP script that calls Grav’s cache clear API internally would be ideal
@01K,
unlink,$cache = Grav::instance()['cache'];
$cache->driver->deleteAll();
I manage multiple Grav sites on shared hosting, and manually clearing cache from Admin each time is time-consuming.
Your approach with a small plugin or PHP endpoint sounds like what I need — something callable via a URL or from cPanel that internally triggers Grav::instance()['cache']->driver->deleteAll() ).
Thanks for this! I’ll give it a try.