As a webmaster it is really good to have a bunch of tools pre-installed on your server. ClamAV is a great antivirus for Linux. In this guide I’ll show you how to install it on CentOS 6.x

Installing The PHP ClamAV Extension (If You Want To Use It Within Scripts!

IMPORTANT: If you want PHP to do the dirty work for you and use CLAMAV within your PHP scripts, then you also need to get PHP extension:

1. Download it here from Sourceforge

2. Enter tar -xzf php-clamav*

3. Enter cd ./php-clamav*

4. Enter phpize

5. Enter ./configure

6. Enter make and make install

This should automatically add the extension to your php.ini – if that did not work for you, add the path to the *.so file to the php.ini – you may have multiple php.ini files!

The Installation

1. To install tools on your server all you need is a good REPO (short for repository) and yum (the popular package installer; the equivalent on Ubuntu is apt-get)

2. Alright, now lets enter yum install clamav clamd

Installing Clamav Via Yum

3.(Optional) – Did Not Work? If you do not have a good REPO in place, you have to install for example the EPEL repo – on a WHM powered server you should already have all of this by default

4. Confirm the download with “y” (without the quotes)

5. Done!

Next Part: Configuration

Tip: After the installation most commands like clamd start, freshclam and clamscan work out of the box – there is little you have to configure manually

1. Enter whereis clamav – you will get something like /usr/share/clamav

2. Enter cd /usr/share/clamav

3. Enter pico README*

4. As explained in the README file, place the config file in /etc/clamd.d/.conf

5.

clamd.logrotate:
  * set the correct value for the logfile
  * place it into /etc/logrotate.d

clamd.sysconfig:
  * set the name of the config-file and the local socket
  * copy it to /etc/sysconfig/clamd.

clamd.init:
  * set the service-name
  * place it into /etc/init.d/ with an unique name and activate it
    (e.g. with /sbin/chkconfig clamd. on)

Starting The ClamAV Service

1. Enter clamd start

2. You can stop it again with clamd stop

Update Your Virus Definitions

1. Enter freshclam

2. Wait until the update is done

Schedule A Scan Using ClamAV

If you want to schedule a scan on your CentOS server, you will only need to know the command clamscan

1. Create a blank file and paste clamscan -i -r $SCAN_DIR >> $LOG_FILE

2. Specify an absolute path for SCAN_DIR and and a path to a LOG_FILE that actually exists

3. Example: clamscan -i -r /home/ >> /root/scripts/clamav.log

Still have questions? Let us know in the comments, we’re here to help