How to Deploy Akaunting - An Opensource FreshBooks Alternative

Updated on April 26, 2024
How to Deploy Akaunting - An Opensource FreshBooks Alternative header image

Introduction

Akaunting is an open-source web-based accounting software that offers a range of business management features such as invoicing, financial reporting, expense management, and payment tracking. It's an alternative to applications such as QuickBooks, WaveApps, and FreshBooks with self-hosting features that grant you full control over your accounting information.

This guide explains how to deploy Akaunting on a Vultr Cloud Server and set up the application to securely perform accounting tasks using a graphical web interface. In addition, you will integrate a Vultr Managed Database for MySQL to improve the Akaunting application server reliability and availability for production use.

Prerequisites

Before you begin:

Set Up the Database

Akaunting uses a MySQL, PostgreSQL, or SQLite database to store data. In a production environment, use an external database server such as a Vultr Managed Database for MySQL to ensure improved uptime and high availability by offloading most database functionalities from the Akaunting server to the database server. Follow the steps below to create a new MySQL database to use with your Akaunting application.

  1. Log in to your Vultr Managed Database for MySQL cluster. Replace dbhost.vultrdb.com, 16751 and vultradmin with your actual database details.

    console
    $ mysql -h dbhost.vultrdb.com -P 16751 -u vultradmin -p
    

    Enter your Vultr Managed Database for MySQL administrator password to access the database console.

  2. Create a new Akaunting database akauntingdb.

    sql
    mysql> CREATE DATABASE akauntingdb;
    
  3. Switch to the database.

    sql
    mysql> USE akauntingdb;
    
  4. Create a new MySQL user akauntingadmin with a strong password.

    sql
    mysql> CREATE USER 'akauntingadmin'@'localhost' IDENTIFIED BY 'secure-password';
    
  5. Grant the user full privileges to the Akaunting database.

    sql
    mysql> GRANT ALL PRIVILEGES ON akauntingdb.* TO 'akauntingadmin'@'localhost';
    
  6. Flush the MySQL privileges table to apply the new permission changes.

    sql
    mysql> FLUSH PRIVILEGES;
    
  7. Exit the MySQL console.

    sql
    mysql> EXIT
    

Install Akaunting

Akaunting uses your existing web server configuration to correctly run and serve the application files on your domain name. Follow the steps below to install all required PHP modules, verify your web server package, and download the latest Akaunting release package to run on your server.

  1. Install all required PHP extensions to use with Akaunting.

    console
    $ sudo apt install php php-fpm php-mysql php-bcmath php-ctype php-curl php-dom php-fileinfo php-intl php-gd php-json php-mbstring php-xml php-zip
    
  2. View the installed PHP version and verify the version number to use with your PHP-FPM configurations.

    console
    $ php -v
    

    Output:

    PHP 8.1.2-1ubuntu2.14 (cli) (built: Aug 18 2023 11:41:11) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.1.2, Copyright (c) Zend Technologies
        with Zend OPcache v8.1.2-1ubuntu2.14, Copyright (c), by Zend Technologies

    Based on the above output, PHP 8.1 is the available version on the server. You can use the version number to access PHP-FPM and verify the service status using the following command.

    console
    $ sudo systemctl status php8.1-fpm status
    
  3. View the Nginx web server status and verify that it's up and running.

    console
    $ sudo systemctl status nginx
    

    Output:

    ● nginx.service - A high performance web server and a reverse proxy server
    Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
    Active: active (running) since Sun 2024-04-07 18:48:52 UTC; 4min 21s ago
      Docs: man:nginx(8)
    Main PID: 5501 (nginx)
     Tasks: 3 (limit: 2299)
    Memory: 2.4M
       CPU: 23ms
    CGroup: /system.slice/nginx.service
            ├─5501 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
            ├─5503 "nginx: worker process"
            └─5504 "nginx: worker process"
  4. Navigate to the default web root directory /var/www/html/.

    console
    $ cd /var/www/html/
    
  5. Create a new directory to store the Akaunting web application files. For example, akaunting.example.com.

    console
    $ sudo mkdir akaunting.example.com
    
  6. Switch to the directory.

    console
    $ cd akaunting.example.com
    
  7. Download the latest Akaunting release file and save it as akaunting.zip.

    console
    $ sudo wget -O akaunting.zip https://akaunting.com/download.php?version=latest
    

    The above wget command downloads the latest Akaunting version from the official project website to your server as a new archive file akaunting.zip in your working directory.

  8. Extract files from the Akaunting release file using the Unzip utility.

    console
    $ sudo unzip akaunting.zip
    

    If you receive the following error:

    Command 'unzip' not found, but can be installed with:

    Install the Zip and Unzip archive utilities.

    console
    $ sudo apt install zip unzip
    
  9. List the directory files and verify that new Akaunting files are available including a nginx.example.com.conf template file.

    console
    $ ls
    

    Output:

    LICENSE.txt  akaunting.zip  artisan    composer.json  database   manifest.json  nginx.example.com.conf  public     routes            storage  web.config
    README.md    app            bootstrap  config         index.php  modules        overrides               resources  serviceworker.js  vendor
  10. Delete the original Akaunting archive file to free your server space.

    console
    $ sudo rm akaunting.zip
    
  11. Switch to the parent /var/www/html/ directory.

    console
    $ cd /var/www/html/
    
  12. Grant the Nginx web server user www-data full permissions to all files in the Akaunting web root directory.

    console
    $ sudo chown -R www-data:www-data akaunting.example.com
    

