Invoice Ninja is a free and open source application for invoicing, time tracking, payments and billing customers.
You can easily create and send invoices from anywhere using Invoice Ninja. Invoice Ninja is written in PHP and build with Laravel Framework.
In this tutorial, we will learn how to install and configure Invoice Ninja on a Ubuntu 16.04 server.
Requirements
- A server running Ubuntu 16.04.
- A non root user with sudo privileges setup on your server.
Update the System
Before starting, it is recommended to update your system with the latest version. You can do this with the following command:
sudo apt-get update -y
sudo apt-get upgrade -y
Once your system is up to date, you can proceed to the next step.
Install LAMP Server
First, you will need to install Apache, PHP and MySQL server on your system. You can install them with the following command:
sudo apt-get install apache2 mysql-server php5 php5-mysql -y
Once the installation is completed, start Apache and MySQL service and enable them to start at boot with the following command:
sudo update-rc.d apache2 defaults
sudo update-rc.d mysql defaults
Once you have done, you can proceed to the next step.
Install Required Dependencies
Next, you will need to install some required dependencies on your server. You can install them with the following command:
sudo apt-get install php5-gd php5-curl php5-mcrypt git curl wget unzip -y
Next, enable mcrypt module with the following command:
sudo php5enmod mcrypt
Next, you will also need to install composer on your system. Composer is a dependency manager that can be used to install required PHP libraries on your system.
You can install composer by running the following command:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Once composer is installed, you can proceed to the next step.
Configure Database
Before configuring your database, you will need to secure it first. You can secure it by running the mysql_secure_installation script:
sudo mysql_secure_installation
Answer all the questions as shown below:
Set root password? [Y/n] n
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
Once MySQL is secured, log in to the MySQL shell and create a database for Invoice Ninja:
mysql -u root -p
Enter your root password when prompt, then create a database for Invoice Ninja. It is recommended to set secure password:
mysql>CREATE SCHEMA
ninjaDEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)`
mysql>CREATE USER 'ninja'@'localhost' IDENTIFIED BY 'ninja';
Query OK, 1 row affected (0.00 sec)`
Next, grant all privileges with the following command:
mysql>GRANT ALL PRIVILEGES ON
ninja.* TO 'ninja'@'localhost';
Next, flush all privileges so that the privileges table will be reloaded by MySQL and we can use new credentials.:
mysql>FLUSH PRIVILEGES;
Query OK, 1 row affected (0.00 sec)
Then, exit from the MySQL shell:
mysql>exit;
Query OK, 1 row affected (0.00 sec)
Download Invoice Ninja
You can download the latest version of the Invoice Ninja from GitHub repository with the following command:
git clone https://github.com/hillelcoren/invoice-ninja.git ninja
Once the download is completed, move the ninja directory to the apache web root directory:
sudo mv ninja /var/www/html/
Next, change the directory to ninja and install framework using composer command:
cd /var/www/html/ninja/
sudo composer install
Next, give proper permission to the ninja directory:
sudo chown -R www-data:www-data /var/www/html/ninja
Once you have done, you can proceed to the next step.
Configure Apache for Invoice Ninja
Next, you will need to create a new virtual host directive in Apache. You can do this by creating ninja.conf file inside /etc/apache2/sites-available/ directory:
sudo nano /etc/apache2/sites-available/ninja.conf
Add the following lines:
<VirtualHost *:80>
ServerAdmin admin@yourdomain.com
DocumentRoot /var/www/html/ninja/public
ServerName 192.168.15.189
ServerAlias www.yourdomain.com
<Directory /var/www/html/ninja/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/ninja-error_log
CustomLog /var/log/httpd/ninja-access_log common
</VirtualHost>
Save and close the file, then restart Apache web server so that the changes take place:
sudo /etc/init.d/apache2 restart
Next, enable rewrite module and virtual host by running the following command:
sudo a2enmode rewrite
sudo a2ensite ninja.conf
Next, you will need to enable the production environment for Invoice Ninja. You can do this with the following command:
cd /var/www/html/ninja
sudo cp bootstrap/environment.default.php bootstrap/environment.php
Once you are done, you can proceed to the next step.
Access Invoice Ninja
Once everything is configured, open your web browser and type the URL http://your-server-ip, you will be redirected to the database configuration page:
Here, provide the following information:
Driver : MySQL
Host : localhost
Database : ninja
Username : ninja
Password : ninja
Next, provide SMTP server information as per your need, then create administrator account, accept the term of services and click on the “Submit” button.
Congratulations! Invoice Ninja is successfully installed on your system. You can now easily deploy it in production environment. Feel free to comment me if you have any questions.