Perl Module installation in a Linux/cPanel server?

There are various ways to download and install perl modules from CPAN. In general it’s a good idea to download and install the perl module but we will see the different ways of installing the perl module.

1. The easiest way is to use the perl CPAN module. SSH to the server as root and execute:

# cpan

If you are running this for the first time, it will prompt you for a few questions (default answers are fine) before providing you with the “cpan >” prompt. To install a module, say for example “Perl::OSType”, execute

# cpan > install Perl::OSType

this will download and compile the module and install it server wide. To know more commands/options of cpan, type question mark ( ? ) at the cpan prompt.

2. The second and the quickest method is to use perl CPAN module from the bash prompt instead of ‘cpan’ prompt. If you are on the command line of Linux, just execute

# perl -MCPAN -e ‘install Perl::OSType’

3. The above 2 methods are the easiest one but it is recommended to install the module manually as the above methods may not always work. You can search the module at http://search.cpan.org/ and then wget it on your server. Once done, extract it:

# tar -zxf Perl-OSType-1.002.tar.gz

There is a standard way of installing the perl module, however, you will see a README file inside the extracted directory containing the installation steps. Goto the extracted directory and execute

# perl Makefile.PL

# make

# make test

# make install

Or you can use perl module installer script as well.

It’s simplest to install a perl module from the shell:

# /scripts/perlinstaller module

e.g.

# /scripts/perlinstaller Inline::C

If you’re not sure of the module name, you can search for it on cpan:
http://search.cpan.org/

Or you can use Perl Module Installer in WHM;

This WHM feature allows you to download and install a Perl module. It works by providing an interface that lets you search through the central Perl repository known as CPAN (http://www.cpan.org). WHM then returns a list of Perl modules that match your search criteria, allowing you to click on any of the relevant search results to download and install the module.

To search for and install a Perl module:

1. Enter your search criteria into the available text field. Alternatively:

You can also view a list of Perl modules available from CPAN by clicking Show Available Perl Module(s). The list is limited, however; an exhaustive list is available at http://www.cpan.org.

If you know the exact name of the module you wish to install, you may install it by entering its name in the Install a Perl Module text box and clicking Install Now.

2. Click Go.

WHM will display the matching Module Name, Version, Description, and any Actions you may perform.

3. Click the Install button next to the module you would like to download and install.

You may also view a module’s documentation by clicking its corresponding Show Docs button.

If you did not find the desired module, you may continue searching from the search results page using the Search field and Go button.

Thats it.

How to install/upgrade roundcube in a cPanel/Linux server

Before installing roundcube on a cPanel server you should know your mysql root password. Replace DATABASEPASSWORD with your mysql root password.

If Roundcube is already installed, you need to uninstall it.

Uninstall/remove exiting RoundCube

# cd /usr/local/cpanel/base

# rm -rf roundcube*

On mysql prompt

mysql -e ‘drop database roundcube’;

# /scripts/upcp

Now follow the  steps to update/install latest roundcube. You will have to specify your root password when prompted.

# cd /usr/local/cpanel/base

# wget -O roundcube.tar.gz http://nchc.dl.sourceforge.net/sourceforge/

# roundcubemail/roundcubemail-0.2.1.tar.gz

# rm -rf roundcube.tar.gz

# mv -f roundcubemail-0.2.1/ roundcube

# cd roundcube

# chmod -R 777 temp

# chmod -R 777 logs

Database Configuration

Create the database, database user and install the intial sql file. The following commands will do this for you.

mysql -e “CREATE DATABASE roundcube;”

mysql -e “GRANT ALL PRIVILEGES ON roundcube.* TO [email protected] IDENTIFIED BY

‘DATABASEPASSWORD’;”

mysql -e “FLUSH PRIVILEGES;”

mysql -e “use roundcube; source SQL/mysql.initial.sql;”

You will have to replace the roundcube password with ‘DATABASEPASSWORD’ field.

Roundcube Configuration

# cd config

# mv db.inc.php.dist db.inc.php

# mv main.inc.php.dist main.inc.php

then open database configruation file db.inc.php in your favroite editor.

# vi db.inc.php

Find following line

$rcmail_config[‘db_dsnw’] = ‘mysql://roundcube:[email protected]/roundcubemail’;

Replace it with

$rcmail_config[‘db_dsnw’] = ‘mysql://roundcube:[email protected]/roundcube’;

Now Open main.inc.php

# vi main.inc.php

Find

$rcmail_config[‘default_host’] = ”;

Replace with

$rcmail_config[‘default_host’] = ‘localhost’;

Configure cPanel to show roundcube in the theme. Please note this is for the X theme(default) only!! If you use another theme please skip the next part and see below.

# cd /usr/local/cpanel/base/roundcube/skins/default/images/

# cp –reply=yes roundcube_logo.png /usr/local/cpanel/base/frontend/x/images/roundcube_logo.png

# cp –reply=yes roundcube_logo.png /usr/local/cpanel/base/webmail/x/images/roundcube_logo.png

# cd /usr/local/cpanel/base

# wget http://www.solsearch.net/HGpatch-roundcube-1.0BETA2

# patch -p0 < HGpatch-roundcube-1.0BETA2

# chattr +i /usr/local/cpanel/base/frontend/x3/webmaillogin.html

# chattr +i /usr/local/cpanel/base/webmaillogin.cgi

Restart the mysql, cpanel services on your server. You are done!, have fun with your new Roundcube installation!!

You can access roundcube by http://yourdomain.com/webmail.

no mysql database size shown in cpanel

You may see the mysql database size is zero in cPanel >> Mysql Databases, though the databases contains tables and data. In order to include the size of the databases while displaying disk usage in cPanel/WHM, use either of the following steps:

1) SSH to your server as root and edit the cpanel.config file

