Monthly Archives: March 2020

Change default PHP version in WHM

With the cPanel MultiPHP Manager utility you can have multiple PHP versions installed on your web hosting server. In this article, we will show to change the default PHP version in WHM.

WHM MultiPHP Manager

To change the default PHP version in WHM:

1. Log in with root credentials to WHM

2. Navigate to Software-> MultiPHP Manager

3. In the System PHP Version section, click the Edit link

4. From the drop-down list that will appear, select the default version you wish to use. Click the Apply button.
You will see a confirmation message. In our case:

Success: The system default PHP version has been set to “PHP 7.3 (ea-php73)”.

Notice that the change will apply only to domains that inherit the PHP version. The domains where the PHP version was manually set will keep the specified versions.

Related articles:
How to change PHP version in cPanel

Cloudflare Errors – Web server is down/Connection timed out

The two most common Cloudflare errors are 521 – Web server is down and 522 – Connection timed out. You can read more about this error by following the links from the References section. In many cases, these errors are caused by the firewall blocking the Cloudflare request. The first step in troubleshooting the issue is to whitelist the Cloudflare IPs.

Cloudflare error

At the time of writing the Cloudflare IPs are:

#cloudflare start IPv4
173.245.48.0/20
103.21.244.0/22
103.22.200.0/22
103.31.4.0/22
141.101.64.0/18
108.162.192.0/18
190.93.240.0/20
188.114.96.0/20
197.234.240.0/22
198.41.128.0/17
162.158.0.0/15
104.16.0.0/12
172.64.0.0/13
131.0.72.0/22
#cloudflare end

Cloudflare IPv4 IPs

#cloudflare start IPv6
2400:cb00::/32
2606:4700::/32
2803:f800::/32
2405:b500::/32
2405:8100::/32
2a06:98c0::/29
2c0f:f248::/32
#cloudflare end

Cloudflare IPv6 IPs

You should whitelist these two sets of IPs on your server. As many web hosting servers are using CSF, you should add these IPs to the file /etc/csf.allow. Don’t forget to restart it.

References:
Cloudflare error 521
Cloudflare error 522

Redirect HTML extension to PHP

It’s very easy to redirect requests to .html pages to .php pages. You will need to add some lines to the .htaccess file. If this file doesn’t exist in your directory then you must create it.

The two lines are:

RewriteEngine On
RewriteRule ^(.*).html$ /$1.php [L,R]

Now, html files will be redirected to php file. E.g. https://domain.com/test.html will be redirected to https://domain.com/test.php

Redirect *.html to *.php

cPanel reporting incorrect /mail/ directory size

Many times, cPanel is reporting an incorrect value in cPanel->Disk Usage interface. In our test case the value from the shell is 308MB:

root@web [/home/mmtest]# du -sh mail
308M    mail
root@web [/home/mmtest]#

But the value reported in cPanel is 462.99MB as shown in the image below:

mail directory size 1

This is caused by the dovecot server not updating correctly the disk usage. to fix this situation, run the commands:

# /scripts/generate_maildirsize –confirm –allaccounts –verbose $username

root@web [/home/mmtest]# /scripts/generate_maildirsize --confirm --allaccounts --verbose mmtest
Rebuilding the maildirsize files for: mmtest
Rebuilding the maildirsize files for: john@mmtest123.com
Checking user mmtest
Calculating diskusage and diskcount from reading files
Writing /home/mmtest/mail/maildirsize for user merches
Checking user john@mmtest123.com
Calculating diskusage and diskcount from reading files
Writing /home/mmtest/mail/mmtest123.com/john/maildirsize for user john
root@web [/home/mmtest]#

Now the disk usage is reported correctly in cPanel:

mail directory size 2

To run the command for all the accounts use
# /scripts/generate_maildirsize –confirm –allaccounts –verbose

More information on this cPanel script can be found by running
# /scripts/generate_maildirsize –help

Redirect site to another URL except for a specific directory

You are moving your site to another domain. You want to redirect users to the new domain. But you have a script on a directory that you still want to access on the old domain.

The necessary lines that must be added to your .hatccess file are:

RewriteEngine on
RewriteRule !^(script_directory) https://newdomain.com%{REQUEST_URI} [R=301,L]

If you want to redirect two directories, separate them with | :

RewriteEngine on
RewriteRule !^(directory1|directory2) https://newdomain.com%{REQUEST_URI} [R=301,L]

The code will keep the path – for example olddomain.com/dir1/file1.php will be redirected to newdomain.com/dir1/file1.php

Resources:
RewriteRule Directive

Page 1 of 2
1 2