Scanning Moodle uploads with ClamAV

Connecting ClamAV to a self-hosted Moodle site so uploaded files are scanned, with the daemon mode, permissions and failure behavior chosen before go-live.

On this page

Why Moodle upload scanning with ClamAV needs a planned setup

If your self-hosted Moodle lets students and staff upload assignments, files and course content, ClamAV scanning adds a malware check on those files before other users or your staff open them. Turn it on as soon as uploads come from people you do not fully control, such as external learners, guest accounts or contractors, and before you open assignment submissions to large cohorts. The antivirus plugin sends each uploaded file to a ClamAV engine and acts on the verdict, so the value depends on the scanner actually running for every upload path your site offers.

The integration depends on the server setup, which makes it a planning decision rather than a checkbox. Moodle has to reach the scanner through a command line call, a Unix socket or a TCP daemon, and each option has different requirements for the process that runs PHP and for the file permissions of the ClamAV user. Confirm which method your hosting model supports, who owns the ClamAV service and its virus definition updates, and whether the web server user can read the files Moodle hands to the scanner. Check the current plugin documentation for the exact settings your Moodle version expects before you test.

Moodle core includes an infected files report (report_infectedfiles) that lists files flagged during scanning, so administrators can review findings instead of searching logs. Plan who receives that review, how often it happens and what the response is when a file is flagged, including how the affected user is notified and whether the file is quarantined or removed. Also decide what happens when the scanner is unreachable. Whether uploads are blocked or accepted without a scan is a security decision that should be written down and tested, not left to the default.

Before go-live, run test uploads with a harmless test signature that the scanner flags, confirm the report shows the file, and verify that a stopped or misconfigured scanner produces the behaviour you chose. Ask your implementation partner or internal team to document the scan method, the service account, the permission model and the failure policy in the same runbook as your backup and patch routine, so the control survives upgrades and staff changes.

Choosing command line, Unix socket or TCP daemon mode

This table compares the three ways Moodle can call ClamAV: the clamscan command line tool, a clamd daemon over a Unix socket, and a clamd daemon over TCP. Read each row against your server layout, since the right choice depends on where the scanner runs and how many web nodes share it. The main takeaway is that the daemon modes trade extra permissions and exposure for faster scans under upload load.

FactorCommand line (clamscan)Unix socket or TCP daemon (clamd)
Where the scanner runsStarts a new process on the web server for each scanA long-running clamd service, on the same host (socket) or a separate host (TCP)
File access neededThe web server user must read the uploaded file and the scanner's database filesSocket: clamd must read the uploaded file path. TCP: the file contents are streamed, so clamd needs no access to the Moodle data directory
Network exposureNone beyond the local processSocket: local only, controlled by socket file permissions. TCP: a listening port that must be restricted by firewall and bind address
Load on a busy upload siteEach upload pays the cost of loading virus signatures, which adds delay under concurrent uploadsSignatures load once at daemon start, so scans are faster and more consistent under concurrent uploads
Single server fitUsually sufficient for a small site with light upload trafficSocket suits a single server well; keeps the scanner local with no network hop
Multi-node or containerized fitPoor fit, because every web node needs the scanner binary and signature databaseTCP suits web nodes sharing one scanner service; confirm the scanner's memory needs and restrict who can connect
Permissions to confirmConfirm the web server user can execute the scanner and read the signature databaseConfirm the clamav service user owns the socket or port setup and that Moodle's configured path or host matches the daemon

Setting up ClamAV for Moodle step by step