# vi /var/cpanel/cpanel.config

Search for

disk_usage_include_sqldbs=0

and change to

disk_usage_include_sqldbs=1

If the parameter is not present, add it. Save the file and execute the following command:

# /scripts/update_db_cache

OR You may use follwing option in WHM

2) Login to the WHM, goto Tweak Settings >> ‘SQL’ section and enable the following option:

When displaying disk usage in cpanel/WHM include Postgresql and MySQL.

You are done.

Cpanel error Fantastico is not installed at the default location

While accessing the Fantastico in cpanel, you may encounter following error,

Fantastico is not installed at the default location /usr/local/cpanel/3rdparty/fantastico. Either move the Fantastico directory from it’s current location to /usr/local/cpanel/3rdparty/fantastico OR enable ioncube loaders in WHM -> Tweak settings.

To resolve the issue

Make sure ioncube loader is installed and enabled on server. You can check it in WHM >> Tweal Settings

If its not working,

You need to compile cpanel PHP (not server PHP) by

# /scripts/makecpphp

This updates/compiles the version of PHP that cPanel uses internally. Not the same as the PHP account users use to execute scripts. The internal PHP binary is used for the cPanel installed version of PHPMyAdmin, Horde, Squirrelmail and any other PHP Webapp that is internal to cPanel/WHM.

After cpphp, if its still showing the same error,

Try to update the cpanel installation by,

# /scripts/upcp –force

This should resolve the issue.

phpMyadmin error in a cPanel server

Sometimes you may face following error in phpmyadmin

Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.

First thing you’ll neet to do is to check the error logs.(Generally its here /usr/local/apache/logs/error_log). You will probably see errors referencing permission errors writing to your session directory.

Just  change the permission of the session directory (chmod 777) you should be good to go.

If no success….

Login in to the Shell with the root user and then open the file using your favorite editor.

# vi /usr/local/cpanel/3rdparty/etc/phpmyadmin/php.ini

Search for session.save_path and change the following
FROM:
—–
session.save_handler = sqlite
session.save_path = /var/cpanel/userhomes/cpanelphpmyadmin/sessions/
—–
TO
—–
session.save_handler = files
session.save_path = /tmp
—–
Save & Exit
Restart apache

