Running FOSSBilling or WHMCS on your own server: cron, payments, security and upgrades
In this article10 sections
A billing system is the one application on your server that touches money, customer records and the automation that creates, renews and suspends services. When it works, nobody notices. When it quietly stops, invoices are not generated, payments are not recorded and customers pay for things they never receive.
FOSSBilling and WHMCS are the two names most hosting businesses choose between. FOSSBilling is open source and free; WHMCS is commercial and has the larger ecosystem. Their servers look alike and they fail in similar ways. This guide covers what both need from the machine they run on, the mistakes that cost the most, and how to upgrade without drama. The commands use FOSSBilling’s file names; WHMCS equivalents are noted where they differ.
1. A server and a user of their own
Run the billing system as its own user, in its own PHP-FPM pool, with its own database and database user. If it shares a pool and a user with a WordPress blog, a flaw in any one plugin can read the billing configuration, which contains the database password and encryption keys.
sudo adduser --system --group --no-create-home fossbilling
sudo nano /etc/php/8.3/fpm/pool.d/fossbilling.conf
A minimal pool:
[fossbilling]
user = fossbilling
group = fossbilling
listen = /run/php/fossbilling.sock
listen.owner = www-data
listen.group = www-data
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 20s
pm.max_requests = 500
php_admin_value[open_basedir] = /var/www/fossbilling/:/tmp/:/usr/share/php/
open_basedir confines PHP to the application’s own folders. pm = ondemand keeps idle memory low on a small server. Point NGINX’s fastcgi_pass for that site at the new socket. Use the PHP version your billing version supports; read its requirements before installing, not after.
2. The cron job is the heartbeat
Both systems rely on a scheduled job that runs every five minutes. It generates invoices, sends reminders, processes renewals, suspends overdue services and runs the automation. If it stops, nothing visibly breaks: the admin pages still load. That is why a stopped cron is the most expensive silent failure in the whole stack.
For FOSSBilling, run cron.php as the application user:
echo '*/5 * * * * fossbilling /usr/bin/php /var/www/fossbilling/cron.php' | sudo tee /etc/cron.d/fossbilling
For WHMCS the equivalent is php -q /path/to/whmcs/crons/cron.php every five minutes.
Three things to get right:
- Exactly one entry. Two copies of the cron job (for example one in a user’s crontab and one in
/etc/cron.d) can run jobs twice. After any server move, checksudo crontab -l -u <user>for each user andls /etc/cron.d. - The same user as the application. Cron running as another user creates files the application cannot overwrite later.
- A dead man’s switch. Make something tell you when the cron has not run for thirty minutes. The admin dashboard often shows a warning, but you will not be looking at it. A monitoring service that expects a regular ping, or a small script that checks the time of the last run, closes the gap. (See the guide on monitoring a small server.)
3. Payment callbacks must reach the server
This one is invisible until the first payment. A customer pays at the gateway; the gateway then calls your server (an IPN or webhook) to say the payment succeeded, and your billing system marks the invoice paid. If the callback cannot reach the right file, the money arrives and the invoice stays unpaid.
The usual cause is a good security habit applied too widely: an NGINX rule that answers 404 for every PHP file except index.php. That rule is sensible, and it also blocks the callback file. FOSSBilling receives gateway callbacks at ipn.php; other gateways in other systems use their own paths. Allow exactly the callback paths, with a rate limit, and keep everything else blocked:
# in the http block (for example /etc/nginx/conf.d/callbacks.conf)
limit_req_zone $binary_remote_addr zone=callbacks:10m rate=10r/s;
# in the server block
location = /ipn.php {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/fossbilling.sock;
limit_req zone=callbacks burst=20 nodelay;
}
After any change, test with a real small payment on a test invoice, from the customer’s side, and confirm in the admin area that there is exactly one processed transaction and that the invoice shows paid. Test a second payment path (for example a different gateway) separately; they do not share a code path. Remember to refund the test payment at the gateway first, and only then record the refund in the billing system, because recording a refund in the billing system does not move any money.
If you use Cloudflare in front of the site, restore real visitor addresses on the server (the real_ip module with Cloudflare’s published ranges), or the billing system’s rate limiter and logs will only ever see Cloudflare’s addresses. That also means one noisy visitor can lock out everyone behind the same address.
4. Lock the configuration file
The configuration file holds the database credentials and an encryption salt. Treat it like a key:
sudo chown fossbilling:fossbilling /var/www/fossbilling/config.php
sudo chmod 440 /var/www/fossbilling/config.php
Read-only for the application user, invisible to everyone else. The cost is that the admin panel cannot write to it, which is the point. When you need to save certain settings or run an update, unlock it briefly, do the work, and lock it again. Write that down as a procedure so that nobody leaves it open.
Also: keep the admin path private (and restricted by country or address at your firewall or Cloudflare, if your admins have predictable locations), serve everything over HTTPS only, and turn on the strongest second factor your system offers for staff. Remove demo content and the install folder after setup.
5. Back up the key as well as the data
A database dump alone does not restore a working billing system. Both products encrypt some stored values with a key that lives outside the database: in FOSSBilling it is the salt in config.php, in WHMCS it is the encryption hash in configuration.php. Without the original key, encrypted fields in a restored database are unreadable.
So the backup must contain:
- the database, as a consistent dump (
mysqldump --single-transaction), - the configuration file, stored encrypted and off the server,
- uploaded files, custom themes, and any module or extension you added,
- and a restore test on a spare machine, documented once.
Keep a copy somewhere that is not the same server and not the same provider account.
6. Upgrades without surprises
Upgrades are where most problems start, especially when you have customised the look. A custom theme replaces some of the system’s own templates, and when the core changes a form, your override can keep the old one. One real example: a point release started requiring a hidden token in the sign-in and sign-up forms. A customised theme that replaced those forms needed the new field, or customers simply could not sign in.
A safe routine:
- Read the release notes for security and breaking changes.
- Rehearse on a copy: restore last night’s backup to a test instance, run the upgrade there, click through sign-in, order, payment, invoice PDF and the admin area.
- Back up the database and the code immediately before, and note where.
- Update your theme and extensions first if the rehearsal showed that they need changes, in a way that stays compatible with the version you are running now.
- Upgrade in a quiet hour, then lock the configuration file again.
- Verify: pages load, a test payment records once, the cron has run since the upgrade, emails send.
- Keep the rollback (code archive and database dump) until you are sure, then remove it.
7. Email that arrives
Invoices, receipts and password resets are the emails customers must receive. Send them through a proper mail provider over authenticated SMTP, with SPF, DKIM and DMARC set for your domain (see SPF, DKIM and DMARC for a domain that sends from several services). Look at the mail log for a test invoice, not just at the admin screen that says “sent”.
8. Allowlists that point at the old server
Registrars, payment gateways and some APIs only accept requests from addresses you registered. After a server move, every one of those silently starts failing: domain checks return errors, payment status checks are refused, renewals do not run. Keep a list of every service that has your server’s address on an allowlist, and update each of them as part of the migration plan, before the cutover.
9. A short checklist
- Own user, own PHP-FPM pool, own database.
- One cron entry, as the application user, with a dead man’s switch.
- Callback paths allowed in NGINX; test payments for every gateway.
- Configuration file read-only, admin path restricted, second factor on.
- Backups that include the key, and a restore tried once.
- Upgrades rehearsed on a copy, with a rollback.
- Authenticated mail with SPF, DKIM and DMARC.
- A list of every allowlist that holds your server’s address.
When it is worth getting help
Setting up a billing system is a weekend. Setting it up so that it keeps working, handles payments correctly, survives an upgrade and can be restored after a disaster is where experience pays off. I have set up, migrated and customised FOSSBilling for a hosting business, including its payment callbacks, registrar integrations and scheduled jobs, and I can do the same for yours.
You can see my profile on Upwork or read about hosting platform setup. For hosting your own platform on a VPS, SiteHarbour has VPS plans.