This sequence takes a self-hosted Moodle from no antivirus to a working scan path: a running ClamAV service with current signatures, a chosen connection mode, file access that matches that mode, a Moodle setting that enables scanning, and a verified test with a harmless file.

  1. Install ClamAV and confirm signature updates

    The platform or systems team installs ClamAV on the server or on a dedicated host that the Moodle web servers can reach, using the package source your operating system supports. Enable the freshness updater (freshclam) as a scheduled service so virus definitions update without manual work. Confirm the installed version and that the signature database files exist and have a recent modification date. Done means the update service runs without errors on its first pass and the database loads, which you can check in the service logs and the ClamAV version output.

  2. Choose the command line or daemon connection mode

    The Moodle administrator and the platform team agree on how Moodle will call ClamAV. The command line mode starts a scanner process for each file, which is simple to set up but loads signatures every time and suits low upload volumes. The daemon mode, reached through a Unix socket or a TCP port, keeps signatures in memory and suits steady traffic. Record the decision, the socket path or host and port, and who owns the service. Done means the team has a written choice that matches the host layout, and the connection address is documented for the next steps.

  3. Start the daemon and test its response

    If you chose daemon mode, the systems team enables the clamd service, points it at the same socket or TCP address recorded in the previous step, and restarts it after any configuration change. Test the connection from the Moodle web server host, not only from the scanner host, because the web server user must reach the socket or port. Scan a known test file with the scanner client to confirm the daemon answers. Done means the daemon starts on boot, responds to a ping or scan request from the web server host, and logs no permission errors.

  4. Set file permissions for the clamav and web server users

    Grant each account only the access its mode needs. The clamav user must read the files Moodle places in the upload area when the daemon scans them, and the web server user must be able to write the socket or execute the command line scanner. Moodle data stays under the dataroot, which should sit outside the web root, so set group membership or ACLs there rather than widening permissions for everyone. Confirm access by running the scanner as each user against a sample file. Done means both accounts scan the sample file successfully and neither can read unrelated directories.

  5. Enable the antivirus setting in Moodle

    A Moodle administrator installs or confirms the ClamAV antivirus plugin in the site administration area, selects the matching mode, enters the socket path, host and port or scanner binary path, and saves the settings. Review the plugin's setting for what happens when a scan fails, and choose the behavior your policy requires before users upload files. Done means the plugin appears as an enabled antivirus option with the chosen connection details saved, and no configuration error appears on the settings page.

  6. Run the scanner test in Moodle

    Use the scanner test that the plugin provides in Moodle to send the standard harmless test string through the configured connection. Confirm the test reports that the scanner is working, then upload a harmless test file through a course or user file area as a non-administrator account. Done means the test passes and the upload completes, which shows the path works from the user's side as well as the administrator's.

  7. Confirm the infected files report is reachable

    Moodle core includes an infected files report (report_infectedfiles), which lists files that the antivirus scan flagged. Sign in as a site administrator and open the report from the site administration area to confirm it loads and shows the expected empty or test state. Check that only administrators and other roles you intend can reach it, and record who receives the review task. Done means the report loads for an administrator, is hidden from ordinary users, and your team has a named owner for reviewing findings.

What happens when a scan fails

A scanner that cannot answer is a control decision, not a background detail. Each case below changes what users see on upload and what the administrator must check, so the configured behavior should be chosen deliberately and tested before go-live.

Scanner unreachable

The ClamAV daemon is down, the Unix socket path is wrong, or the TCP host and port cannot be reached from the Moodle web or cron nodes. Users may see an upload error or, depending on how the plugin is configured, an upload that is accepted without a scan. Check the service status, the socket or port in the plugin settings, and firewall rules between the Moodle servers and the scanner host. Confirm how your Moodle release handles a scanner error before you decide which behavior you want.

Daemon busy or timing out

During bursts of uploads, such as a course start or assignment deadline, the daemon can queue requests or exceed the plugin's time limit. The likely user effect is a slow upload, a timeout message, or a retry that succeeds later. Check daemon logs for queueing, the size of files being scanned, and whether many scans run through the command line method at once. Load test the upload path with realistic file sizes before a term opens.

File permissions block the scanner

If the clamav user cannot read files in moodledata or the temporary upload location, the scan cannot inspect the file at all. This often appears after a restore, a change of web server user, or a move of the data directory, and it can look like a clean result if the failure is not surfaced. Check that the clamav user has read access through group membership or ACLs, not by widening permissions on the whole data tree. Confirm the scanner reads an actual test file and reports a result.

Signatures out of date

A daemon with stale virus definitions will pass files that newer signatures would flag. The failure is silent, so nothing on the user side changes. Check the freshbits or update service, the date of the last signature update, and the daemon log for update errors. Set an alert on signature age so an outdated database is found before it becomes a gap in coverage.

File flagged as infected

A positive detection should block or quarantine the file according to the plugin configuration, and the event should appear in the infected files report. Users see a rejection message, which can confuse legitimate staff who upload archives or macro-enabled templates. Check the report for the file, the signature name, and the uploader, then decide on user communication and whether to review the account. Test that a harmless EICAR test file triggers the same path you intend to use in production.

Reviewing infected files with the infected files report

The infected files report gives administrators a single place to see which uploaded files Moodle has flagged as infected, so that scanning results do not depend on someone reading server logs. It ships as part of Moodle core as the report_infectedfiles plugin, and its source sits under the public/report directory of the Moodle GitHub repository, which is the place to check its behavior against the exact version you run. Because the report is core, it needs no separate install, but you should confirm after each upgrade that it still appears in the site administration reports and that your ClamAV configuration still feeds it. Limit access to the people who will act on findings, typically site administrators and a small security or service desk group. Users who can see a flagged file's name and owner learn about a possible incident before your team has assessed it.