If after upgrade its reverting back, or you don’t want to change the session.save_path in php.ini for phpmyadmin

# mkdir -p /var/cpanel/userhomes/cpanelphpmyadmin/sessions
# chmod 1777 /var/cpanel/userhomes/cpanelphpmyadmin/sessions

and restart the apache service.

You are done !

How to enable allow_url_fopen for a single domain in a cPanel server

The way to enable allow_url_fopen on a phpsuexec and a non-phpsuexec server is different. For security reasons the option is mostly disabled server wide, however, you can turn it ON for a single domain/account if it is required.

Its pretty simple to enable it.

On a non phpsuexec server:

# cd /usr/local/apache/conf/
see if you have a “userdata” directory there? If not, create the “userdata/” directory and then the file allowurl.conf inside it. So the complete path should look like:

# vi /usr/local/apache/conf/userdata//allowurl.conf
and add the following to the file
php_admin_value allow_url_fopen On
php_admin_value allow_url_include On

Now, edit the Apache configuration file and scroll down to the VirtualHost entry of the domain. Include the path of the above created file in it, as shown below:

Include “/usr/local/apache/conf/userdata//allowurl.conf”
Save the file and rebuild the apache configuration by

# /usr/local/cpanel/bin/apache_conf_distiller –update
# /usr/local/cpanel/bin/build_apache_conf
# /scripts/restartsrv httpd
This will enable allow_url_fopen for that domain.

On a PHPSuExec Or SuPHP server:
On a SuPHP enabled server, turning ON allow_url_fopen in the VirtualHost entry won’t work since PHP is not working as a Apache Handler anymore.

In such a case, copy the global php.ini of the server under directory of the domain, say public_html (you need to copy php.ini to the directory, where your script with allow_url_fopen resides)

# cp /usr/local/lib/php.ini /home//public_html/
Edit the new php.ini file and enable allow_url_fopen in it

allow_url_fopen = On
Save the file. That’s it.

please replace “” with the actual username of the domain wherever stated above.

How to enable passive FTP in a Cpanel server

If you are running a FTP server (Pureftp/Proftp) with a CSF firewall (very important in a VPS or virtuozzo), it is necessary to enable passive mode, because this mode works best for ftp clients protected by firewall since the client initiates the connections. If you don’t enable passive mode in VPS, you might encounter problems like unresponsive ftp server or hang or it will not list the directories after FTP connection.

Here are the steps to enable passive FTP.

Login to your server using a SSH client

Open the Pure-FTPd configuration file in your favorite editor

# vi  /etc/pure-ftpd.conf

Uncomment the line that starts with PassivePortRange and add:

PassivePortRange  30000  35000

Restart Pure-FTPd with the command,

# service pure-ftpd restart

If you use a firewall don’t forget to allow inbound connections on the newly added ports.

This can be done by editing CSF firewall,

# vi /etc/csf/csf.conf

and add th ports as below.

# Allow incoming TCP ports
TCP_IN = “20,21,22,25,53,80,110,30000:35000”

and then,

# service csf restart

OR

# csf -r

# service pureftpd restart

Same steps can be followed for proftp as well, in proftpd.conf, you will have to edit the option “PassivePorts”.

 

Log files in a cPanel server

To better troubleshoot an issue in a cPanel server its good go know the various log files, following are some log files which will help in resolution.

General Logs :

cPanel/WHM Initial Installation Errors:
Location : /var/log/cpanel*install*
Description : These log files contain cPanel installation logs & should be referenced first for any issues resulting from new cPanel installations..

Cpanel/WHM Service Status Logs:
Location : /var/log/chkservd.log
Description :The service monitoring demon (chkservd) logs all service checks here. Failed service are represented with a [-] and active services are represented by [+].

Cpanel/WHM Accounting Logs:
Location : /var/cpanel/accounting.log
Description : Contains a list of accounting functions performed through WHM, including account removal and creation..

