DebianDebian BasedTutorials

How To Install BoxBilling on Debian 11

Install BoxBilling on Debian 11

In this tutorial, we will show you how to install BoxBilling on Debian 11. For those of you who didn’t know, BoxBilling is an open-source, self-hosted billing and customer relationship management (CRM) system. BoxBilling can help you to automate your invoicing, incoming payments, and client management and communication.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of BoxBilling on a Debian 11 (Bullseye).

Prerequisites

  • A server running one of the following operating systems: Debian 10 or Debian 11.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install BoxBilling on Debian 11 Bullseye

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt upgrade

Step 2. Installing the LEMP stack.

A Debian 11 LEMP server is required. If you do not have LAMP installed, Please read our previous tutorial to install LEMP Server on Debian 11.

Step 3. Installing BoxBilling on Debian 11.

By default, BoxBilling is not available on Debian 11 base repository. So, now we download the latest stable version of BoxBilling from the official page:

mkdir -p /var/www/boxbilling/
cd /var/www/boxbilling
wget https://github.com/boxbilling/boxbilling/releases/download/4.22.1.3/BoxBilling.zip
unzip Boxbilling.zip

Next, we create a new directories ‘cache‘ and ‘upload‘:

mkdir -p /var/www/boxbilling/bb-data/{cache,uploads}

We will need to change some folders permissions:

sudo chown -R www-data:www-data /var/www/boxbilling
sudo chmod u+rw /var/www/boxbilling/bb-data/{cache,uploads}

Step 4. Configuring MariaDB.

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. You should read and below each step carefully which will set the root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:

mysql_secure_installation

Configure it like this:

- Switch to unix_socket authentication [Y/n] Y
- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

Next, we will need to log in to the MariaDB console and create a database for BoxBilling. Run the following command:

mysql -u root -p

This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server, you need to create a database for BoxBilling installation:

MariaDB [(none)]> CREATE DATABASE boxbilling_db;
MariaDB [(none)]> CREATE USER 'boxbillingp_user'@'localhost' IDENTIFIED BY 'your-strong-password';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON boxbilling_db.* to boxbilling_user@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

Step 5. Configure Nginx.

Now we create a new VirtualHost to better manage the BoxBilling website:

cd /var/www/sites-available/
nano boxbilling.conf

Add the following file:

server {
    listen 80;
    server_name billing.your-domain.com;
    return 302 https://$server_name$request_uri;
}

server {
  listen 443 ssl http2;

     set $root_path '/var/www/boxbilling';

     server_name  billing.your-domain.com;

     index index.html index.htm index.php;
     root $root_path;
     try_files $uri $uri/ @rewrite;
     sendfile off;

  ssl_certificate /etc/letsencrypt/live/billing.your-domain.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/billing.your-domain.com/privkey.pem;

  ssl_protocols TLSv1.2;
  ssl_prefer_server_ciphers on;
  ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
  ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
  ssl_session_timeout  10m;
  ssl_session_cache shared:SSL:10m;
  ssl_session_tickets off; # Requires nginx >= 1.5.9
  # ssl_stapling on; # Requires nginx >= 1.3.7
  # ssl_stapling_verify on; # Requires nginx => 1.3.7
  resolver 8.8.8.8 8.8.4.4 valid=300s;
  resolver_timeout 5s;
  add_header X-Frame-Options DENY;
  add_header X-Content-Type-Options nosniff;
  add_header X-XSS-Protection "1; mode=block";

    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;

     location @rewrite {
         rewrite ^/(.*)$ /index.php?_url=/$1;
     }

    location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
         include fastcgi_params;
         fastcgi_intercept_errors on;
    }

     # Disable PHP execution in bb-uploads and bb-data
     location ^~ /bb-uploads/ { }
     location ^~ /bb-data/ {
       deny all;
     }

     location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
         root $root_path;
         expires off;
         proxy_no_cache 1;
         proxy_cache_bypass 1;
     }

     location ~ /\.ht {
         deny all;
     }
 }

Save and close the file, then restart the Nginx web server so that the changes take place:

ln -s /etc/nginx/sites-available/boxbilling.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Now you will start installing and configuring BoxBilling from the web browser:

https://billing.your-domain.com

Install BoxBilling on Debian 11 Bullseye

Once the Boxbilling installation is completed, you will need to remove the ‘install’ directory and change the permission of the file ‘bb-config.php‘, the create a new cronjob for the BoxBilling application:

rm -rf /var/www/boxbilling/install
sudo chmod 644 /var/www/boxbilling/bb-config.php

Next, we create a new cronjob for the user ‘www-data‘. The BoxBilling application is mainly running under the Nginx web server with the user ‘www-data‘:

export EDITOR=nano
sudo crontab -u www-data -e

Step 6. Accessing BoxBilling Admin Page.

Once successfully installed, open a web browser and go to https://boxbilling.your-domain/bb-admin/ and you will see the following screen admin login page, input your user and password:

Install BoxBilling on Debian 11 Bullseye

Congratulations! You have successfully installed BoxBilling. Thanks for using this tutorial for installing the latest version of the BoxBilling on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official BoxBilling website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button