Installation Steps of virus scan any file with ClamAV

ClamAV® is an open source (GPL) anti-virus engine used in a variety of situations including email scanning, web scanning, and end point security. It provides a number of utilities including a flexible and scalable multi-threaded daemon, a command line scanner and an advanced tool for automatic database updates.

Install ClamAV on Ubuntu 18.04

sudo apt install clamav clamav-daemon -y

Permission to Directories where log save (For Eg. in my case)

sudo chmod 777 /var/log/clamav/
sudo chmod 777 /var/lib/clamav/

Update the ClamAV Singature Database

systemctl stop clamav-freshclam

freshclam

sudo systemctl start clamav-freshclam

While downloading ClamAV Signature if facing timeout issue then modify below configuration

sudo gedit /etc/clamav/freshclam.conf

Change below parameters in configuration file

ConnectTimeout 30
ReceiveTimeout 30
To
ConnectTimeout 9999sudo apt install clamav clamav-daemon -y
ReceiveTimeout 9999

Clamscan command execution

clamscan --help

In PHP you can write simple script to execute clamscan as below

<?php
exec('clamscan [/path-to-file/file-name.ext]', $output, $result);

if($result == 1){
    // Virus Infected
}else{
    // Virus not found
}
?>

How to maipulate the shell output in php

To get disk usage of server , need to execute shell command << df -h -T >>

I used <?php shell_exec(‘df -h -T’); ?>

To parse disk usage shell command to get memory usage of different directories , use code as follows :-

$output = shell_exec(‘df -h -T’);
$drives = split(“[\r|\n]”, trim($output));
echo “<pre>”;
print_r($drives);
echo “</pre>”;

Enabling Use Of Apache Htaccess Files

WARNING: This page was written based on Ubuntu 10.04 (Lucid), although the same may apply to other releases. You are encouraged to also read:

  1. The related ubuntu server guide (Choose your distribution version > “Ubuntu Server Guide” > “Web servers”).
  2. The apache htaccess tutorial: http://httpd.apache.org/docs/2.0/howto/htaccess.html

By default, Ubuntu’s Apache will ignore the directives in your .htaccess files.

When (not) to use .htaccess files

According to Apache.org’s Apache Tutorial,

“In general, you should never use .htaccess files unless you don’t have access to the main server configuration file. There is, for example, a prevailing misconception that user authentication should always be done in .htaccess files. This is simply not the case. You can put user authentication configurations in the main server configuration, and this is, in fact, the preferred way to do things.”

“.htaccess files should be used in a case where the content providers need to make configuration changes to the server on a per-directory basis, but do not have root access on the server system. In the event that the server administrator is not willing to make frequent configuration changes, it might be desirable to permit individual users to make these changes in .htaccess files for themselves.”

On Ed/X/Ubuntu 6.06 and Ubuntu Edgy Eft, the “main server configuration file” is  /etc/apache2/apache2.conf .

To make .htaccess files work as expected, you need to edit this file:

/etc/apache2/sites-available/default

Look for a section that looks like this:

        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
                # Uncomment this directive is you want to see apache2's
                # default start page (in /apache2-default) when you go to /
                #RedirectMatch ^/$ /apache2-default/
        </Directory>

You need to modify the line containing AllowOverride None to read AllowOverride All. This tells Apache that it’s okay to allow .htaccess files to over-ride previous directives. You must reload Apache before this change will have an effect:

sudo /etc/init.d/apache2 reload

2009.12.08 note: in the LAMP download about a week ago with Ubuntu 9.10 (Karmic) the default configuration file was /etc/apache2/sites-available/000-default and it included AllowOverride None under <Directory /> in addition to <Directory /var/www/>. Also, directories in /www/var/ containing .htaccess files defaulted to not giving the Apache server read access, resulting in the Apache error

  • (13)Permission denied: /var/www/webapp/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable.

To fix, $ sudo nautilus then right click on the directory with the .htaccess file, select Properties, then select Permissions, and give the user group you log in as at least read permission.

See http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride for more info on AllowOverride.

