Category Archives: cPanel/WHM

cPanel – Install Nginx + Varnish alongside Apache !

Nginx is a very fast webserver when compared with the default Apache offered by cPanel. Nginx is known for its high performance and low resource consumption. Servers hosting WordPress sites are employing Nginx as it improves the performance.

Nginx will work as a front end reverse proxy of your cPanel server along with apache, which will increase the performance. We have a plugin called ‘Nginx Admin’ which is a cPanel Nginx integration plugin.

Use the following steps to install it on a cPanel server :

1 ) Download the source files :

# cd /usr/local/src
# wget http://nginxcp.com/latest/nginxadmin.tar
# tar xf nginxadmin.tar
# cd publicnginx

2) Generate a Remote Access Key.

Generate a key by logging into WHM, going to Clusters, then Remote Key Access, and then clicking Generate New Key.

3) Run the script

# ./nginxinstaller install

This Nginx installation method integrates with WHM/cPanel and uses the Apache configuration files that WHM/cPanel uses by default.

After installation you can go to WHM, Plugins, and Nginx Admin to handle Nginx. From there you can restart Nginx, edit the configuration files, view logs, and more.

You can also restart Nginx on the command line with the Apache command:

# /etc/init.d/httpd restart

Now lets move ahead with the installation of Varnish.

Varnish is a caching technology known as web accelerator which is used as reverse HTTP proxy, which will enhance the performance of your website.

Varnish stores a copy of the page which is served by the web server the first time a user visits the website. Next time, when the user requests for the same page, varnish will serve the copy instead of serving it from the web server. Thus, your webserver is seldom bought into the lime-light if the used pages are being fetched, which improves the performance.

Before moving ahead, we will bind our webserver to the port 8081, in the file – /usr/local/apache/conf/httpd.conf,

Change the Portion – Listen 0.0.0.0:80 to Listen 0.0.0.0:8081 and restart the webservice.

Now, lets download and install the Varnish !

1) Add the repo : ( check the version of your OS ) : the URL given below is for CentOS / Redhat 5.x versions :

# wget http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm

# rpm -Uvh varnish-release-3.0-1.noarch.rpm

2) Install the service :

# yum install varnish

3) Edit the configuration file for varnish – /etc/sysconfig/varnish and change the value of VARNISH_LISTEN_PORT to 80

# grep VARNISH_LISTEN_PORT /etc/sysconfig/varnish
VARNISH_LISTEN_PORT=80
4)  Edit Varnish config: /etc/varnish/default.vcl . Correct the backend default Port to reflect – 8081 ( the port to which webserver was bind to )

backend default {
.host = “YOUR IP ADDRESS”;
.port = “8081”;
}

5) Start Varnish service on your server

# chkconfig varnish on

# service varnish start

You are done with installing Nginx and varnish in your cPanel server, which should improve your speed and performance.

 

cPanel – Installing Memcached !

Caching mechanisms are always useful to improve the speed and performance of the services being provided. Especially when you have dynamic webpages that are required to be loaded up, caching mechanisms, if enabled can be used to load the pages up quickly without bottle-necking the server.

Memcache(d) – | ‘d’ for daemon |  is an open source caching method used to speed-up webpages and its parsing.

Steps to install it on a cPanel based server is given below :

# yum install memcached ( ensure the EPEL repo’s are enabled ) : help needed on this ? Check this third-party link

# service memcached start – start the service.

# pecl install memcache – Install PHP memcache.

Now, make sure the memcache module is referenced in the php.ini file. If not, add the memcache extension in php.ini file.

# echo "extension=memcache.so" >> /usr/local/lib/php.ini

# service httpd restart

# chkconfig --levels 235 memcached on : To ensure memcached will be up even after a server reboot:

# php -m | grep memcache – check if you are good to go !

You can find the configuration file at –  vi /etc/sysconfig/memcached

Dont forget to open the port in your Firewall !

 

cPanel – Install Google mod_pagespeed module for Apache

