Difference between revisions of "Further Security Steps"

From WHMCS Documentation

(Vendor Directory)
m
Line 1: Line 1:
WHMCS has many features built-in to help keep your data safe, but here are several simple extra steps you can take to secure your WHMCS installation even further.
+
WHMCS includes many features to help keep your data safe, but you can simple additional steps to secure your WHMCS installation further.
  
 
==Secure the Writeable Directories==
 
==Secure the Writeable Directories==
  
We recommend moving all writeable directories to a non-public location to prevent web based access. There are three writeable directories required for WHMCS to function, they are: ''attachments'', ''downloads'' and ''templates_c''
+
We recommend moving all writeable directories to a non-public location to prevent web based access. There are three required writeable directories: ''attachments'', ''downloads'' and ''templates_c''
  
WHMCS needs to be given the new location of the writeable directories. This is done in two places:
+
You must specify the new location of the writeable directories in WHMCS. This is done in two places:
  
 
===File Storage===
 
===File Storage===
The ''attachments'' and ''downloads'' storage directories can be moved to a local location or stored remotely on an AWS S3-compatible service. If you are unfamiliar with the AWS S3 service we recommend using the local storage option.
+
 
 +
You can move the ''attachments'' and ''downloads'' storage directories to a local location, or you can store them remotely on an AWS S3™-compatible service. If you are unfamiliar with the AWS S3 service, we recommend using the local storage option.
 +
 
 +
To do this:
  
 
# Create the storage location. This could be either:
 
# Create the storage location. This could be either:
#* A writeable directory on your server above the web-root
+
#* A writeable directory on your server above the web root.
 
#* A non-public AWS S3-compatible storage bucket.
 
#* A non-public AWS S3-compatible storage bucket.
# Navigate to '''Setup > Storage Settings'''
+
# Navigate to '''Setup > Storage Settings'''.
 
# Use the interface to add the secure storage locations and switch to them.
 
# Use the interface to add the secure storage locations and switch to them.
  
For step-by-step guidance using this interface please refer to [[Storage Settings]].
+
For step-by-step guidance using this interface, see [[Storage Settings]].
  
 
===Templates Cache===
 
===Templates Cache===
The templates cache (''templates_c'') is used to improve performance of templated pages and emails.
 
  
# Create a ''templates_c'' directory in the desired location (a non-public location above your web root)
+
You can use the templates cache (''templates_c'') to improve performance of templated pages and emails.
 +
 
 +
To do this:
 +
 
 +
# Create a ''templates_c'' directory in the desired location (a non-public location above your web root).
 
# Edit the ''configuration.php'' file and specify the path to the new location by adding a new line:
 
# Edit the ''configuration.php'' file and specify the path to the new location by adding a new line:
 
<source lang="php">
 
<source lang="php">
 
$templates_compiledir = "/home/username/templates_c/";
 
$templates_compiledir = "/home/username/templates_c/";
 
</source>
 
</source>
 +
In the above example, "username" is the cPanel username and the folder is in the home directory, above <tt>public_html</tt>.
 +
<div class="docs-alert-info">
 +
If you are running suPHP or PHP suEXEC, <tt>chmod 755</tt> should be sufficient permissions to make the directories writeable. This is the highest permission available for both folders and files when running in that condition.
 +
</div>
  
In the above example, "username" is the cPanel username and so the folder is located in the home directory, above public_html.
+
==Secure the configuration.php File==
  
<div class="docs-alert-info">Note that if you are running suPHP or phpSuExec chmod 755 should be sufficient permissions to make the directories writeable as this is the highest permission available for both folders and files when running in that condition.</div>
+
We recommend adjusting the permissions for the "configuration.php" file in your WHMCS root directory. This file contains sensitive data that you can't recover without a backup of the file. To avoid accidentally overwriting, editing or deleting the file, change the permission setting of this file to <tt>400</tt>.  This provides the system with read-only access and prevents anyone else from reading, editing or executing the file.
  