Configure Nginx to Enable Access to Akaunting

Akaunting supports the Nginx and Apache web server applications to deliver all dynamic files on the server. Follow the steps below to configure the Nginx web server to enable access to the Akaunting application interface using your domain akaunting.example.com.

  1. Navigate to the Nginx virtual host configurations directory /etc/nginx/sites-available.

    console
    $ cd /etc/nginx/sites-available
    
  2. Create a new Akaunting configuration file such as akaunting.conf.

    console
    $ sudo touch akaunting.conf
    
  3. Open the file using your preferred text editor such as Vim.

    console
    $ sudo vim akaunting.conf
    
  4. Add the following configurations to the file. Replace akaunting.example.com with your domain.

    nginx
    server {
        listen 80;
        server_name akaunting.example.com;
        root /var/www/html/akaunting.example.com;
    
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Content-Type-Options "nosniff";
    
        index index.html index.htm index.php;
        error_page 404 /index.php;
        charset utf-8;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location ~ \.(env|log) {
            deny all;
        }
    
        location ~ ^/(^app$|bootstrap|config|database|overrides|resources|routes|storage|tests|artisan) {
            deny all;
        }
    
        location ~ ^/(modules|vendor)\/(.*)\.((?!ico|gif|jpg|jpeg|png|js\b|css|less|sass|font|woff|woff2|eot|ttf|svg|xls|xlsx).)*$ {
            deny all;
        }
    
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
        location ~ /\.(?!well-known).* {
            deny all;
        }
    }
    

    Save and close the file.

    The above Nginx configuration creates a new Akaunting virtual host profile that points to the /var/www/html/akaunting application directory and uses the available PHP8.1-FPM module to serve all dynamic PHP application files on the server.

  5. Activate the Akaunting virtual host configuration by linking the configuration to the sites-enabled directory.

    console
    $ sudo ln -s /etc/nginx/sites-available/akaunting.conf /etc/nginx/sites-enabled/
    
  6. Test the Nginx configuration changes to verify any syntax errors.

    console
    $ sudo nginx -t
    

    Output:

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
  7. Restart the Nginx web server to apply all configuration changes.

    console
    $ sudo systemctl restart nginx
    

Secure the Server

The Akaunting virtual host configuration for Nginx includes security options that block access to specific files and requests on the server. To secure the server, set up the default UFW firewall application to allow incoming connections to the Akaunting application. Then, generate trusted SSL certificates using a CA (Certificate Authority) such as Let’s Encrypt to secure your domain with encrypted HTTPS connections.

Set Up the Firewall Application Rules

  1. Verify that the UFW firewall is active on the server.

    console
    $ sudo ufw status
    

    If the UFW application is inactive, allow connections to the default SSH port 22 and activate the firewall using the following command.

    console
    $ sudo ufw allow 22 && sudo ufw enable
    
  2. Allow connections to the server HTTP port 80.

    console
    $ sudo ufw allow 80
    
  3. Allow connections to the HTTPS port 443.

    console
    $ sudo ufw allow 443
    
  4. Restart UFW to apply the new firewall changes.

    console
    $ sudo ufw reload
    

