Latest blog entry

How to make Tomcat work on port 80 instead of 8080?

January 11, 2014    |   Posted by admin   |    Category: cPanel Management, Linux Administration

Sometimes people host applications that are fully Java based and don’t require a Webserver to access their application. However, in such a case, the application has to be accessed with port 8080 i.e. http://domainname:8080 which is not feasible.

There are 2 ways for the Java application to work on port 80, so people don’t have to mention port 8080 in their URL We will take a look at each of the above 2 options below:

1. The easiest way is to change the Tomcat port from port 8080 to 80 in the conf/server.xml file. This file is inside the Tomcat folder. 

To locate the file, update the mlocate database first (this command will take sometime to complete):

# updatedb

now, search the server.xml file using the locate command:

# locate server.xml

Open the file in the edit mode

# nano server.xml

and search for the below section

<Connector port="8080" Protocol="HTTP"
maxHttpHeaderSize="8192"
connectionTimeout="20000"
/>

Replace port 8080 with 80 and restart the Tomcat service.

2. The second method is to use iptables rules to redirect traffic received on port 80 to port 8080.

To add the iptables redirect rules, SSH to your server as root and execute the below commands:

# iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
# iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
# iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j \
REDIRECT --to-port 8080

To make the rules permanent

# service iptables save

Applying any of the above 2 methods will make the Java application work without the use of port 8080 in the URL.

Comments Off on How to make Tomcat work on port 80 instead of 8080?

How to install Tomcat 7 on a cPanel server?

May 7, 2013    |   Posted by admin   |    Category: cPanel Management

cPanel’s easyapache script by default install Tomcat version 5.5 and provides no option to upgrade to version 7.x if required, so people who requires Tomcat 7 will have to install/upgrade tomcat manually but the newer version won’t be recognized by cPanel by default and people will have to configure domains manually in the tomcat configuration files.

There is a workaround though, so once Tomcat 7 is installed and some small changes are made, it can be managed from WHM also.

1) Start by installing the available Tomcat version provided by cPanel using the easyapache script. It will install Java on your server so you don’t have to install it manually. cPanel will install Tomcat under /usr/local/jakarta/ directory and a link to tomcat inside it.

# ls -la /usr/local/jakarta
drwxr-xr-x  13 tomcat nobody 4096 Apr 29  2009 apache-tomcat-5.5.25/
lrwxrwxrwx   1 root   root     39 Apr 29  2009 tomcat -> /usr/local
/jakarta/apache-tomcat-5.5.25/

2) Download Tomcat 7 in the /usr/local/jakarta directory and extract it

# cd /usr/local/jakarta
# wget http://apache.cs.utah.edu/tomcat/tomcat-7/v7.0.39/\
bin/apache-tomcat-7.0.39.tar.gz
# tar -zxf apache-tomcat-7.0.39.tar.gz

3) Once the tomcat file is extracted, a new directory ‘apache-tomcat-7.0.39’ will be created under the jakarta folder. Now, remove the old ‘tomcat’ link and create a new symlink to point to the new tomcat directory i.e.

# rm -f tomcat
# ln -s /usr/local/jakarta/apache-tomcat-7.0.39 tomcat

so it looks like follows:

# ls -la /usr/local/jakarta
 drwxr-xr-x  13 tomcat nobody apache-tomcat-5.5.25/
 drwxr-xr-x   9 root   root apache-tomcat-7.0.39/
 -rw-r--r--   1 root   root apache-tomcat-7.0.39.tar.gz
 lrwxrwxrwx   1 root   root tomcat -> /usr/local/jakarta
/apache-tomcat-7.0.39/

4) Now goto the new tomcat directory and compile the newer version

# cd /usr/local/jakarta/tomcat/bin
# tar -zxf commons-deamon-native.tar.gz
# cd commons-daemon-1.0.14-native-src/unix
# ./configure
# make
# cp jsvc ../..   (copies the new file to the bin directory)

5) Now copy the server.xml and workers.properties from the old tomcat installation to the new one. This is required if you already have tomcat enabled on some websites before the upgrade.

# cp -p /usr/local/jakarta/apache-tomcat-5.5.25/conf/server.xml \
/usr/local/jakarta/tomcat/conf/
# cp -p /usr/local/jakarta/apache-tomcat-5.5.25/conf/workers.properties\
/usr/local/jakarta/tomcat/conf/

6) Now, restart the tomcat server

# /usr/local/jakarta/tomcat/bin/shutdown.sh
# /usr/local/jakarta/tomcat/bin/startup.sh
# /etc/init.d/httpd restart

7) Check the tomcat version in use:

# sh /usr/local/jakarta/tomcat/bin/version.sh

If for any reason, you would like to go back to the older Tomcat version, just goto the jakarta folder and change the ‘tomcat’ symlink to the older tomcat folder and restart the tomcat server.

Comments Off on How to install Tomcat 7 on a cPanel server?

How to install ClamAV antivirus on Linux / cPanel?

April 7, 2013    |   Posted by admin   |    Category: cPanel Management

ClamAV is a anti-virus software that detects various malicious softwares and viruses. It can also be installed and configured in front of a mail server to scan emails. It provides command line scanning and automatic database update.

You can install ClamAV on a cPanel server from WHM as well as via SSH.

1) Login to WHM and goto the cPanel section
2) click Manage Plugins
3) select the checkbox "Install and Keep Updated" in ClamAV section.
4) Click Save at the bottom of the page.

