Documentation
Install on Apache

Installing on an Apache Server

Apache is a popular web server. In this guide, we'll guide you through installing FOSSBilling on an Apache server running on an Ubuntu server. We will also show you how to configure Apache to serve your website over HTTPS using a free Let's Encrypt SSL certificate.

This guide is incomplete. The complete version will be available soon.

We are planning to improve the guide by also including CentOS/RHEL-based distributions in the near future. This guide is currently only tested on Ubuntu 22.04 LTS, but you should be able to run FOSSBilling on any Linux distribution that supports Apache server and PHP 8.0 or higher.

This guide will assume you have a basic understanding of how to use the command line and have a sudo-enabled account other than root in your server. The provided steps are tested on a freshly-installed Ubuntu 22.04 LTS server.

We will only cover the basics here. If you are new to Linux servers, we recommend you to read the Ubuntu Server Guide (opens in a new tab) to learn more about the basics of the Ubuntu Server.

Prerequisites

Anything above PHP 8.0 or higher should work. However, FOSSBilling depends on the following PHP extensions and won't work without them enabled:

  • pdo_mysql
  • curl
  • zlib
  • openssl

FOSSBilling also needs a MySQL database in a MariaDB server running version 10.3 or later, or in a MySQL server running version 8 or later.

If you want to provision a free Let's Encrypt SSL certificate for your website, you will need to have a valid hostname pointed to your server.

In the next steps, we will assist you with the installation of the required software.

Installing and configuring Apache

Let's start by updating our local package index. This will ensure that we have the latest version of all packages available to us.

Depending on your internet connection, this may take a few minutes.

bash
sudo apt update

Next, we will install Apache and its dependencies.

bash
sudo apt install apache2

APT will prompt you to confirm the installation. Press Y and hit Enter to continue.

Testing to see if Apache was installed correctly

Now, let's do a quick test to see if Apache was set up correctly. Open a new tab and navigate to your server's IP address in your browser. You should see the default Apache page. It should look something like this:

Default Apache2 page for Ubuntu Server

If you could view this page, you have successfully installed Apache on your server. You can now move on to the next step.

Configuring our Apache server

Enabling mod_rewrite

FOSSBilling uses the Apache mod_rewrite module to rewrite URLs. We need to enable it to make FOSSBilling work correctly.

Enabling the module is as simple as running the following command:

bash
sudo a2enmod rewrite

To make sure our changes take effect, we will restart Apache.

bash
sudo systemctl restart apache2

Allowing Apache configuration to be overridden by FOSSBilling

FOSSBilling will need to override some of the Apache configuration to make it work correctly. Applications can use the .htaccess file to adjust the Apache configuration and tweak how it works for that specific application. However, by default, Apache doesn't allow .htaccess files to override the configuration. We need to enable it to make FOSSBilling work correctly.

To enable .htaccess files to override the Apache configuration, we will need to edit the apache2.conf file. Open the file using your favourite text editor. We will use nano in this guide.

bash
sudo nano /etc/apache2/apache2.conf

nano is a simple text editor that comes pre-installed on Ubuntu. Press Ctrl + W to search for the following line:

/etc/apache2/apache2.conf
AllowOverride None

There should be different lines that look similar. We need to find the one that specifies the AllowOverride option for the /var/www/ directory. It should look something like this:

/etc/apache2/apache2.conf
<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

Change that line to AllowOverride All.

Now, save the file by pressing Ctrl + O, then Enter. Press Ctrl + X to exit the editor.

To make sure our changes take effect, we will restart Apache.

bash
sudo systemctl restart apache2

You can set up a virtual host for FOSSBilling instead of using the default /var/www/ directory. For the sake of keeping it simple for beginners, we will use the default directory in this guide. If you want to set up a virtual host, you can read more about it over the internet.

Installing and configuring the MySQL server

Installing the MySQL server

Now that we have our web server installed, we need a MySQL database to store the data for FOSSBilling. We will install the MySQL server.

Let's use APT again to install the MySQL server and its dependencies.

bash
sudo apt install mysql-server

APT will prompt you to confirm the installation. Press Y and hit Enter to continue.

Now, use the built-in mysql_secure_installation script to secure our MySQL installation.

bash
sudo mysql_secure_installation

Configuring our MySQL server

Validating password strength

We will then be asked if we want to enable the VALIDATE PASSWORD COMPONENT. Enabling it is completely up to you. Once it's enabled, The MySQL server will reject insecure passwords with an error. Keeping it disabled is also fine, but we recommended you to enable it.

If you chose to enable it, you will be asked to select one of the three password validation policies.