==Secure the `configuration.php` File==
+
To change the permissions on this file, you can run the following command while in your WHMCS root directory:
 
 
We recommend adjusting the permissions set for the "configuration.php" file located in your WHMCS root directory.  This file contains sensitive data that cannot be recovered without a backup of the file.  To avoid accidentally overwriting, editing or deleting the file, change the permission setting of this file to `400`.  This provides read only access to the file by the system and prevents anyone else from reading, editing or executing the file.
 
 
 
To change the permissions on this file, you can run the following command from shell while in your WHMCS root directory:
 
 
<pre>
 
<pre>
 
chmod 400 configuration.php
 
chmod 400 configuration.php
Line 42: Line 48:
 
<div class="docs-alert-warning">
 
<div class="docs-alert-warning">
 
<span class="title">Attention!</span>
 
<span class="title">Attention!</span>
<p>Some systems may require you to set the permission to 440 or 444 depending on how the server is configured. For most, 400 should suffice, but if you encounter an error loading the application after setting the permission to 400, try 440 and then 444.</p>
+
<p>Some systems may require you to set the permission to <tt>440</tt> or <tt>444</tt>, depending on the server's configuration. Usually, <tt>400</tt> should suffice, but if you encounter an error loading the application after setting the permission to <tt>400</tt>, try <tt>440</tt> and then <tt>444</tt>.</p>
 
</div>
 
</div>
 
<div class="docs-alert-warning">
 
<div class="docs-alert-warning">
 
<span class="title">License Key Updates</span>
 
<span class="title">License Key Updates</span>
<p>Should you need to ever update your license key, you must set the permissions on this file to 755 to allow the system to edit the file. Once the key is updated, you can revert the permissions to 400.</p></div>
+
<p>If you need to update your license key, you must set the permissions on this file to <tt>755</tt> to allow the system to edit the file. After the updating the key, you can revert the permissions to <tt>400</tt>.</p></div>
  
 
==Move the Crons Directory==
 
==Move the Crons Directory==
Line 54: Line 60:
 
==Restrict Access by IP==
 
==Restrict Access by IP==
  
For increased protection, if your staff use fixed IP addresses, you can add even more protection to your admin area by restricting access to a specific set of IPs.  This is done by creating a file with the name .htaccess within your WHMCS admin directory, with the following content:
+
For increased protection, if your staff uses fixed IP addresses, you can restrict access to a specific set of IPs.  To do this, create a file with the name <tt>.htaccess</tt> in your WHMCS admin directory with the following content:
  
 
<source lang="php">
 
<source lang="php">
Line 63: Line 69:
 
</source>
 
</source>
  
You can specify as many different '''allow from''' lines as you require. Or you can even allow entire IP subnet's by specifying just the first part of an IP, for example: "12.34.".  This is called Htaccess IP Restriction.
+
You can specify as many different '''allow from''' lines as you require. You can allow entire IP subnets by specifying just the first part of an IP address (for example, "12.34.").  This is .htaccess IP restriction.
  
 
==Change your WHMCS Admin Folder Name==
 
==Change your WHMCS Admin Folder Name==
  
Customising the url of your WHMCS admin area makes it harder for bots and malicious users to find it. It is not required, but if you wish to do so, find out how here: [[Customising the Admin Directory]]
+
Optionally, customising the URL of your WHMCS admin area can make it harder for bots and malicious users to find it. For steps, see [[Customising the Admin Directory]].
  
 
==Restrict Database Privileges==
 
==Restrict Database Privileges==
For day to day use, only the following database privileges are required. All others may be disabled.
 
  
*DELETE
+
Disable any unneeded database privileges.
*INSERT
+
 
*SELECT
+
Most tasks only require the following database privileges:
*UPDATE
+
 
*LOCK TABLES
+
*<tt>DELETE</tt>
 +
*<tt>INSERT</tt>
 +
*<tt>SELECT</tt>
 +
*<tt>UPDATE</tt>
 +
*<tt>LOCK TABLES</tt>
  
Please note that installation, upgrading, activating, and deactivating modules require the following additional privileges.
+
Installation, upgrades, and activating and deactivating modules require the following additional privileges:
  
*ALTER
+
*<tt>ALTER</tt>
*CREATE
+
*<tt>CREATE</tt>
*DROP
+
*<tt>DROP</tt>
*INDEX
+
*<tt>INDEX</tt>
  
 
==Enable SSL==
 
