Skip to main content

What is ClamAV?

ClamAV (Clam AntiVirus) is an open-source antivirus engine designed for detecting malwares, viruses, and other malicious threats. It is widely used for scanning file servers, and web applications. ClamAV is known for its lightweight nature and ability to be integrated into various security systems. Logo ClamAV

Why integrate ClamAV into your web application?

Integrating ClamAV into a web application, provides several security benefits:
  • Protect uploaded files: If your application allows users to upload files, scanning them for viruses ensures that no malicious files enter your system.
  • Regulatory compliance: Many industries require businesses to scan files for malware as part of cybersecurity compliance.
  • Prevent system contamination: Detecting and removing infected files early prevents malware from spreading across your infrastructure.
  • Increase user trust: Ensuring that files are clean enhances trust in your platform, especially in cloud-based environments like Upsun.
In this tutorial we will be implementing ClamAV in one-time scan.

Using ClamAV with service mode vs one-time scan mode

There are two possible (and cumulative) policy approaches to file verification with ClamAV:
  • One-time scan mode: This mode of ClamAV allows the user to scan an entire file tree without distinction. A pro is that all files can be scanned, however this does take a considerably long amount of time to process all the verifiers - which some may consider to be a con.
  • Service mode: This mode of ClamAV allows the user to scan specific files on demand. eg. the user uploads 3 new files and scans only these. A pro is that this process is very fast, due to the limitation of files to be processed, however a con is that it also requires communication between the application and the antivirus.
This tutorial covers how to run ClamAV in one-time scan mode. Another ClamAV integration approach in service mode in this article.

Setting up ClamAV

Add ClamAV binary

To use ClamAV on Upsun, you need to install the ClamAV binaries.
Let’s use Upsun composable-image to add ClamAV to our application container:

Add ClamAV configuration

After adding the ClamAV binaries, you need to configure ClamAV (see the full ClamAV documentation here). This involves modifying two configuration files to add on the reposotory project, each corresponding to one of the two main commands: This includes updating the virus database (aka freshclam). Create these 2 files, etc/freshclam.conf and etc/clamd.conf, with the following:
As well as the configuration of ClamAV itself (for the scan, aka clamscan).
The storage locations for the virus database and the configuration files have been modified to adapt them to Upsun. These modifications were made by adding DatabaseDirectory and NotifyClamd to the mount points with write permissions.

Add mount endpoint for storage

Since ClamAV needs to write to the disk, we must add appropriate mount points with the necessary write permissions.
Additionally, these mount points must have a specific directory structure.
To do this, let’s combine everything into a shell script to set up this structure (on the repository project), that will be executed during each deployment to ensure the structure’s existence.
You will note the use of the built-in variable PLATFORM_APP_DIR to define the application’s default path. And let’s add execution permissions to the script.
This script can only be executed once the mount points are mounted, which is done in Upsun during the deployment step.
To automate this, we will add the script call to the deployment hooks.

Deploying ClamAV on Upsun

We need to push these additions to the Upsun project. (If you don’t have one, create a project on Upsun.)
Finally, ClamAV requires a minimum set of resources to function properly, particularly for logging and updating its virus database. Therefore, it’s important to fine-tune and allocate sufficient resources - such as memory and disk I/O - to ensure optimal performance:
  • Disk : > 800Mb
  • Memory : > 1.5Gb
Use this command line to upsize disk:
and add container_profile parameters in your clamav settings:

Test the ClamAV integration on Upsun

After the deployment, test that everything works as expected by opening an SSH connection:
Let’s start by triggering the update of ClamAV’s virus database.
To check that it’s working as expected, let’s create a file that simulates an infected file:
Now, let’s run a scan:

Automating updates and scans

In order to automate the database updates and the scans, we will be grouping all the necessary commands into shell scripts to make their usage easier:
Now let’s add execution permissions to the script.
Then, automate these step by setting up some Crons:
Finally, commit everything:

Extra feature

You can use runtime-operation provided by Upsun to trigger a new scan:

Declare runtime operation

Call runtime operation

Then, trigger this runtime operation from your development machine (or any other environment with access to the Upsun CLI).

Conclusion

By following this guide, you have learned how to set up ClamAV on Upsun, utilizing features like Upsun composable-image and deployment hooks to automate updates and scans. This approach not only strengthens your infrastructure’s security but also enhances user trust, especially in cloud environments like Upsun. With proper configuration and automation scripts, ClamAV can be a powerful tool for maintaining system integrity while remaining lightweight and easy to integrate. Another ClamAV integration approach in service mode in this article.
Project on our Github Upsun
Last modified on April 17, 2026