How To Setup WHMCS – One

These 6 installations where all on separate servers. Maintaining each one and having to manually upgrade was ridiculous. So I used brain power and combined them into one installation.

For this example, I will be using domain1.com and domain2.com. This setup can handle as many as you need. I am assuming you have root access to a basic Linux server.

Step By Step

– Create a user on the server “whmcs”
– – This user should be pointed to /home/whmcs

# adduser -d /home/whmcs whmcs

– Extract the WHMCS script into /home/whmcs/master
– – This will be the single install of WHMCS and it’s root web directory – Create symbolic links
– – This is used for DOCUMENT_ROOT reference

# ln -s /home/whmcs/master domain1.com
# ln -s /home/whmcs/master domain2.com

– Edit /home/whmcs/master/configuration.php to the following
– – We are creating logic to include a different configuration file depending on which domain is being visited.

if ($_SERVER["DOCUMENT_ROOT"] == '/home/whmcs/domain1.com') {
        include('configuration_domain1.com.php');
}
if ($_SERVER["DOCUMENT_ROOT"] == '/home/whmcs/domain2.com') {
        include('configuration_domain2.com.php');
}

– Create and edit your new configuration files
– – Edit the settings as necessary, but make sure to use domain1.com and domain2.com where specified

/home/whmcs/configuration_domain1.com.php

$license="";
$db_host = "";
$db_username = "";
$db_password = "";
$db_name = "whmcs_domain1";
$cc_encryption_hash = ""; 
$templates_compiledir = "/home/whmcs/domain1.com/templates_domain1_c";
$api_access_key = "";
session_name("WHMCS_DOMAIN1");
$display_errors = true;

/home/whmcs/configuration_domain2.com.php

$license="";
$db_host = "";
$db_username = "";
$db_password = "";
$db_name = "whmcs_domain2";
$cc_encryption_hash = ""; 
$templates_compiledir = "/home/whmcs/domain2.com/templates_domain2_c";
$api_access_key = "";
session_name("WHMCS_DOMAIN2");
$display_errors = true;

– Create template caching dirs for the domains, then chmod 777
– – Due to the WHMCS’s devs wisdom, they require the directory to be 777.

# mkdir /home/whmcs/master/templates_domain1_c
# mkdir /home/whmcs/master/templates_domain2_c
# chmod 777 /home/whmcs/master/templates_domain1_c
# chmod 777 /home/whmcs/master/templates_domain2_c

 

Now your configuration and directory structure is completed. WHMCS is now ready for both domains to work from one installation.

The easiest part of this is setting up the web server. You can use anything, Nginx, Apache, etc. All you do is setup the document root to the symbolic links you created.

Your directory structure should look something like this.

# ll /home/whmcs
drwxr-xr-x 21 whmcs whmcs    4096 Jan 21 13:49 master
lrwxrwxrwx  1 root  root        7 Dec 11 11:41 domain1 -> master/
lrwxrwxrwx  1 root  root        7 Dec 11 11:41 domain2 -> master/

 

Just to give you an idea, this is what an Nginx configuration could look like.

server {
    listen       123.456.789.1:443;
    server_name  domain1.com;
    root /home/whmcs/domain1.com;
    access_log /var/log/nginx/domain1.com-access.log;
    error_log /var/log/nginx/domain1.com-error.log;
    ...more stuff below...
}
server {
    listen       123.456.789.2:443;
    server_name  domain2.com;
    root /home/whmcs/domain2.com;
    access_log /var/log/nginx/domain2.com-access.log;
    error_log /var/log/nginx/domain2.com-error.log;
    ...more stuff below...
}

 

Now when you visit domain1.com or domain2.com they will be accessing the same WHMCS installation. You can change the themes and templates as needed through the admin interface.

For cron job setup, make sure to use WGET with the full domain name so that each configuration is populated correctly.

Cron example:

0 8 * * *  /usr/bin/wget -O /dev/null https://domain1.com/admin/cron.php >/dev/null 2>&1
0 9 * * *  /usr/bin/wget -O /dev/null https://domain2.com/admin/cron.php >/dev/null 2>&1

 

This setup works flawlessly. We’ve had zero problems and have gone through two WHMCS updates already.

Source

1 Response on this post

Leave a Reply

Your email address will not be published. Required fields are marked *