Generate Trusted SSL Certificates

  1. Install the Certbot Let’s Encrypt client application for Nginx.

    console
    $ sudo apt install python3-certbot-nginx
    
  2. Request for a new SSL certificate using your Akaunting domain. Replace akaunting.example.com with your domain and akaunting@example.com with your email address to bing with the SSL certificate request.

    console
    $ sudo certbot --nginx -d akaunting.example.com -m akaunting@example.com --agree-tos
    

    Your output should look like the one below when successful.

    Successfully received certificate.
    Certificate is saved at: /etc/letsencrypt/live/akaunting.example.com/fullchain.pem
    Key is saved at:         /etc/letsencrypt/live/akaunting.example.com/privkey.pem
    This certificate expires on 2024-07-06.
    These files will be updated when the certificate renews.
    Certbot has set up a scheduled task to automatically renew this certificate in the background.
    
    Deploying certificate
    Successfully deployed certificate for akaunting.example.com to /etc/nginx/sites-enabled/akaunting.conf
    Congratulations! You have successfully enabled HTTPS on https://akaunting.example.com
  3. Test the Cerbot SSL certificate automatic renewal process.

    console
    $ sudo certbot renew --dry-run
    

    Output:

    Account registered.
    Simulating renewal of an existing certificate for akaunting.example.com
    
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Congratulations, all simulated renewals succeeded: 
     /etc/letsencrypt/live/akaunting.example.com/fullchain.pem (success)
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Access the Akaunting Interface

  1. Access your Akaunting application domain in a web browser such as Google Chrome.

    https://akaunting.example.com

    Verify that the Akaunting setup interface displays in your web browser.

    Access the Akaunting Interface

  2. Select your default Akaunting application language, for example, English (GB) and press Next to start the configuration process.

  3. Enter your Vultr Managed Database for MySQL host URL in the Hostname field.

    Enable the Akaunting Vultr Managed Database for MySQL Connection

  4. Enter the MySQL user you created earlier in the Username field.

  5. Enter the associated MySQL user password in the Password field.

  6. Enter the Akaunting database name you created earlier in the Database field.

  7. Click Next to test your Akaunting database connection.

  8. Enter your business name in the Company Name field to set up your main Akaunting application information.

    Set Up a new Akaunting Company Profile and Admin User

  9. Enter your business email in the Company Email field.

  10. Enter your new Akaunting administrative user email in the Admin Email field and a strong password in the Admin Password field.

  11. Click Next to save your Akaunting configuration changes.

  12. Enter your administrator email and account password, then click login to access the Akaunting setup page.

  13. Enter your Akaunting account API key in the API Key field or click the Get your API Key prompt to generate a new key.

  14. Fill in your company tax number, and choose a financial year start date to use with Akaunting.

    Set Up the Akaunting Company Information

  15. Enter your company address, select the country of operation, and click the Logo field to upload your company logo to use with your Akaunting-generated documents.

  16. Click Save to apply the application changes and set your default currencies to use with Akaunting documents.

  17. Keep US Dollar selected or click New Currency to set up additional values.

  18. Click Next to save your accounting currency changes.

    Complete the Akauting Configuration Steps

  19. Click Create your first Invoice to set up a sample Akaunting invoice.

  20. Set up your Invoice details with a title in the Title field, upload a logo, and enter an optional invoice subheading.

  21. Click Add a Customer in the billing section and select New Customer from the list of options to create a new customer profile.

  22. Enter the new customer details in the pop-up dialog and click Save to add your first client.

    Create a new Akaunting Invoice

  23. Enter the additional invoice details including the date, invoice, and order numbers. Then click Add an Item to add your invoice values.

  24. Click Save at the bottom of the invoice page to preview your Akaunting invoice.

  25. Click the options symbol in the top right corner next to Edit to download the invoice in PDF format, print, customize, or send the document in a new email.

  26. Navigate to Settings on the left navigation menu and click Email Service to enable your SMTP server details to use with email communications on the server. All generated invoices and additional items are sent over email when you integrate an active SMTP server with your Akaunting application.

    Enable Akaunting SMTP Server Settings to Send Invoice Mails

    You have set up your Akaunting application information and created an example invoice document. For every invoice or company tracking document you create, you can share it with multiple users using links or email messages depending on your SMTP account settings.

