Installing WHMCS
Download WHMCS
- Download WHMCS from their Official Website
- Install unzip with
apt install unzip
- Extract the zip with
cd /var/www && unzip whmcs_*
Install Apache
apt install apache2
Generating SSL/TLS Certificates
Downloading Certbot
To begin, we will install certbot, a simple script that automatically renews our certificates and allows much easier creation of them. The command below is for Ubuntu distributions, but you can always check Certbot’s Official Website for installation instructions. We have also included a command below to install certbot’s Apache plugin so you won’t have to stop your webserver.
apt update
apt install -y certbot python3-certbot-apache
Completing the HTTP Challenge
- Make sure you have port 80 open on your firewall
- Request a certificate from Let’s Encrypt, you should replace
billing.example.com
with the domain you would like to generate a certificate for.
certbot certonly --apache -d billing.example.com
Automatically Renewing SSL/TLS certificates
- Install crontab:
apt install cron
- Create a crontab rule for the automatic renewal:
(crontab -l ; echo "0 23 * * * certbot renew --quiet --deploy-hook \"systemctl restart apache2\"")| crontab -
Webserver Configuration
Remove the default configuration:
a2dissite 000-default.conf
- Create a new Apache site configuration like
whmcs.conf
in/etc/apache2/sites-available
using a text editor like nano or vim. - Paste the text below into the file, replacing
billing.example.com
with your domain:
<VirtualHost *:80>
ServerName billing.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/whmcs
Options -Indexes
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>
<VirtualHost *:443>
<Directory /var/www/>
Options -Indexes
AllowOverride All
Require all granted
Order allow,deny
allow from all
</Directory>
ServerName billing.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/whmcs
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# PHP Limits
php_value upload_max_filesize 100M
php_value post_max_size 100M
# SSL Configuration
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/billing.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/billing.example.com/privkey.pem
# Headers
Header always set X-Content-Type-Options "nosniff"
Header always set X-XSS-Protection "1; mode=block"
Header always set X-Robots-Tag "none"
Header always set Content-Security-Policy "frame-ancestors 'self'"
Header always set X-Frame-Options "DENY"
Header always set Referrer-Policy "same-origin"
Header always set Permissions-Policy "accelerometer=(), camera=(), fullscreen=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), usb=()"
</VirtualHost>
Link Config
Enable your new Apache website configuration and required modules:
ln -s /etc/apache2/sites-available/whmcs.conf /etc/apache2/sites-enabled/whmcs.conf
Install PHP
apt-add-repository universe
apt -y install libapache2-mod-php8.1 php8.1 php8.1-{common,cli,gd,mysql,mbstring,bcmath,xml,fpm,curl,zip,bcmath,gmp,intl,mbstring,soap}
Install IonCube
wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
tar -xzvf ioncube_loaders_lin_x86-64.tar.gz
cp ioncube/ioncube_loader_lin_8.1.so /usr/lib/php/20210902/
Add IonCube Extension to CLI PHP.ini:
zend_extension = "/usr/lib/php/20210902/ioncube_loader_lin_8.1.so"
Add IonCube Extension to Apache PHP.ini:
zend_extension = "/usr/lib/php/20210902/ioncube_loader_lin_8.1.so"
Check if IonCube was successfully installed:
php -v
Enable Required Modules
a2enmod rewrite
a2enmod headers
a2enmod ssl
# List Modules
apachectl -M
Restart Apache and PHP
systemctl restart apache2
systemctl restart php8.1-fpm
Install MariaDB
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
apt install mariadb-server
Enter MySQL Shell
mysql
Create Database
CREATE DATABASE whmcs;
CREATE USER 'whmcsuser'@'127.0.0.1' IDENTIFIED BY 'somePasswordHere';
GRANT ALL PRIVILEGES ON whmcs.* TO 'whmcsuser'@'127.0.0.1';
Strict Privileges
If you wish to have strict database privileges instead, only allow the following:
When installing WHMCS, updating WHMCS, activating modules, or deactivating modules, the following privileges are required:
- ALTER
- CREATE
- DROP
- INDEX
For day-to-day use, only the following database privileges are required:
- DELETE
- INSERT
- SELECT
- UPDATE
- LOCK TABLES
Setting File Permissions
chown -R www-data:www-data /var/www/whmcs
Create Cron Schedule
(crontab -l ; echo "*/5 * * * * /usr/bin/php -q /var/www/crons/cron.php")| crontab -
Begin Setup
- Visit your domain and click “Click here to begin…”
- Read and either agree or disagree with the WHMCS EULA
- Fix any errors, most commonly are simple file permission errors
- Input your database login credentials
- Input your license and create an administrator user