We do support Round the Clock 24 x 7 x 365 (+91) 883 012 3924
header-image

L3 Web Hosting Blog

cPanel, Plesk, Wordpress Hosting SSD disk

Check out L3WebHosting blog for tips and in-depth articles on web hosting services !!

How to Reduce WordPress Admin Ajax Server Load

Sometimes wordpress admin Ajax script creates load on the server.
WordPress Heartbeat API was introduced in WordPress 3.6 version.
The WordPress Heartbeat API uses wp-admin/admin-ajax.php to run AJAX calls from the browser. The purpose of this API is to improve user session management, auto-saving, revision tracking.

However, sometimes it causes high CPU usage and crazy amounts of PHP processes.
For example, if you leave your wordpress dashboard open, it will keep sending POST requests on a regular interval, hence can cause the Heartbeat API to continually spawn PHP processes which uses CPU.

Heartbeat control wordpress plugin can help you fix this problem.
Follow the steps below to configure.

# Login to wp-admin of your website
# Install Heartbeat control plugin
# Go to Settings and click into “Heartbeat Control.”

# Under “Control heartbeat locations” you have a couple options, select any option as per your need

  • Use default
  • Disable everywhere
  • Disable on dashboard page
  • Allow only on post edit pages

# Then you can set frequency for the heartbeat polling.

Hopefully, it will take care of some of your problems.

How to block search bots from accessing your website

Robots.txt is a small text file which needs to create in the root directory of your website.
On cPanel server, you will need to put robots.txt fiile into /public_html/ folder.

It tells well-behaved crawlers whether to crawl certain parts of the site or not. The file uses a simple syntax to be easy for crawlers to put in place.

In order to block all bots from accessing your site, you need to create a robots.txt file with the following content:

User-agent: *
Disallow: /

To block all bots from accessing a specific folder, you should create a robots.txt file with the following content:

User-agent: *
Disallow: /folder/

You can create/modify the robots.txt file via File Manager in cPanel.

Useful Exim commands

Display the number of email messages in the queue

# exim -bpc

Display information about email messages in the queue

# exim -bp

Display a summary of messages in the queue

# exim -bp | exiqsumm 

Display Exim’s current activity

# exiwhat

Test Exim SMTP transaction

# exim -bh ipaddress 

Display Exim settings of your server

# exim -bP

How to enable the MySQL slow query log

You can use the slow query log to help determine which database queries take a long time to run. However, the slow queries can affect database performance and overall server performance.

Follow below steps to enable the mysql slow query log on your server :
# Login to SSH shell with root user
# vi /etc/my.cnf

# Add below lines under the [mysqld] section:

slow_query_log = 1
log-slow-queries = /var/log/mysql-slow.log
long_query_time = 2


Note : where long_query_time – time taken by an SQL query to be executed in seconds. If a query takes longer than the value specified, this query will be recorded in the slow query log file.

Note: In MySQL 5.7, the variable log-slow-queries is deprecated so use slow_query_log_file instead of log-slow-queries .

# Save and close /etc/my.cnf file.

# touch /var/log/mysql-slow.log
# chown mysql:mysql /var/log/mysql-slow.log
# service mysqld restart

You can test your log file is working by typing
# tail -t /var/log/mysql-slow.log


How to Harden Your cPanel System’s Kernel

Warnings:

  • cPanel-provided hardened kernel update deprecated in cPanel & WHM version 68.
  • The cPanel-provided kernel update will not work for container-based systems like OpenVZ®,Virtuozzo® etc
  • This document only applies to systems installed with CentOS 6 64-bit systems.
  • We strongly suggest that only experienced System Administrators perform this process.

To harden your cPanel system’s kernel, log in to your server as the root user via SSH and perform the following steps:

# cd /etc/yum.repos.d/   
# wget https://securedownloads.cpanel.net/cPkernel/cPkernel.repo
# yum -y update kernel

After you update the kernel, you must restart the system to complete the kernel update. To reboot the server, run the reboot command.