cPanel/WHM Specific Requests and Errors:

cPanel error logs:
Location : /usr/local/cpanel/logs/error_log
Description : cPanel logs any error it incurs here. This should be checked when you encounter errors or strange behavior in cPanel/WHM…

cPanel License Error Logs:
Location : /usr/local/cpanel/logs/license_log
Description : All license update attempts are logged here. If you run into any errors related to license when logging in, check here.

Stats Daemon Logs:
Location : /usr/local/cpanel/logs/stats_log
Description : The stats daemon (cpanellogd) logs the output from all stats generators (Awstats, Webalizer, Analog) here.

Client Information, Requested URL Logs:
Location : /usr/local/cpanel/logs/access_log
Description : General information related to access cPanel requests is logged here.

cPanel/WHM Update Logs:
Location : /var/cpanel/updatelogs/update-[TIMESTAMP].log
Description : Contains all output from each cPanel update [upcp]. It’s named with the timestamp at which the upcp process was initiated..

Bandwidth Logs:
Location : /var/cpanel/bandwidth
Description : Files contain a list of the bandwidth history for each account. Each named after their respective user.

Tailwatchd [New]:
Location : /usr/local/cpanel/logs/tailwatchd_log
Description : Logs for daemon configuired under tailwatchd ie. cPBandwd, Eximstats, Antirelayd.

Apache Logs:

General Error and Auditing Logs:
Location : /usr/local/apache/logs/error_log
Description : All exceptions caught by httpd along with standard error output from CGI applications are logged here..
The first place you should look when httpd crashes or you incur errors when accessing website.

Apache SuExec Logs:
Location : /usr/local/apache/logs/suexec_log
Description : Auditing information reported by suexec each time a CGI application is executed. Useful for debugging internal server errors, with no relevant information being reported to the Apache error_log, check here for potential suexec policy violations…

Domain Access Logs:
Location : /usr/local/apache/domlogs/domain.com
Description : General access log file for each domain configured with cPanel.

Apache Access Logs:
Location : /usr/local/apache/logs/access_log
Description : Complete web server access log records all requests processed by the server.

Exim :

Message Reception and Delivery:
Location : /var/log/exim_mainlog or /var/log/exim/mainlog
Description : Receives an entry every time a message is received or delivered.

Exim ACLs/Policies based RejectLog :
Location : /var/log/exim_rejectlog
Description : An entry is written to this log every time a message is rejected based on either ACLs or other policies eg: aliases configured to :fail

Unexpected or Fatal Errors:
Location : /var/log/exim_paniclog
Description : Logs any entries exim doesn’t know how to handle. It’s generally a really bad thing when log entries are being written here, and they should be properly investigated..

IMAP/POP/SpamAssassin General Logging and Errors:
Location : /var/log/maillog & /var/log/messages
Description : The IMAP, POP, and SpamAssassin services all log here. This includes all general logging information (login attempts, transactions, spam scoring), along with fatal errors.

FTP:

FTP Logins and General Errors:
Location : /var/log/messages
Description : General information and login attempts are logged here..

FTP Transactions logging:
Location : /var/log/xferlog or /var/log/messages
Description : Is a symbolic link in most cases to /usr/local/apache/domlogs/ftpxferlog, which contains a history of the transactions made by FTP users…

MySQL:

MySQL General Information and Errors :
Location : /var/lib/mysql/$(hostname).err
Description : This path could vary, but is generally located in /var/lib/mysql. Could also be located at /var/log/mysqld.log

Security:

Authentication attempts:
Location : /var/log/secure
Description : Logs all daemons which requires PAM Authentication.

Tracking all Bad Logins and Logouts:
Location : /var/log/btmp
Description : Log of all attempted bad logins to the system. Accessed via the lastb command..

Tracking all Logins and Logouts:
Location : /var/log/wtmp
Description : The wtmp file records all logins and logouts.

