How to Install Invoice Ninja on Ubuntu 20.04

Invoice Ninja is a free and open-source online invoicing app for freelancers & businesses that helps you to accept payments, track expenses, create proposals, and time-tasks. It is a self-hosted invoice application very similar to commercial invoice applications such as Freshbooks. It allows you to create your own custom invoice and send it online within a second.

Invoice Ninja is very useful for small or medium-sized businesses. If you are looking for secure and easy to use invoicing software then the Invoice Ninja is the best option for you.

In this tutorial, we will show you how to install Invoice Ninja with Apache and Let's Encrypt SSL on Ubuntu 20.04 server.

Prerequisites

  • A server running Ubuntu 20.04.
  • A valid domain name pointed with your server IP.
  • A root password is configured the server.

Getting Started

First, it is recommended to update your system packages to the latest version. Run the following command to update all the packages:

apt-get update -y

Once all the packages are updated, install other required dependencies with the following command:

apt-get install software-properties-common apt-transport-https ca-certificates gnupg2 -y

Once all the dependencies are installed, you can proceed to the next step.

Install LAMP Server

Next, you will need to install Apache, MariaDB, and PHP to your system. First, install the Apache and MariaDB packages with the following command:

apt-get install apache2 mariadb-server -y

After installing both packages, you will need to install PHP version 7.2 and other extensions in your system.

By default, Ubuntu 20.04 ships with PHP version 7.4. So you will need to add the Ondrej repository to your system.

You can add the PHP Ondrej repository with the following command:

add-apt-repository ppa:ondrej/php

Once the repository is added, install the PHP and other extensions with the following command:

apt-get install php7.2 libapache2-mod-php7.2 php-imagick php7.2-fpm php7.2-mysql php7.2-common php7.2-gd php7.2-json php7.2-curl php7.2-zip php7.2-xml php7.2-mbstring php7.2-bz2 php7.2-intl php7.2-gmp unzip -y

After installing all the packages, verify the installed version of PHP with the following command:

php -v

You should see the following output:

PHP 7.2.34-8+ubuntu20.04.1+deb.sury.org+1 (cli) (built: Oct 31 2020 16:57:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.34-8+ubuntu20.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

Configure MariaDB Database

Next, you will need to create a database and user for Invoice Ninja. First, log in to the MariaDB console with the following command:

mysql

Once login, create a database and user with the following command:

MariaDB [(none)]> create database invoicedb;
MariaDB [(none)]> create user invoice@localhost identified by 'password';

Next, grant all the privileges to the invoicedb with the following command:

MariaDB [(none)]> grant all privileges on invoicedb.* to invoice@localhost;

Next, flush the privileges and exit from the MariaDB console with the following command:

MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

Once you are done, you can proceed to the next step.

Install Invoice Ninja

First, download the latest version of Invoice Ninja from its official website:

wget -O invoice-ninja.zip https://download.invoiceninja.com/

Once the download is completed, unzip the downloaded file to the Apache root directory using the following command:

unzip invoice-ninja.zip -d /var/www/html/

Next, set proper permissions and ownership with the following command:

chown -R www-data:www-data /var/www/html/ninja
chmod -R 755 /var/www/html/ninja

Once you are finished, you can proceed to the next step.

Configure Apache for Invoice Ninja

Next, you will need to create an apache virtual host configuration file for Invoice Ninja. You can create it with the following command:

nano /etc/apache2/sites-available/ninja.conf

Add the following lines:

<VirtualHost *:80>
    ServerName invoice.example.com
    DocumentRoot /var/www/html/ninja/public
    <Directory /var/www/html/ninja/public>
       DirectoryIndex index.php
       Options +FollowSymLinks
       AllowOverride All
       Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/invoice-ninja.error.log
    CustomLog ${APACHE_LOG_DIR}/invoice-ninja.access.log combined

    Include /etc/apache2/conf-available/php7.2-fpm.conf
</VirtualHost>

Save and close the file then enable the virtual host file with the following command:

a2ensite ninja.conf

Next, enable the required apache modules using the following command:

a2enmod mpm_event proxy_fcgi setenvif
a2enmod rewrite

Finally, restart the Apache service to apply the changes:

systemctl restart apache2

You can now verify the status of the Apache using the following command:

systemctl status apache2

You should get the following output:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2020-12-27 07:15:15 UTC; 11s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 25097 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 25113 (apache2)
      Tasks: 55 (limit: 2353)
     Memory: 5.3M
     CGroup: /system.slice/apache2.service
             ??25113 /usr/sbin/apache2 -k start
             ??25114 /usr/sbin/apache2 -k start
             ??25115 /usr/sbin/apache2 -k start

Dec 27 07:15:15 ubuntu systemd[1]: Starting The Apache HTTP Server..

At this point, Apache is configured to serve Invoice Ninja. You can now proceed to the next step.

Access Invoice Ninja

Now, open your web browser and access the Invoice Ninja using the URL http://invoice.example.com. You will be redirected to the following page:

Invoice Ninja setup

MySQL settings

User details

Provide your website URL, database details, admin username, password and click on the Submit button. You will be redirected to the Invoice Ninja login screen:

Login

Provide your admin username, password and click on the LOGIN button. You should see the Invoice Ninja dashboard in the following screen:

Invoice Ninja Dashboard

Secure Invoice Ninja with Let's Encrypt SSL

It is always a good idea to secure your website with Let's Encrypt SSL. You will need to install the Certbot client to install and manage the SSL. You can install it with the following command:

apt-get install python3-certbot-apache -y

Once the Certbot is installed, run the following command to secure your website with Let's Encrypt SSL:

certbot --apache -d invoice.example.com

You will be asked to provide your email and accept the term of service as shown below:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Plugins selected: Authenticator apache, Installer apache
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for invoice.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/invoice-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/invoice-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/invoice-le-ssl.conf

Next, select whether or not to redirect HTTP traffic to HTTPS as shown below:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Type 2 and hit Enter to install the Let's Encrypt SSL for your website:

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/invoice.conf to ssl vhost in /etc/apache2/sites-available/invoice-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://invoice.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=invoice.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/invoice.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/invoice.example.com/privkey.pem
   Your cert will expire on 2020-10-23. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Now, you can access your website securely using the URL https://invoice.example.com.

Conclusion

Congratulations! you have successfully installed and configured Invoice Ninja with Let's Encrypt SSL on Ubuntu 20.04 server. You can now explore the Invoice Ninja for more features and deploy it in the production environment. Feel free to ask me if you have any questions.

Share this page:

0 Comment(s)