Output
There are three levels of password validation policy:
 
LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
 
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:

Go with whatever suits you best. Then press Enter to continue.

Setting the MySQL root password

Next, we will be asked to set a password for the MySQL root user.

Don't mistake this for the root account in your Ubuntu server, it's a different account and they are unrelated to each other. This is the root account for your MySQL server which will have full permissions over your MySQL server. Enter a strong password, press Enter, then confirm the password and press Enter again.

It will display the estimated strength of the password you entered. If you are satisfied with the strength, press Y and hit Enter to continue.

Removing anonymous users

Next, we will be asked if we want to remove anonymous users. We will say Y and hit Enter to continue.

Disallowing root login remotely

Next, we will be asked if we want to disallow root login remotely.

You might want to disable this. We will create different accounts for our MySQL server later on, and we will use those accounts to connect to the MySQL server remotely. Disallowing access to the root account which has unlimited permissions over the MySQL server is a good idea. We will say Y and hit Enter to continue.

Removing the test database

Next, we will be asked if we want to remove the test database and access to it. We will say Y and hit Enter to continue.

Reloading the privilege tables

And for the last step, we will be asked if we want to reload the privilege tables now. We will say Y and hit Enter to continue.

Our MySQL server should now be installed and secured. We can now move on to the next step.

Installing PHP

Now that we have our web server and database server installed, we need to install PHP.

Let's use APT once more to install PHP and the extensions we need for FOSSBilling.

bash
sudo apt install php libapache2-mod-php php-mysql php-curl

APT will prompt you to confirm the installation. Press Y and hit Enter to continue.

Making sure PHP was installed correctly

Let's verify that PHP was installed correctly. Run the following in your terminal:

bash
php -v

The output should be something like this:

Output
PHP 8.1.2-1ubuntu2.9 (cli) (built: Oct 19 2022 14:58:09) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2-1ubuntu2.9, Copyright (c), by Zend Technologies

At this point, our LAMP stack should be installed and configured.

Installing FOSSBilling

Downloading the latest version of FOSSBilling

Now that we have our LAMP stack installed and configured, we can download the latest version of FOSSBilling.

Pull the latest stable version using curl

We will use curl to download the latest stable version of FOSSBilling. Run the following in your terminal:

bash
curl https://fossbilling.org/downloads/stable -L --output FOSSBilling.zip

This command will download the latest stable version of FOSSBilling and save it as FOSSBilling.zip. If you want to download the latest development preview instead, replace stable with preview.

Extract the downloaded archive

Now that we have downloaded the latest version of FOSSBilling, we need to extract it. We will use unzip to extract the archive.

unzip doesn't come pre-installed on Ubuntu 22.04 LTS. We will need to install it first. Run the following in your terminal:

bash
sudo apt install unzip

Then, extract the archive using unzip:

bash
sudo unzip FOSSBilling.zip -d /var/www/html

This will extract the archive to /var/www/html. This is the default web root directory for Apache on Ubuntu 22.04 LTS.

Changing the ownership of the extracted files

We will need to change the ownership of the extracted files to www-data. This is the default user for Apache on Ubuntu 22.04 LTS.

Run the following in your terminal:

bash
sudo chown -R www-data:www-data /var/www/html

Setting up the MySQL database

Creating the MySQL database

Creating the MySQL user

Using the web installer

Getting a free SSL certificate from Let's Encrypt

Installing Certbot

Obtaining the certificate

Post-installation steps

Securing your configuration file

Setting up the cron jobs

Setting up the firewall

Once the installation is done, we will need to adjust the firewall settings to allow incoming traffic on ports 80 (HTTP) and 443 (HTTPS).

We will use ufw. UFW provides an easy-to-use interface to manage the firewall. It is enabled by default on Ubuntu 22.04 LTS.

To list the available UFW rules, run:

bash
sudo ufw app list

You should see the following output:

Output
Available applications:
  Apache
  Apache Full
  Apache Secure
  OpenSSH

Let's break down what these rules mean:

  • Apache - This will only allow incoming traffic on port 80 (unencrypted HTTP traffic), but not on port 443 (encrypted HTTPS traffic).
  • Apache Full - Allows incoming traffic on both port 80 (HTTP) and 443 (HTTPS). As we're planning to get ourselves an SSL certificate from Let's Encrypt, we will use this rule.
  • Apache Secure - This will only allow incoming traffic on port 443 (encrypted HTTPS traffic), but not on port 80 (unencrypted HTTP traffic).

To enable the Apache Full rule, run:

bash
sudo ufw allow in "Apache Full"

To verify that the rule has been added, run:

bash
sudo ufw status