==Enable SSL==
  
As a billing application that handles customer data, there is often private and sensitive data passing between it and end users browsers. Therefore having a valid SSL Certificate that enables the use of HTTPs and encrypted communication is essential.
+
As a billing application that handles customer data, there is often private and sensitive data passing between WHMCS and end users' browsers. Having a valid SSL certificate that enables the use of HTTPS and encrypted communication is essential.
  
Once you have an SSL Certificate configured, simply enter the https:// enabled URL in the WHMCS System URL field in Setup > General Settings to ensure it is used.
+
After you configure an SSL certificate, enter the <tt>https://</tt>-enabled URL in the WHMCS System URL text box in Setup > General Settings to ensure that the system uses it.
  
If you do not have an SSL Certificate, you may purchase one quickly and easily at: https://www.whmcs.com/ssl-certificates/
+
If you do not have an SSL certificate, purchase one at https://www.whmcs.com/ssl-certificates/.
  
 
==Vendor Directory==
 
==Vendor Directory==
WHMCS is distributed with a vendor directory ("/vendor"). This is a common directory for advanced scripts and applications, such as WHMCS, and is comprised of various common libraries. However, web servers should not serve file requests directly from this path. Only the controlling script or application should load these libraries in order to ensure appropriate context and prevent unexpected behavior.
 
  
Apache is the recommended web server software platform on which to run WHMCS. If you are using Apache, the .htaccess distributed by WHMCS in the /vendor directory should suffice. If you are running Apache and files remain accessible, then you will want to investigate if your Apache configuration has disabled the use of .htaccess files or if there is a parent configuration that is negating the directive in the provided .htaccess file.
+
We distribute WHMCS with a vendor directory ("/vendor"). This is a common directory for advanced scripts and applications, such as WHMCS, and includes various common libraries. However, web servers should not serve file requests directly from this path. Only the controlling script or application should load these libraries in order to ensure appropriate context and prevent unexpected behavior.
  
While other web server technologies are not officially supported, we understand that some users do wish to run WHMCS in environments other than Apache. For those that do, you must ensure that files within the ''/vendor'' directory are not served based on your web server configuration.
+
Apache is the recommended web server software platform on which to run WHMCS.  If you are using Apache, the .htaccess file that WHMCS distributes in the <tt>/vendor</tt> directory should suffice. If you are running Apache and files remain accessible, investigate whether your Apache configuration has disabled the use of <tt>.htaccess</tt> files or there is a parent configuration that is negating the directive in the provided <tt>.htaccess</tt> file.
  
If you are using NGINX as your web server, we have put together a general guideline to assist you and your system administrator here: [[Nginx Directory Access Restriction]]
+
While we don't officially support other web server technologies, we understand that some users do wish to run WHMCS in environments other than Apache. To do this, you must ensure that your web server configuration does not serve files within the ''/vendor'' directory.
  
 +
If you are using NGINX as your web server, see [[Nginx Directory Access Restriction]].
  
 
[[Installation|<< Back to Installation Overview]]
 
[[Installation|<< Back to Installation Overview]]

Revision as of 19:24, 28 April 2020

WHMCS includes many features to help keep your data safe, but you can simple additional steps to secure your WHMCS installation further.

Secure the Writeable Directories

We recommend moving all writeable directories to a non-public location to prevent web based access. There are three required writeable directories: attachments, downloads and templates_c

You must specify the new location of the writeable directories in WHMCS. This is done in two places:

File Storage

You can move the attachments and downloads storage directories to a local location, or you can store them remotely on an AWS S3™-compatible service. If you are unfamiliar with the AWS S3 service, we recommend using the local storage option.

To do this:

  1. Create the storage location. This could be either:
    • A writeable directory on your server above the web root.
    • A non-public AWS S3-compatible storage bucket.
  2. Navigate to Setup > Storage Settings.
  3. Use the interface to add the secure storage locations and switch to them.

For step-by-step guidance using this interface, see Storage Settings.

Templates Cache

You can use the templates cache (templates_c) to improve performance of templated pages and emails.