Use the report during incident triage in a fixed order: confirm the flagged file's owner, course and context, check whether any other user downloaded it, and decide whether the file must be removed or kept for investigation. Treat a new entry after a plugin installation, a theme change or a core upgrade as a signal to review the upload paths that changed, because a new file type or a reconfigured scanner can alter what gets caught. Record each decision in your own ticketing system, since the report shows state but not the reasoning behind it. Run the same review after any change to the ClamAV path, socket or permissions, because a broken scanner may produce a quiet gap rather than an error.

Decide retention for flagged files before the first detection happens. Your privacy and records teams should confirm how long infected material and its metadata may be kept, whether it is a personal data record that falls under your retention schedule, and who may authorize deletion or release for evidence. Ask them whether an incident involving malware in learner-submitted work needs its own handling procedure, and whether the files should be held in a restricted location rather than left in place where course staff can reach them. Confirm these rules with your organization's policy owners and any applicable legal counsel, not from this page, since the answer depends on your jurisdiction and sector.

Security and operational considerations for the scanner

A ClamAV scanner sits in the upload path, so it inherits trust, network exposure and operating load that the Moodle site itself does not carry. The cards below cover the decisions that connect those areas and the checks to run in your own environment before the scanner takes live uploads.

Least privilege for the clamav user

The scanning daemon or command line process must read files Moodle stores in moodledata, so it needs read access to the upload area and nothing more. Confirm that the clamav user can read the paths Moodle passes to it, cannot write into moodledata, and has no shell login or sudo rights. Test with a file the account should not reach, and record the result.

Exposure of clamd over TCP

A TCP listener on clamd accepts scan requests from anything that can reach its port. Bind the daemon to localhost or a Unix socket where possible. If Moodle runs on a separate host, restrict the port with firewall rules to the Moodle web and cron servers only, and confirm from another host that the port is closed. Treat any open scan port as an unauthenticated service unless your own tests show otherwise.

Signature update routine

Malware detection is only as current as the signature database. Confirm how freshclam is scheduled, where it writes its database, and whether the clamav user can update those files without giving the Moodle web user access. Ask your security team how often signatures should refresh and who is alerted when updates fail.

Monitoring signature freshness

A stale database fails silently because scans still return clean results. Add a check that reads the database age and raises an alert when updates stop. Pair it with a periodic test that uploads the standard EICAR test string through Moodle and confirms the file is flagged, so you know the whole path works end to end.

Resource use during peak uploads

Scanning is CPU and memory heavy, and large files or bursts of assignment submissions near a deadline can queue scans behind each other. Measure scan time and daemon load during a realistic peak, set a maximum file size that matches your policy, and decide whether the Moodle site should wait for a result or reject uploads when the scanner is busy. Ask your team to confirm the threshold in writing.

Logging scan events

Keep a record of scanner errors, infected detections and daemon restarts, and forward them to the log platform you already use. Confirm which log file the daemon writes to, how long it is retained, and whether the infected files report in Moodle is reviewed on a schedule. Logs should show file identifiers and outcomes without copying the file contents.

Questions teams ask before scanning Moodle uploads

How much effort does setting up ClamAV scanning for Moodle take?

The effort depends mostly on how the ClamAV daemon is deployed and how many Moodle upload paths need coverage. A team that runs a single Moodle site on a server it already manages will spend its time on three things: installing and updating ClamAV, choosing between the command line scanner and a daemon connection (Unix socket or TCP), and running test uploads through every path users rely on. Effort rises when the site runs across several web nodes, when the daemon is shared with other services, or when the security team wants evidence of each step. Ask any partner to split its estimate into installation, configuration, testing and handover, so you can see which part is driving the number.

Can our team set up Moodle antivirus scanning without outside help?

Yes, a team with Linux administration skills and someone who knows Moodle administration can usually do it in-house. The work is well bounded: install ClamAV, configure the antivirus plugin in Moodle, set file permissions so the clamav user can read uploaded files, and confirm that the infected files report (report_infectedfiles) shows the expected results. The harder questions are operational: who watches the scanner logs, who handles a failed scan, and who checks the setup after each Moodle upgrade. If those owners are not clear inside your team, an outside partner can document the design and hand it over. DeployOpen implements, hardens and documents self-hosted platforms in your own infrastructure, so the choice between in-house and partner delivery is yours to make.

What does the scanning project need from our team?