Last Logins:
Location : /var/log/lastlog
Description : Database times of previous user logins. The lastlog file is a database which contains info on the last login of each user.

WebDav or WebDisk Log :
Location : /usr/local/cpanel/logs/cpdavd_error_log
Description : The cpdavd daemon is “WebDav” (better known as “WebDisk”) which was introduced in cPanel 11 to allow users to mount their home directory on their personal computer, always having access to the files and content…

Cphulkd Logs:
Location : /usr/local/cpanel/logs/cphulkd_errors.log
Description : cPHulk Brute Force Protection prevents malicious forces from trying to access your server’s services by guessing the login password for that service….
It blacklists IPs that it thinks are trying to run a brute force attack.

Failure Logging:
Location : /var/log/faillog
Description : Faillog formats the contents of the failure log from /var/log/faillog database. It also can be used for maintains failure counters and limits. Run faillog without arguments display only list of user faillog records who have ever had a login failure.

Startup/Boot, Kernel & Hardware error messages :
Location : /var/log/dmesg
Description : dmesg is a “window” into the kernels ring-buffer. It’s a message buffer of the kernel. The content of this file is referred to by the dmesg command. It shows bootlog and the hardware errors..

Tomcat:

General Startup, Shutdown & Error Logs:
Location : /usr/local/jakarta/tomcat/logs/catalina.err and /usr/local/jakarta/tomcat/logs/catalina.out
Description : Logs for Tomcat and all tomcat based applications…

Mysql database backup and restore

If you’re storing anything in MySQL databases that you do not want to lose, it is very important to make regular backups of your data to protect it from loss. It is always good to have backup copy of everything. This tutorial will show you easy steps to backup and restore the data in your MySQL database.

Creating A Backup

The mysqldump command is used to create textfile “dumps” of databases managed by MySQL. These dumps are just files with .sql format which are used to restore the database in case of any database loss.

If you want to back up a single database, you can create the dump and send the output into a file by

# mysqldump database_name > database_name.sql

Multiple databases can be backed up at the same time

# mysqldump –databases database_one database_two > two_databases.sql

It is also simple to back up all of the databases on a server

# mysqldump –all-databases > all_databases.sql

Restoring a Backup

Since the dump files are just .sql files, you can restore the database backup by

# mysql database_name < database_name.sql

If you are trying to restore a single database from dump of all the databases, you have to let mysql know like this

# mysql –one-database database_name < all_databases.sql

Here is the proper syntax if there is password for mysql for root user.

# mysqldump –opt -u [uname] -p[pass] [dbname] > [backupfile.sql]

[uname] Your database username

[pass] The password for your database (note there is no space between -p and the password)

[dbname] The name of your database

[backupfile.sql] the filename for your database backup

[–opt] The mysqldump option.

For example, to backup a database named ‘database_name’ with the username ‘root’ and with no password to a file database_name.sql ,

# mysqldump -u root -p database_name > database_name.sql

This command will backup the ‘database_name’ database into a file called database_name.sql which will contain all the SQL statements needed to re-create the database.

With mysqldump command you can specify certain tables of your database you want to backup. For example, to back up only “tableone” and “tabletwo” tables from the ‘database_name’ database use the command below. Each table name has to be separated by space.

# mysqldump -u root -p database_name tableone tabletwo > tables.sql

Sometimes it is necessary to back up more than one database at once. In this case you can use the –database option followed by the list of databases you would like to backup. Each database name has to be separated by space.

# mysqldump -u root -p –databases database_name database_name2 > databases_backup.sql

If you want to back up all the databases in the server at one time you should use the –all-databases option. It tells MySQL to dump all the databases it has in storage.

# mysqldump -u root -p –all-databases > alldb_backup.sql

The mysqldump command has also some other useful options:

–add-drop-table: Tells MySQL to add a DROP TABLE statement before each CREATE TABLE in the dump.

–no-data: Dumps only the database structure, not the contents.

–add-locks: Adds the LOCK TABLES and UNLOCK TABLES statements you can see in the dump file.

