GUIDE CREATE A CRON TASK IN CPANEL (II) – DELETE JOOMLA 2020 CACHE AND TEMPORARY FILES -WAU

Home/Posts/Administración del Hosting/GUIDE CREATE A CRON TASK IN CPANEL (II) – DELETE JOOMLA 2020 CACHE AND TEMPORARY FILES -WAU

Create a cron task in CPanel (II) - Delete Joomla cache and temporary files

In the first chapter of this series dedicated to cron and scheduled tasks we learned about the tools that are available in the Hosting Panel (cPanel) and how to build scripts that can be executed automatically and scheduled.

Since the tasks must be applied to specific actions, we will focus in this chapter on the scheduling of tasks or crontabs that allow us empty certain folders that periodically fill with temporary or cached files from our Joomla website.

When we manage a single Joomla website it may be relatively easy to maintain it, regularly clean the cache, either manually or through an extension such as Cache Cleaner, or empty temporary files folder and in this way avoid that these files gradually go consuming hosting space that we need for other more important things.

The normal thing would be to use the tools of the Joomla backend to purge said cache and to zero the aforementioned folder, but many users, without time, due to forgetfulness or ignorance, stop doing this task and in the end it ends up becoming a consumer of space not checked.

By default, any Joomla installation manages the CMS or extensions cache by storing the files in the folder / public_html / cache or / folder / where_is_installed_joomla / cache and the same for the storms that are stored in / public_html / tmp or / folder / where_is_installed_joomla / tmp so that with the passage of time, if these folders are not emptied, many files that occupy space in the Hosting end up accumulating.

Depending on the number of extensions we use and the frequency with which we install new extensions, the / tmp folder will have the files used to install templates, plugins, modules or components and if we have never emptied this folder we are likely to be surprised by the number extensions and templates installed that have left temporary traces.

We can schedule a task that once a week (or daily), depending on the activity that we develop as administrators on the web, empty the folders /cache and / tmp so that we recover that occupied space and keep the Hosting account more healthy.

How to schedule a cron task to empty / tmp and / cache from Joomla?

We solve it with a scheduled Task, which requires a few minutes to start and forget about manually deleting these files from now on.

The summarized process is as follows:

  1. Access cPanel, Advanced, Cron jobs.
  2. Add the following command lines (in different cronjob) to run once a day during a time that you have no traffic on the site (for example at 3 am) to empty the folder / public_html / cache (or the folder where your Joomla installation manages the cache):

To recursively delete folders and their corresponding files:

find /home/pruebasw/public_html/sport25/cache/ -mindepth 1 -type d -exec rm -rf  {} ;

To delete the files that are directly in the cache folder:

find /home/pruebasw/public_html/sport25/cache/ -mindepth 1 -type f -exec rm -rf  {} ;

Note: If the Joomla website is in another folder -because we have several websites installed- different from / public_html then we must indicate the path after find, if it is in the / public_html / sport25 folder then we will add / home / testsw / public_html / sport25 / cache / as shown in the example.

This same task can be applied to empty the folder / tmp deleting the temporary files that are generated in Joomla.

Sintasix to find:

find [-H] [-L] [-P] [ruta...] [expression]

-mindepth n = True if the depth of the current file in the tree is greater than or equal to n.

Note: Paths must precede the expression.

Commands for rm:

-F = –Force – Does not ask for confirmation. Does not write diagnostic messages. It does not produce an error exit status if the only errors have been files that do not exist.

-r = –Recursive (can also be R) – Repeatedly delete directories and subdirectories in the argument list. The directory will be emptied of files and removed. Typically the user is prompted before deleting any write protected file containing the directory.

The action of ‑Exec it takes a command as an argument (along with its options). The arguments must contain {} (usually quoted), which is replaced by the file name found in the command. The command ends with a semicolon, which must be quoted (escaped) to pass with the find command.

Practical case:

As an example we can see that we have a Joomla installation in the Hosting / public_html / esport25 folder and inside, in the / cache folder, numerous files and folders that in turn contain files and more folders.

Once we program a cron task and add the appropriate command to periodically empty the / cache folder, we can see, after executing the cron, that the folder has been emptied completely:

These types of tasks are useful for keeping empty folders like / cache or / tmp in Joomla, which are the usual collectors of temporary files coming from the installation of extensions, templates, etc., and / or the folder / cache that sometimes, depending The amount of extensions that we use can occupy a considerable space in the Hosting.

If you want to know in more detail contrab You can check at the following link.

Member of the Websites Are Us technical team.
Coordinator of content on the Blog and YouTube.
Technical support in CyberProtector. Teacher at Websites Are Us Learning.

By |2020-05-12T01:32:28+00:00May 12th, 2020|Administración del Hosting|