It will take a few minutes for the installation to complete. Once done, enable the following checkboxes from WHM >> Plugins >> Configure ClamAV Scanner and click Save.

Scan Entire Home Directory
Scan Mail
Scan Public FTP Space
Scan Public Web Space

Each individual users will have a Virus Scanner option in his cPanel from where he can scan his files, emails etc.

The second method of ClamAV installation is through SSH. Login to the server and goto module-install directory and run the installer

# cd /usr/local/cpanel/modules-install/clamavconnector-Linux-i686/
# ./install

That’s it. If you now plan to scan the server side files OR the website files of any account, the following commands are very much useful and provide you with a quick result.

Updating the antivirus database first:

# freshclam

To scan a directory and print a list of the infected files:

# clamscan -ri /home

Scan and directly remove the infected files and emails

# clamscan -ri –remove /home
Comments Off on How to install ClamAV antivirus on Linux / cPanel?

Munin Unable to Generate Mysql Stats

January 27, 2013    |   Posted by admin   |    Category: cPanel Management

Munin plugin is known to have issues while generating Mysql graphs. The mysql graph remains empty due to a bug in the Perl library that causes the path to the mysqladmin to be lost.

The solution is to specify the path to mysqladmin in the /etc/munin/plugin-conf.d/cpanel.conf file. Edit the file

# nano /etc/munin/plugin-conf.d/cpanel.conf

and add the below line in the [mysql*] section

env.mysqladmin /usr/bin/mysqladmin

The mysql section should look like follows

[mysql*]
user root
group wheel
env.mysqladmin /usr/bin/mysqladmin

Restart the munin-node  service and see if it works. If it doesn’t, it indicates munin cannot read the values of mysql variables i.e. the username/password of mysql.

In such a case, have munin read the Mysql password from the .my.cnf file directly which is residing under the /root directory. To achieve this, create a file say, /root/mysqlpass

# nano /root/mysqlpass

and add the following command

/usr/bin/mysqladmin -uroot -p`cat /root/.my.cnf | grep pass \
| sed s/pass// | sed s/=// | sed s/\"//g` $@

The sed command may look confusing but it just removes words and characters around the password.

Set executable permission on the file

# chmod 755 /root/mysqlpass

Now edit the /etc/munin/plugin-conf.d/cpanel.conf file again and replace

env.mysqladmin /usr/bin/mysqladmin

with

env.mysqladmin /root/mysqlpass

Once done, restart the munin-node service and munin will start generating the Mysql graphs

Comments Off on Munin Unable to Generate Mysql Stats

How to install PHP 5.2 and PHP 5.3 together on cPanel server?

August 12, 2012    |   Posted by admin   |    Category: cPanel Management

Although PHP 5.2 is becoming outdated, still a lot of applications and custom scripts still works on PHP 5.2. However, as per cPanel PHP 5.2 is “End of Life” and may stop offering it soon. So here is the guide for people who want PHP 5.2 along side PHP 5.3 on a cPanel server and make use of both the PHP versions at the same time.

We are assuming the default PHP version installed on your sever is 5.3.x.

1. Download and untar PHP 5.2:

# mkdir /usr/local/buildphp52
# cd /usr/local/buildphp52
# wget http://museum.php.net/php5/php-5.2.9.tar.gz
# tar --strip-components=1 -zxvf php-5.2.*

2. Configure and install PHP

# ./configure --prefix=/usr/local/php52 --enable-cgi --enable-bcmath\
 --enable-calendar --with-mysql=/usr/bin -with-libdir=lib64\ --with-gd\
 --enable-mbstring   (you can add more modules per your wish)
 # make
 # make install

3. Now add the PHP 5.2 handlers to Apache

# pico  /usr/local/apache/conf/includes/pre_virtualhost_global.conf

add the following:

Action application/x-httpd-php52 /cgi-sys/php52
AddType application/x-httpd-php52 .php52

4. Use Apache distiller for the above changes to take affect and make cPanel skip .htaccess scan and remove the mime types:

# /usr/local/cpanel/bin/apache_conf_distiller --update
# touch /var/cpanel/easy_skip_update_php_mime_types

5. Now create a file under the cgi-sys directory of cPanel so it detects PHP 5.2

# pico /usr/local/cpanel/cgi-sys/php52

and add the following to it

#!/bin/sh
exec /usr/local/php52/bin/php-cgi

6. Set the proper ownership/permission

# chown root:wheel /usr/local/cpanel/cgi-sys/php52
# chmod +x /usr/local/cpanel/cgi-sys/php52

7. Now copy the php configuration from the build directory of PHP 5.2

# cp /usr/local/buildphp52/php.ini-production /usr/local/php52/lib/php.ini

8. Create a symlink for the PHP 5.2 executable to use from the command line:

# ln -s /usr/local/php52/bin/php-cgi /usr/local/bin/php52

9. Once done, restart Apache for changes to take affect

# service httpd restart

10. Now, PHP 5.3 will work by default and to make PHP 5.2 work for a specific account OR a folder, create a .htaccess file inside it and add the PHP 5.2 Handler

AddHandler application/x-httpd-php52 .php

That’s it. Create a phpinfo page inside the folder and browse it to see if PHP 5.2 is in effect for that folder.

Things to note is:  If you want to install OR compile a module with PHP 5.2, use appropriate php-config and phpize file, i.e.

phpize: /usr/local/php52/bin/phpize
php-config: ./configure --with-php-config=/usr/local/php52/bin/php-config
Comments Off on How to install PHP 5.2 and PHP 5.3 together on cPanel server?