After you reboot the server, verify that the cPanel Hardened Kernel update succeeded with below command :

# uname -r

If the command’s output includes cpanel in the returned value, you successfully updated the kernel.

How to Modify your hosts File


On cPanel server, “mod_userdir” (WHM >> Home >> Security Center >> Apache mod_userdir Tweak) allows you to access website through a temporary URL in the http://IP/~username format.
However, some sites will not work with a temporary URL like wordpress.
For those sites, you can configure your windows computer with the server’s IP address into “hosts” file so you can view website without pointing DNS to your server.

Follow below steps to modify the “hosts” file on a Windows® 8 or Windows® 10 system :

1. On your keyboard, type Win+X on the keyboard, or click the windows icon in the lower-left corner of your desktop interface to to open the Start menu.
2. Enter Notepad in the search text box.
3. Right-click Notepad and select Run as Administrator.
4. From the Notepad , open the following file:
C:\Windows\System32\Drivers\etc\hosts 

5. Add the destination server’s IP address and domain name under the latest entry in the file, for example:

127.0.0.1 localhost localhost.localdomain localhost4 
1.2.3.4 example.com
1.2.3.4 www.example.com
1.2.3.4 blog.example.com

Note:
In this example, 1.2.3.4 represents the destination server’s IP address, and blog.example.com represents the domain name.
6. Save your changes.
7. Reload your web browser for the changes to take effect.

To modify the “hosts" file on a Windows® 7 or Windows Vista® system, perform the following steps:

  1. Click Start.
  2. Enter Notepad in the Start menu search text box.
  3. Right-click Notepad and select Run as Administrator.
  4. From the Notepad, open the following file: C:\Windows\System32\Drivers\etc\hosts 
  5. Add the destination server’s IP address and domain name under the latest entry in the file, for example:
127.0.0.1 localhost localhost.localdomain localhost4 
1.2.3.4 example.com
1.2.3.4 www.example.com
1.2.3.4 blog.example.com

Note: In this example, 1.2.3.4 represents the destination server’s IP address, and blog.example.com represents the domain name.

6. Save your changes.
7 . Reload your web browser for the changes to take effect.

How to check the resource usage on the server

If there is a high load on your server and you need to find out exact processes & users are consuming your server resources.
In such case, we can use “ps” command.

Here are some useful commands :

# To list top 10 CPU usage processes with user

# ps -e -o pcpu,pid,user,args|sort -k1 -nr|head -10

# Find out top 10 CPU consuming process

# ps -auxf|sort -nr -k3|head -10

# To list top 10 Memory consuming processes with user

# ps -e -o pmem,pid,user,args|sort -k1 -nr|head -10

# Find out the top 10 memory consuming process

# ps -auxf|sort -nr -k4|head -10

# Find out every process running under a user

# ps -U user-name -u user-name u

Or

# ps -e -o pid,user,args|grep $username

How to change default PHP version on cPanel server through command line

In WHM, you can change the default PHP version through Multi-PHP Manager.
However, if you want to change the global default PHP version through command line you can follow below steps :

To display the current default PHP version :

# /usr/local/cpanel/bin/rebuild_phpconf –current

Above command is showing PHP 5.6 as default php version. Now we will change it to PHP 7.0 version with below command

# /usr/local/cpanel/bin/rebuild_phpconf –default=ea-php70

How to disable security questions on cPanel WHM server

cPanel / WHM allows you to setup Security Policies for cPanel/whm login page.

If you have configured Security Policies with security questions and you forgot it’s answers, you will not able to login to cPanel / WHM.

Please perform the following steps to disable security questions via the command line :

 

  1. Use SSH to log in to your server with root user.
  2. Open the /var/cpanel/cpanel.config file in your preferred text editor.
  3. Change the value of the SecurityPolicy::SourceIPCheck option to 0.
  4. Save and exit the file.
  5. Run the /scripts/restartsrv cpanel command to restart cPanel & WHM service.