To do this:

  1. Create a templates_c directory in the desired location (a non-public location above your web root).
  2. Edit the configuration.php file and specify the path to the new location by adding a new line:
$templates_compiledir = "/home/username/templates_c/";

In the above example, "username" is the cPanel username and the folder is in the home directory, above public_html.

If you are running suPHP or PHP suEXEC, chmod 755 should be sufficient permissions to make the directories writeable. This is the highest permission available for both folders and files when running in that condition.

Secure the configuration.php File

We recommend adjusting the permissions for the "configuration.php" file in your WHMCS root directory. This file contains sensitive data that you can't recover without a backup of the file. To avoid accidentally overwriting, editing or deleting the file, change the permission setting of this file to 400. This provides the system with read-only access and prevents anyone else from reading, editing or executing the file.

To change the permissions on this file, you can run the following command while in your WHMCS root directory:

chmod 400 configuration.php

Attention!

Some systems may require you to set the permission to 440 or 444, depending on the server's configuration. Usually, 400 should suffice, but if you encounter an error loading the application after setting the permission to 400, try 440 and then 444.

License Key Updates

If you need to update your license key, you must set the permissions on this file to 755 to allow the system to edit the file. After the updating the key, you can revert the permissions to 400.

Move the Crons Directory

By default, the system stores cron-related items in the /crons/ directory. We recommend moving the crons directory to a custom private directory above your web root. This will prevent web-based access and help to protect your WHMCS installation.

Moving the Crons Directory

When you customize this location, you must move the directory and update WHMCS's configuration.

For steps to do this, see Moving the Crons Directory.

Upgrades and Patches

Applying updates or patches after customizing your crons directory location requires an additional step. You must upload any updated crons files from the default location to your custom directory.

If you do not move the files, you will see errors and issues with WHMCS's automation.

Restrict Access by IP

For increased protection, if your staff uses fixed IP addresses, you can restrict access to a specific set of IPs. To do this, create a file with the name .htaccess in your WHMCS admin directory with the following content:

order deny,allow
allow from 12.34.5.67
allow from 98.76.54.32
deny from all

You can specify as many different allow from lines as you require. You can allow entire IP subnets by specifying just the first part of an IP address (for example, "12.34."). This is .htaccess IP restriction.

Change your WHMCS Admin Folder Name

Optionally, customising the URL of your WHMCS admin area can make it harder for bots and malicious users to find it. For steps, see Customising the Admin Directory.

Restrict Database Privileges

Disable any unneeded database privileges.

Most tasks only require the following database privileges:

  • DELETE
  • INSERT
  • SELECT
  • UPDATE
  • LOCK TABLES

Installation, upgrades, and activating and deactivating modules require the following additional privileges:

  • ALTER
  • CREATE
  • DROP
  • INDEX

Enable SSL

As a billing application that handles customer data, there is often private and sensitive data passing between WHMCS and end users' browsers. Having a valid SSL certificate that enables the use of HTTPS and encrypted communication is essential.

After you configure an SSL certificate, enter the https://-enabled URL in the WHMCS System URL text box in Setup > General Settings to ensure that the system uses it.

If you do not have an SSL certificate, purchase one at https://www.whmcs.com/ssl-certificates/.

Vendor Directory

We distribute WHMCS with a vendor directory ("/vendor"). This is a common directory for advanced scripts and applications, such as WHMCS, and includes various common libraries. However, web servers should not serve file requests directly from this path. Only the controlling script or application should load these libraries in order to ensure appropriate context and prevent unexpected behavior.

Apache is the recommended web server software platform on which to run WHMCS. If you are using Apache, the .htaccess file that WHMCS distributes in the /vendor directory should suffice. If you are running Apache and files remain accessible, investigate whether your Apache configuration has disabled the use of .htaccess files or there is a parent configuration that is negating the directive in the provided .htaccess file.

While we don't officially support other web server technologies, we understand that some users do wish to run WHMCS in environments other than Apache. To do this, you must ensure that your web server configuration does not serve files within the /vendor directory.

If you are using NGINX as your web server, see Nginx Directory Access Restriction.

<< Back to Installation Overview