Plan for four inputs. First, administrative access to the Moodle server and the host running ClamAV, including the ability to change file permissions and the web server or PHP-FPM user context. Second, a written test plan listing the upload paths to cover, such as assignment submissions, forum attachments, file repositories and course files, plus a set of harmless test files and one safe test signature that triggers detection. Third, admin time from the Moodle team to make configuration changes in the site and to review the infected files report during testing. Fourth, a named owner for ongoing alerts and scanner updates. Confirm the server and network access rules with your security team before the work starts, because the daemon connection path matters for firewall and socket policy.

What drives the cost of ClamAV scanning up or down?

Cost follows the number of moving parts. Expect the price to be lower when Moodle runs on one server, uses the local daemon or command line scanner, and has few custom upload paths. It rises when the site spans several app servers, needs a shared scanning service, must follow a formal change process, or requires evidence for an auditor. Ongoing costs are mainly staff time for reviewing alerts, applying ClamAV updates and re-checking the setup after each Moodle minor release. Ask any quote to separate one-time work (design, installation, testing, documentation) from recurring work (monitoring, updates, retesting after upgrades), and to state which Moodle and ClamAV versions it assumes.

How long does it take to verify that scanning works?

Verification time depends on the number of upload paths and how complete your test set is, not on the scanner alone. A practical check covers each upload route with a clean file and a test file that ClamAV should flag, then confirms that the infected file is blocked or quarantined according to your configured behavior, that the event appears in the infected files report, and that the log shows the scan result. Also test the failure path: stop the daemon or make the socket unreachable and confirm how Moodle responds. Ask for a written test matrix with pass and fail results for each path before accepting the work, and confirm the timeline with the team that will carry it out.

How often do ClamAV signatures and the setup need upkeep?

Signature updates run continuously on the scanner side through freshclam, so upkeep is about making sure updates actually run and succeed. Check that the update service is enabled, that the host can reach the update source or your internal mirror, and that alerts fire when updates fail. The Moodle side needs attention after each minor release and plugin change, because a changed upload path or a plugin update can bypass scanning if the configuration no longer covers it. Re-run your test matrix after every Moodle upgrade. Confirm with your scanner vendor or distribution how signature updates are delivered in your environment, since the exact mechanism depends on how you install ClamAV.

What should we ask a partner for in a ClamAV scanning quote?

Ask for a written scope that lists the Moodle version, the ClamAV installation method and the scanning mode (command line, Unix socket or TCP daemon). Ask which upload paths are covered and which are excluded, and how the file permissions for the clamav user will be set and documented. Request the test matrix, the failure behavior to be configured, and how the infected files report will be reviewed. Ask what handover includes: runbooks, alert ownership, and a retest plan for upgrades. Finally, ask which items are one-time and which recur, and who is responsible for each. DeployOpen works from a written scope agreed before work starts, and does not publish a price list, so the quote will follow from the scope you agree.

Does ClamAV scanning on Moodle meet a compliance requirement by itself?

No. Scanning uploads reduces one specific risk, malware delivered through user files, and produces evidence that a control exists and works. It does not make a Moodle site compliant with any framework on its own. Assessors usually want to see the control design, the configuration as deployed, test results, logs showing that scans ran, and a record of how alerts were handled. Build those records as you go. Independent auditors and certification bodies make the assessment decision, and DeployOpen prepares systems and evidence for that review rather than issuing any audit report or certification.

How DeployOpen scopes and delivers Moodle antivirus work

DeployOpen plans and builds the ClamAV integration for your Moodle site inside infrastructure you control, from the scanner mode and file permissions through to failure handling and the infected files report. Each step is agreed in writing before work starts, so your security and Moodle administration teams know what will change and how it will be checked.

How we scope

  • We confirm which upload paths, file types and Moodle areas need scanning, and where your site currently accepts files.
  • We record the ClamAV topology: command line, Unix socket or TCP daemon, and the hosts that run it.
  • The written scope states the permissions, failure behavior and reporting that will be delivered, and what remains with your team.

How we build

  • We install and configure the ClamAV plugin, set file permissions for the clamav user, and test the chosen connection method.
  • We test failed scans, unreachable daemons and infected test files, then confirm how Moodle reports each outcome to users and administrators.
  • We review the infected files report, so administrators can find and act on flagged uploads during routine checks.

How we hand over

  • You receive configuration notes, a record of the test results and the settings that must stay in place after upgrades.
  • We walk your administrators through the scan failure process and the steps for reviewing and removing infected files.
  • The handover documents which checks to re-run after Moodle upgrades and plugin installs, so the setup is not assumed to persist.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer, which covers ClamAV changes after your Moodle upgrades.
  • Retainer work can include re-testing the scanner after ClamAV updates and reviewing new scan failure cases in your logs.
  • Ask any partner, including DeployOpen, to state in the quote which ClamAV and Moodle versions the support covers.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.