Sep 14, 2024 โ€ข 3 min read

FossBilling: Your Self-Hosting Setup and Management Guide

FossBilling: Your Self-Hosting Setup and Management Guide

FossBilling is an open-source billing and client management software designed for web hosting companies, freelancers, and digital businesses. It provides extensive customization and full control over your data, making it an excellent choice for those seeking a self-hosted alternative to proprietary billing platforms. In this guide, weโ€™ll walk you through installing FossBilling, configuring it with a reverse proxy, managing logs, setting up backups, updating the application, and leveraging its unique features.

Installing FossBilling

๐Ÿ“ฆ Docker/Docker Compose Setup

The easiest way to deploy FossBilling is with Docker. Below is an example docker-compose.yml file tailored for FossBilling, including persistent storage and database configurations.


version: '3.8'

services:

fossbilling:

image: fossbilling/fossbilling:latest

container_name: fossbilling

ports:

- "8080:80"

volumes:

- fossbilling_data:/var/www/fossbilling

environment:

- DB_HOST=db

- DB_NAME=fossbilling

- DB_USER=fossbilling_user

- DB_PASS=secure_password

depends_on:

- db

db:

image: mariadb:10.5

container_name: fossbilling_db

restart: always

environment:

MYSQL_ROOT_PASSWORD: root_password

MYSQL_DATABASE: fossbilling

MYSQL_USER: fossbilling_user

MYSQL_PASSWORD: secure_password

volumes:

- db_data:/var/lib/mysql

volumes:

fossbilling_data:

db_data:

Deploy FossBilling using the following commands:


docker-compose up -d

๐Ÿš€ Manual Installation

For manual installation, follow these steps to install FossBilling on a Linux server:

  1. Install dependencies:

sudo apt update

sudo apt install -y apache2 php php-cli php-mysql mariadb-server unzip curl

  1. Download and extract FossBilling:

curl -LO https://github.com/FOSSBilling/FOSSBilling/releases/latest/download/fossbilling.zip

unzip fossbilling.zip -d /var/www/fossbilling

  1. Set permissions:

sudo chown -R www-data:www-data /var/www/fossbilling

sudo chmod -R 755 /var/www/fossbilling

  1. Set up Apache or Nginx to serve the app, and complete the web-based installation wizard at http://your-server-ip.

Configuring Nginx as a Reverse Proxy

๐ŸŒ Nginx Configuration

Set up Nginx to serve FossBilling and forward requests to the backend.

Create a server block file for FossBilling:


sudo nano /etc/nginx/sites-available/fossbilling

Add the following content:


server {

listen 80;

server_name example.com;

root /var/www/fossbilling/public;

index index.php index.html;

location / {

try_files $uri $uri/ /index.php?$query_string;

}

location ~ \.php$ {

include fastcgi_params;

fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}

location ~ /\.ht {

deny all;

}

}

Enable and reload the configuration:


sudo ln -s /etc/nginx/sites-available/fossbilling /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl reload nginx

๐Ÿ”’ SSL/TLS Setup

Secure the connection with Let's Encrypt:


sudo apt install certbot python3-certbot-nginx

sudo certbot --nginx -d example.com

Schedule automatic renewal:


sudo systemctl enable certbot.timer

๐Ÿ› ๏ธ Testing and Reloading Nginx

Validate the Nginx configuration:


sudo nginx -t

sudo systemctl reload nginx

Logging and Debugging FossBilling

๐Ÿ—ƒ๏ธ Enabling Debug Logs

To enable debug logs, update config.php in the FossBilling directory:


'log_level' => 'debug',

๐Ÿ“„ Viewing Logs

View logs in Docker or on the filesystem:


docker logs fossbilling

tail -f /var/www/fossbilling/logs/app.log

๐Ÿ› ๏ธ Troubleshooting Common Issues

Check for common issues like incorrect DB credentials in config.php or permissions errors:


sudo chmod -R 755 /var/www/fossbilling

sudo chown -R www-data:www-data /var/www/fossbilling

๐Ÿ“ค Exporting Logs

Forward logs to ELK for advanced analysis:


docker run -d --name logstash -v /path/to/logstash.conf:/usr/share/logstash/pipeline/logstash.conf docker.elastic.co/logstash/logstash:7.17.0

Backup and Restore

๐Ÿ—‚๏ธ File-Based Backups

Backup configuration and app files:


tar -czvf fossbilling_backup_$(date +%F).tar.gz /var/www/fossbilling

๐Ÿ”„ Database Backups

Export the database:


mysqldump -u fossbilling_user -p fossbilling > fossbilling_db_backup.sql

Restore the database:


mysql -u fossbilling_user -p fossbilling < fossbilling_db_backup.sql

๐Ÿ“… Automated Backup Scripts

Create a cron job for periodic backups:


crontab -e

## Add the following line:

0 2 * * * tar -czvf /backups/fossbilling_backup_$(date +\%F).tar.gz /var/www/fossbilling

Updating and Upgrading FossBilling

โฌ†๏ธ Updating Docker Images

Update FossBilling in Docker:


docker-compose pull fossbilling

docker-compose up -d

๐Ÿ› ๏ธ Manual Updates

For manual installations, download the latest release and overwrite files:


curl -LO https://github.com/FOSSBilling/FOSSBilling/releases/latest/download/fossbilling.zip

unzip -o fossbilling.zip -d /var/www/fossbilling

sudo chown -R www-data:www-data /var/www/fossbilling

sudo systemctl reload apache2

๐Ÿ” Checking for Updates

Stay informed by visiting FossBillingโ€™s GitHub releases page:

https://github.com/FOSSBilling/FOSSBilling/releases

Leveraging FossBillingโ€™s Unique Features

๐Ÿ”ง Enabling APIs

Activate and test APIs by enabling API access in the admin panel under "Settings > API." Use this example to test with curl:


curl -X POST https://example.com/api/login \

-H "Content-Type: application/json" \

-d '{"username":"admin","password":"your_password"}'

๐ŸŒŸ Advanced Configurations

Customize FossBilling by tweaking config.php for advanced features like multi-currency or email integration:


'currency' => 'USD',

'mail_settings' => [

'smtp_host' => 'smtp.example.com',

'smtp_port' => 587,

'smtp_user' => 'user@example.com',

'smtp_pass' => 'secure_password',

],

Wrapping Up

With this guide, you now have all the tools to deploy, configure, manage, and scale FossBilling efficiently. By self-hosting FossBilling, you gain full control over your billing system while maintaining flexibility and security. Use the provided examples to set up a robust ecosystem tailored to your needs, and take full advantage of FossBillingโ€™s powerful features to streamline your operations.

Great! Youโ€™ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.