Password-Protect a Directory With .htaccess

Warning: On at least some versions of Ubuntu, .htaccess files will not work by default. See EnablingUseOfApacheHtaccessFiles for help on enabling them.

Create a file called .htaccess in the directory you want to password-protect with the follwing content:

AuthUserFile /your/path/.htpasswd
AuthName "Authorization Required"
AuthType Basic
require valid-user

instead of valid-user, you can also add the users you want directly

If you want to password protect just a single file in a folder add the following lines to the .htaccess file:

<Files "mypage.html">
  Require valid-user
</Files>

Then create the file /your/path/.htpasswd which contains the users that are allowed to login and their passwords. We do that with the htpasswd command:

htpasswd -c /path/to/your/.htpasswd user1

The -c flag is used only when you are creating a new file. After the first time, you will omit the -c flag, when you are adding new users to an already-existing password file. Otherwise you will overwrite the file!!

Nevertheless, you should store the file in as secure a location as possible, with whatever minimum permissions on the file so that the web server itself can read the file.

Finally we need to add the following lines to /etc/apache2/apache2.conf:

<Directory /your/path>
AllowOverride All
</Directory>

You have to adjust /your/path/.htpasswd

Restart your webserver:

sudo /etc/init.d/apache2 restart

Troubleshooting

If you can’t access your stuff and the dialog keeps popping up, check that you entered the username and password correctly. If it still doesn’t work, check the path to your .htpasswd and make sure the path specified in the AuthUserFile directive is correct. Also make sure that both the .htpasswd and .htaccess files are readable by the web server user chmod 644 should do the trick!

Example

Here is an example on how to prevent users from access the directory, password-protect a specific file and allow userse to view a specific file:

AuthUserFile /your/path/.htpasswd
AuthName "Authorization Required"
AuthType Basic
Order Allow,Deny
<Files myfile1.html>
 Order Allow,Deny
 require valid-user
</Files>

<Files myfile2.html>
 Order Deny,Allow
</Files>

Redirect requests using .htaccess and mod_rewrite

  1. Make sure Apache .htaccess is enabled (by default it is enabled in Ubuntu)
  2. Make sure the Apache module mod_rewrite is enabled. Execute:
sudo a2enmod rewrite

..and see if rewrite is listed here:

sudo apache2ctl -M

and then you can redirect requests using RewriteRules. Example:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?_REQUEST=$1 [L]

Setting up LAMP Stack on your UBUNTU System

This is to help people set up LAMP on their desktops. Ubuntu server edition comes with LAMP but desktop users must download all the necessary files. This tutorial owes its credits to Ubuntu Community Docs and lots of people around the world who enlightened me about LAMP and Ubuntu. Let’s start.We first need some important packages. These are:

apache2 php5-mysql libapache2-mod-php5 mysql-server

You can get these via apt-get or from your Synaptics Package Manager. For getting via apt-get you must have an active internet connection. Type this command in the terminal:

sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server

If you are in the Packages Manager, just search the packages and select them. This is the easiest method.

You may want to configure your LAMP, but before starting it is advisable to change the installation defaults. The default root user of MySQL has no password or a blank string as password. This should be changed. It is always advisable to create another user with full privileges as that as root. Use this alternate user instead as root. Root is the superuser.

Go to terminal: Type

mysql -u root

At MySQL console type

SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘yourpassword’);

Just put your password instead of yourpassword within single quotes as shown above.

After setting the password if you want to login as root,just enter this at the terminal:

mysql -u root -p

Create a new user and give all the privliges to it as explained above:

grant all privileges on *.* to ‘yourusername’@’localhost’

identified by ‘yourpassword’ with grant option;

Replace yourusername with the username you want and yourpassword with a proper password. If you want this user to deny Grant Option just remove WITH GRANT OPTION from the above statement.

Run, Stop, Test, And Restart Apache:

Start: sudo /usr/sbin/apache2ctl start

Stop: sudo /usr/sbin/apache2ctl stop

Test: sudo /usr/sbin/apache2ctl test

Retart: sudo /usr/sbin/apache2ctl restart