The mysqldump command has advantages and disadvantages. The advantages of using mysqldump are that it is simple to use and it takes care of table locking issues for you. The disadvantage is that the command locks tables. If the size of your tables is very big mysqldump can lock out users for a long period of time.

Back up your MySQL Database with Compress

If your mysql database is too big, its good to compress the output of mysqldump. Just use the mysql backup command below and pipe the output to gzip, then you will get the output as gzip file.

# mysqldump -u [uname] -p[pass] [dbname] | gzip -9 > [backupfile.sql.gz]

If you want to extract the .gz file, use the command below

# gunzip [backupfile.sql.gz]

Restoring your MySQL Database

Above we backup the database_name database into database_name.sql file. To re-create the database_name database, you can use following commands

Create an empty database on the serverLoad the file using the mysql command

# mysql -u [uname] -p[pass] [database_name] < [database_name.sql]

To restore compressed backup files you can do the following

# gunzip < [backupfile.sql.gz] | mysql -u [uname] -p[pass] [dbname]

If you want to restore a database that already exists, you’ll have to use mysqlimport command. The syntax for mysqlimport is as below

# mysqlimport -u [uname] -p[pass] [dbname] [backupfile.sql]

Backing up database by using PHPMYADMIN

phpMyAdmin is the most popular web-based interface to MySQL and is usually preinstalled in most shared hosting accounts. Through it, you can perform any action on the database including backups and restoration. You can use phpMyAdmin to backup/restore your database if it is relatively small ie upto 8 to 10 MB. For bigger databases, you can use above method.

To back up your database, open your phpMyAdmin page in your web browser and select your database from the dropdown on the left. From the main database page, click on Export tab on the top button bar.

1. Select the database you’d like to back up from the column on the left side of phpMyAdmin.

2. Click on Export tab on the top button bar.

3. Select the tables from the list that you would like to backup. If you want to backup the entire database, check Select All.

4. Select Structure and data from the bullet list.

5. Check the Add ‘drop table box if you are moving the database to a new location and don’t want to merge the old table with an existing one.

6. Click the Save as file box.

7. Use the Save as file zipped if you want to compress the backup before downloading it from the server.

8. Click the Go button, when prompted save the file to your local computer.

Restoring via PHPMYADMIN

1. From the column on the left select the database that you want to restore to. If one doesn’t exist you must first create it.

2. Click on Import from the top set of tabs.

3. Click on the Browse button next to Location of the textfile near the bottom.

4. Browse to the local backup and click Open.

5. If you have the local backup in a non-text file format, e.g. you selected save as file: zipped when you backed up the database, you’ll have to unzip the file on your local computer before you can select it during this step.

6. Click the Go button.

7. Done…Your SQL-query has been executed successfully.

Softaculous Installation

Softaculous is an Instant/Auto Installer. Softaculous helps users to install free/opensource softwares in minutes. A user can install a software, available in Softaculous, without having to download/upload any files.

Unlike other auto installers Softaculous is much faster, well designed and it installs all scripts in just ONE STEP.
Please see detailed Comparison of Softaculous and other auto installers.

Softaculous is available as a FREE or a Premium Auto Installer. The Free License has 60/69 scripts while the Premium one has 176 scripts.

You can check the demo here.

Installing Softaculous

Note: Before starting the installation make sure ionCube Loaders are enabled. For that go to WHM and click on Tweak Settings. Please make sure that the Ioncube loader is selected for the backend copy of PHP. Now SSH to your server and enter following commands:

cd /usr/local/cpanel/whostmgr/docroot/cgi
wget -N http://www.softaculous.com/ins/addon_softaculous.php
chmod 755 addon_softaculous.php

Now go to : WHM > Plugins (Add-Ons on older versions than 11) > Softaculous – Instant Installs The following webpage will open if the installation was successful.

Now, just wait for the scripts to get downloaded. The download status is shown in the iFRAME.

That’s it the installation of Softaculous is completed!