“mod_pagespeed is an open-source Apache module created by Google to help Make the Web Faster by rewriting web pages to reduce latency and bandwidth” – http://modpagespeed.com/

To incorporate this module to your Apache webserver in a cPanel running server, do the following steps :

Note : This is meant for Apache 2.2.x versions.

1) Clone the installation scripts to the server :

# /usr/local/cpanel/3rdparty/bin/git clone https://github.com/pagespeed/cpanel.git /tmp/pagespeed/

2) Create a tar.gz custom_opt_mod for EasyApache script to be detected :

# cd /tmp/pagespeed/Easy
# tar -zcvf Speed.pm.tar.gz pagespeed

3) Move the custom mod to the place which is scanned by EasyApache ( create that folder, if not already present ) :

# mv Speed.pm Speed.pm.tar.gz -t /var/cpanel/easy/apache/custom_opt_mods/Cpanel/Easy/

4)  Remove the cloned script from /tmp

cd && rm -rf /tmp/pagespeed

Now, login to your cPanel WHM > EasyApache and look for “mod_pagespeed” option under the short lists along with other Apache modules. Select it,  make sure to enable deflate and version module.  Re-compile Apache webserver using this and you are good to go with PageSpeed.

– The default conf file will be under – /usr/local/apache/conf/

– Refer these sites to customize your configurations :

https://developers.google.com/speed/pagespeed

modpagespeed.com

 

cPanel upgrade to 11.50.x – issues with horde database ?

Prior to cPanel & WHM version 11.50,  Horde user data was stored in a single server-wide MySQL database. However, in 11.50, cPanel moved these data to individual SQLite database for each cPanel account.

Recently, during the upgrade, several users are seeing this failure message :

While attempting to back up Horde database, mysqldump did not exit cleanly: 2

For more information about the exact nature of the failure, review the /var/cpanel/logs/horde_mysqltosqlite_log file. cPanel & WHM versions 11.50 and later require SQLite for Horde data storage. Any Horde data that the system could not migrate is not visible to Horde users.

Review the log file as mentioned and see if the entire conversion has failed.

The command to perform the conversion in full on a server that did not get a chance to begin the conversion would be :

# /scripts/horde_mysqltosqlite

If you encounter a server that has been partially completed according to the output of the conversion process  /var/cpanel/logs/horde_mysqltosqlite_log , then it can be performed for a single user as per the logs using the following command :

# /usr/local/cpanel/3rdparty/bin/perl -MCpanel::Horde::MySQLToSQLite -e 'Cpanel::Horde::MySQLToSQLite->new->convert_user("cpanelaccountname")'

Replace ‘cpanelaccountname‘ with the concerned cpanel account name viewed from the logs !

 

Corrupt Roundcube tables in WHM ?

Are you getting a message from cPanel saying something like ?


check_mysql has determined that there are corrupted database tables .

cPanel & WHM has determined that the following database tables are corrupt: 

Error : Table 'roundcube.contacts' doesn't exist
roundcube.identities.
Error : Table 'roundcube.identities' doesn't exist
roundcube.messages
Error : Table 'roundcube.messages' doesn't exist
roundcube.session
Error : Table 'roundcube.session' doesn't exist

The roundcube database on the server might have got corrupt. You can re-generate the database by stopping the MySQL service, moving away the corrupt ones, restarting the service and then moving ahead with updating roundcube :

# /etc/init.d/mysql stop

# mv /var/lib/mysql/roundcube/ var/lib/mysql/roundcube_bk

# /scripts/restartsrv_mysql

# /usr/local/cpanel/bin/update-roundcube --force

Once this is done, you will be able to access roundcube and the databases will be fixed !

 

Upgrade / install a different version of Python in CentOS !

The Python version which comes along with CentOS is usually 2.4.x, which is way behind and some of the applications / scripts would require a newer version of Python.

Upgrading Python in a cPanel environment using yum is not preffered as it may break services / managers including yum which is dependent on Python.

The best option will be to install a different version of Python at a different location. The default Python binary will be at /usr/bin/python. We can install the newer one at an alternate location. Following steps will help you :