Troubleshooting

The Akaunting application may display errors or fail to run on your server after installation due to several issues. Follow the troubleshooting steps below to fix the following common installation and application errors to enable Akaunting on your server.

Connection Timed Out

A connection time-out error is a result of your web server or firewall configurations. Follow the steps below to verify the error source.

  1. View the firewall table and verify that connections to the HTTPS port 443 are allowed to the server.

    console
    $ sudo ufw status
    
  2. View the Nginx web server status and verify that it’s actively running.

    console
    $ sudo systemctl status nginx
    
  3. View the Nginx web server logs to verify the latest entries associated with your application error.

    console
    $ sudo cat /var/log/nginx/error.log
    
  4. Restart the Nginx to refresh all connections to your Akaunting application.

    console
    $ sudo systemctl restart nginx
    

Error: Could not connect to the database! Please, make sure the details are correct.

  1. Log in to your MySQL server using the Akaunting database user.

    console
    $ mysql -u akauntingadmin -p
    
  2. View all databases and verify that the user has access to the Akaunting database.

    sql
    mysql> SHOW DATABASES;
    

    Output:

    +--------------------+
    | Database           |
    +--------------------+
    | akauntingdb        |
    +--------------------+
    1 rows in set (0.02 sec)

    If the Akaunting database is not available on the list, log out of the user, then log in to the MySQL server as an administrator to assign the user full privileges to the database.

  3. Visit your Akaunting configuration page and set up the database user details again to test connectivity to the MySQL database server.

    https://akaunting.example.com

Unable to save admin user and company information

  1. Delete your Akaunting web root directory files.

    console
    $ sudo rm -r /var/www/html/akaunting/*
    
  2. Download the latest Akaunting version again.

    console
    $ sudo wget -O /var/www/html/akaunting/akaunting.zip https://akaunting.com/download.php?version=latest
    
  3. Extract files from the Akaunting archive file using unzip.

    console
    $ sudo unzip /var/www/html/akaunting/akaunting.zip
    
  4. Grant the web server user www-data full privileges to all directory files.

    console
    $ sudo chown -R www-data:www-data /var/www/html/akaunting/
    
  5. Create a new database and grant your MySQL user full privileges to the database.

  6. Access your Akaunting configuration screen again and set up the application with a new database.

    Set Up the Akaunting database

502 Bad Gateway

  1. View the available PHP version on your server.

    console
    $ php -v
    
  2. View the PHP-FPM status and confirm that it's active. For example, for PHP 8.1, run the following command.

    console
    $ sudo systemctl status php8.1-fpm status
    

    Output:

    ● php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
       Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; preset: enabled)
       Active: active (running) since Sun 2024-04-07 18:51:58 UTC; 16min ago
       Docs: man:php-fpm8.1(8)
    Main PID: 14691 (php-fpm8.1)
       Status: "Processes active: 0, idle: 2, Requests: 5, slow: 0, Traffic: 0req/sec"
       Tasks: 3 (limit: 2299)
       Memory: 69.6M
           CPU: 911ms
       CGroup: /system.slice/php8.1-fpm.service
               ├─14691 "php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)"
               ├─14692 "php-fpm: pool www"
               └─14693 "php-fpm: pool www"
  3. Open the Akaunting Nginx configuration and verify that the PHP-FPM directive matches your installed version to handle dynamic Akaunting application requests.

    console
    $ vim /etc/nginx/sites-available/akaunting.conf
    

    Output:

    fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;

    Change the PHP-FPM version number depending on the available version on your server.

Missing API key

  1. Log in or create a new account on the Akaunting website.

  2. Click your new user API Key field within the dashboard to copy your custom key.

    Copy the Akaunting API Key

  3. Access your Akaunting dashboard and add your new account key to activate all the application features.

Conclusion

You have deployed Akaunting on a Vultr Cloud Server, secured the application and set up sample invoice documents. Akaunting offers extended features that allow you to perform multiple accounting tasks on your server. Upgrade your API key to use multiple company profiles, or integrate the application with supported modules to enhance your application interface and features. For more information, visit the Akaunting self-hosting documentation.