Introduction

In this guide, we’ll walk you through the process of setting up FOSSBilling on your VPS using Docker and Nginx Proxy Manager for reverse proxying. We will also cover setting up SSL with Let’s Encrypt to secure your domain, ensuring that your billing platform is both efficient and secure.

By the end of this tutorial, you’ll have a fully-functional FOSSBilling setup accessible via a custom domain over HTTPS.


Prerequisites

Before you begin, ensure you have the following:

  • A VPS running Ubuntu 24 (or a similar version).
  • Docker and Docker Compose installed.
  • Nginx Proxy Manager installed and running on your server.
  • A domain (e.g., billing.yourdomain.com) that points to your VPS IP address.

Step 1: Install and Configure FOSSBilling with Docker

If you haven’t already, follow these steps to get FOSSBilling running using Docker:

  1. Create a directory for FOSSBilling:

    mkdir ~/fossbilling && cd ~/fossbilling

  2. Create the Docker Compose file:

    nano docker-compose.yml

    Add the following content, making sure to adjust the database password if necessary:

    version: '3.8'

    services:
    fossbilling:
    image: fossbilling/fossbilling:latest
    container_name: fossbilling
    ports:
    “8080:80”
    volumes:
    fossbilling_data:/var/www/html
    environment:
    FOSSBILLING_DB_HOST: db
    FOSSBILLING_DB_USER: fossbilling
    FOSSBILLING_DB_PASSWORD: fossbillingpass
    FOSSBILLING_DB_NAME: fossbilling
    restart: unless-stopped
    depends_on:
    db

    db:
    image: mariadb:latest
    container_name: fossbilling_db
    environment:
    MYSQL_ROOT_PASSWORD: rootpass
    MYSQL_DATABASE: fossbilling
    MYSQL_USER: fossbilling
    MYSQL_PASSWORD: fossbillingpass
    volumes:
    db_data:/var/lib/mysql
    restart: unless-stopped

    volumes:
    fossbilling_data:
    db_data:

  3. Start the containers:

    docker-compose up -d

  4. Verify if the containers are running:

    docker ps

Once the containers are running, you can access FOSSBilling via http://your-server-ip:8080.

During the FOSSBilling installation, when it asks for the MySQL connection information, you should enter the following values:

  • Database hostname: db (This is the name of the MariaDB service in your Docker Compose file)
  • Database port: 3306 (This is the default port for MySQL/MariaDB)
  • Database name: fossbilling (As defined in your Docker Compose file)
  • Database username: fossbilling (As defined in your Docker Compose file)
  • Database password: fossbillingpass (As defined in your Docker Compose file)

So, the information to enter would be:

  • Database hostname: db
  • Database port: 3306
  • Database name: fossbilling
  • Database username: fossbilling
  • Database password: fossbillingpass
  • Great to hear that the installation is complete! 🎉 Here’s how to complete the remaining setup tasks:

    1) Remove the Installer

    You need to delete the install folder to complete the installation process. Run the following command:

    rm -rfv /var/www/html/install

    This ensures that the installer folder is removed for security reasons.

    2) Configuration Permission

    To make the config.php file read-only, which is important for security, run:

    chmod 644 /var/www/html/config.php

    This ensures that the configuration file is protected from unwanted changes.

    3) Set Up Cron Job

    You need to set up a cron job to ensure FOSSBilling runs scheduled tasks every 5 minutes. To do this:

    1. Open the crontab editor:

      crontab -e

    2. Add the following line at the end of the file:

      */5 * * * * php /var/www/html/cron.php

    This command will execute cron.php every 5 minutes. Save the file and exit the editor.


    With these steps completed, FOSSBilling should be fully configured and ready to use! You can log into the admin panel at http://your-server-ip:8080/admin and start using the application.


Step 2: Set Up Nginx Proxy Manager for FOSSBilling

Since Nginx Proxy Manager simplifies the process of managing reverse proxies, follow these steps:

  1. Log into Nginx Proxy Manager at http://your-server-ip:81 using your credentials.

  2. Go to the Proxy Hosts tab and click Add Proxy Host.

  3. In the Add Proxy Host form, enter the following:

    • Domain Names: billing.yourwebsite.com (your domain)
    • Scheme: http
    • Forward Hostname/IP: localhost
    • Forward Port: 8080
    • Block Common Exploits: Check this box.
  4. Enable SSL by selecting Enable SSL and choosing Request a new SSL Certificate from Let’s Encrypt. Ensure you enable Force SSL for HTTPS redirection.

  5. Save the settings.

After saving, your FOSSBilling instance will be accessible at https://billing.yourwebsite.com.


Step 3: Set Up Automated SSL Renewal

To ensure your SSL certificate from Let’s Encrypt remains valid, Nginx Proxy Manager handles the automatic renewal. However, it’s always good to double-check:

  1. Go to SSL Certificates in Nginx Proxy Manager.
  2. Confirm that your certificate is renewed automatically.

Step 4: Configure Backups for FOSSBilling

Setting up regular backups for your database and FOSSBilling files is crucial for data protection. You can do this with a simple bash script and cron job:

  1. Create a backup script:

    sudo nano /usr/local/bin/backup_fossbilling.sh

    Add the following content to back up your database and files:

    #!/bin/bash

    DB_NAME=fossbilling
    DB_USER=fossbilling
    DB_PASSWORD=fossbillingpass
    BACKUP_DIR=/home/youruser/backups
    DATE=$(date +\%Y-\%m-\%d_\%H\%M)

    mysqldump -u$DB_USER -p$DB_PASSWORD $DB_NAME > $BACKUP_DIR/db_backup_$DATE.sql
    tar -czf $BACKUP_DIR/fossbilling_files_$DATE.tar.gz /var/www/html

    find $BACKUP_DIRtype f -mtime +7 –exec rm -f {} \;

  2. Make the script executable:

    sudo chmod +x /usr/local/bin/backup_fossbilling.sh

  3. Schedule the backup using cron:

    crontab -e

    Add the following line to back up every day at 2 AM:

    0 2 * * * /usr/local/bin/backup_fossbilling.sh


Step 5: Optimize Performance

For better performance, you can optimize MariaDB and enable PHP caching:

  1. Edit MariaDB configuration for better performance:

    sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

    Adjust settings like innodb_buffer_pool_size and max_connections.

  2. Enable PHP caching (OPcache) for improved performance:

    Install OPcache:

    sudo apt install php-opcache

    Enable it by modifying /etc/php/7.x/fpm/php.ini and uncommenting:

    zend_extension=opcache.so

    Restart PHP-FPM:

    sudo systemctl restart php7.4-fpm


Conclusion

With these steps, you’ve successfully set up FOSSBilling with Docker, configured it with Nginx Proxy Manager, secured it with SSL, and implemented backups and performance optimizations. You’re now ready to manage your billing platform securely and efficiently.