cd /usr/src

wget https://www.python.org/ftp/python/3.0/Python-3.0.tgz

( You can download a different version if you prefer, just go to the above URL – deleting upto /3.0.. and check for the versions )

tar -xvzf Python-3.0.tgz

cd Python-3.0

./configure –prefix=/usr/local

make

make install

Now, Python3.0 will be installed in /usr/local and the binary will be available at /usr/local/bin/python3.0 and you can use this path as reference to scripts / apps which require the newer version.

That’s it !

 

Remove the option to change the theme for a cPanel user !

There might be situations in which a particular cPanel user mess with his themes and you would want to limit his privilages so that he cant change the theme to a specific one or two. Perhaps you do not want him to change to X Theme or Paper Lantern.

To do this, login to your server as root and create the following file :

/var/cpanel/themes.conf

Edit the file and mention the list of themes which you want to be in the switch theme dropbox in cPanel interface.

For example, if you do not want X theme, the content of the above file would be :

 

# cat /var/cpanel/themes.conf
x3
paper_lantern
x2

If you want the X theme and do not want paper_lantern, just give x in place of paper_lantern in the file.

That’s it !

 

MySQL databases not showing up space in cPanel

When trying to view the databases from the cPanel interface of an account, you might end up with no values at all. However, if you check the backend, you can find that these database folders consumes space.

To fix this issue, SSH to the server and open the file :  /var/cpanel/cpanel.config and make sure the variable disk_usage_include_sqldbs is set to 1 ( instead of 0 )

Once that change is made, hit the following from the shell :

# /scripts/update_db_cache

This should fix the issue !

 

Blocking all mails originating from a domain in your cPanel server !

Basically, there are times when a particular domain in your server is involved in spamming or excessive mail delivery and you just want to block that domain alone from sending mails.  With the current setup with cPanel, it is not straightforward to establish this.

We will see how to do this step-by-step.

First, login to your WHM and navigate to, Home »Service Configuration »Exim Configuration Manager » Advanced editor

Find the portion “ROUTERS CONFIGURATION” and right under the section – PREROUTERS, give the following piece of code :

reject_domains:

driver = redirect
# RBL Blacklist incoming hosts
domains = +exim_blacklist
allow_fail
data = :fail: Connection rejected: Sorry dude :/

Once this is done, save the configuration.

Next, SSH to your server and open the file /etc/exim.conf for editing.

Open it and right after the first line (usually it is something like)  “#!!# cPanel Exim 4 Config”,  give in the following and save the file :

domainlist exim_blacklist = lsearch;/etc/eximblacklist

Save the file and restart exim.

Now, all you need to do is enter the concerned domain(s) in the file ‘/etc/eximblacklist‘ ( one domain – each line )

Now, when you test to see if you can send a mail from the domain, the following can be seen in logs :

DATE H=localhost (xxxxx]:44411 sender verify fail for <test1@domain.com>: Connection rejected: Sorry dude :/

This is it, do you still face any issue ? Post a comment below with the error / issue you get !

 

Clicking on email accounts from cPanel throwing an error ?

When you click on email accounts from cPanel, do you face this error ?

A fatal error or timeout occurred while processing this directive.

Undefined subroutine &Cpanel::ExpVar::expand_and_detaint called at cpanel.pl line 963.main::real_cpexectag(“<?cp StatsBar::stat( [p class=\”caution\” style=\”margin:20px 0\””…) called at cpanel.pl line 4293main::dotag_finished_headers(0) called at cpanel.pl line 4110 main::cpanel_parseblock(“<cpanel setvar=\”headerimg=../images/mailmenu.gif\”>\x{a}<cpanel se”…) called at cpanel.pl line 4024 main::y(GLOB(0x47fb938)) called at cpanel.pl line 5393 main::run_standard_mode() called at cpanel.pl line 828

This is due to a bug in x3 theme in cPanel. Reverting the theme to paper_lantern should fix this error ! I was not able to find any other fix after hours of searching !

Hope it helps !