How to Install Firefly III with Nginx on Ubuntu 18.04 | 20.04

How to Install Firefly III with Nginx on Ubuntu 18.04 20.04

In this post, we are going to show that how to Install Firefly III with Nginx HTTP server on Ubuntu 18.04 | 20.04. If your are going to Install Firefly III on your Ubuntu then this post is ideal for you.

Firefly III is a free, open source and self-hosted server personal finance manager software that is used to track and manage your expenses, income, budgets, cashflow, credit cards, expanses and many more. It is written in PHP Programming language.

For more details about Firefly III, please visit its official website.


How to Install Firefly III with Nginx

Simply follow below steps to install Firefly III on your Ubuntu:

Step 1 : Install Nginx

To install Nginx HTTP on your Ubuntu server, run the commands below.

sudo apt update
sudo apt install nginx

Next, run the commands below to stop, start and enable Nginx service to always start up with the server boots:

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

For check if Nginx server is installed or not, simply open your browser and type server IP or hostname.

If browser show result similar like below then Nginx is installed and working properly.

http://localhost
nginx_default

Step 2 : Install MariaDB Database Server

To install MariaDB database, simply run the commands below:

sudo apt update
sudo apt install mariadb-server mariadb-client

Next, run the commands below to stop, start and enable MariaDB service to always start up with the server boots:

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Now, run the commands below to secure MariaDB server by creating a root password and disallowing remote root access.

sudo mysql_secure_installation

When you run the above command, it will prompted to answer the questions as show below:

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • 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

Now, Restart the MariaDB server using below command:

sudo systemctl restart mariadb.service

For check if MariaDB is installed or Not, run the command below:

sudo systemctl status mariadb.service

Step 3 : Install PHP 7.4-FPM and Related Modules

For install PHP 7.4-FPM, you will need to get it from third-party repositories because PHP 7.4-FPM not available in Ubuntu default repositories. Simply run the command below to add the third party repository:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Now update and upgrade to PHP 7.4 by using command below:

sudo apt update

Next, run the commands below to install PHP 7.4-FPM and its related modules:

sudo apt install php7.4-fpm php7.4-common php7.4-gmp php7.4-curl php7.4-ldap php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-mysql php7.4-gd php7.4-bcmath php7.4-xml php7.4-cli php7.4-zip

After finished installing of PHP 7.4 and its related modules, run the command below to open PHP default config file for Nginx server:

sudo nano /etc/php/7.4/fpm/php.ini

After open the configuration file, Changes the following below lines in the default configuration file and save it:

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

Step 4: Create Firefly III Database

To create Firefly III database, first you will need to create a blank Firefly III database. Simply run the command below to logon to MariaDB database server:

sudo mysql -u root -p

Next, create a database named firefly using command below:

CREATE DATABASE firefly;

Now, run the command below to create a database user named fireflyuser :

CREATE USER 'fireflyuser'@'localhost' IDENTIFIED BY 'your_new_password';

Grant the newly created database user to the firefly database by using command below:

GRANT ALL ON firefly.* TO 'fireflyuser'@'localhost' WITH GRANT OPTION;

Next, save your changes and exit:

FLUSH PRIVILEGES;
EXIT;

Step 5 : Download and Install Latest Release of Firefly III

To download and install the latest release of Firefly III, you will need to use GitHub repository. So first install Composer, Curl and other required dependencies using command below:

sudo apt install curl git
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Next, switch to the Nginx root directory and download Firefly III packages from GitHub repository. To do that run the command below:

cd /var/www/
sudo composer create-project grumpydictator/firefly-iii --no-dev --prefer-dist firefly-iii 5.2.8

When downloading is complete, you will see a message similar like below:

> @php artisan firefly:instructions install
+-----------------------------------------------------------+
|                                                           |
| Thank you for installing Firefly III, v5.2.8!             |
|                                                           |
|                                                           |
+-----------------------------------------------------------+
> @php artisan key:generate
Application key set successfully.

Next, you will need to edit the .env file. So open the file and make the the changes according your environment:

sudo nano /var/www/firefly-iii/.env

After open the file, make the below highlighted changes in the file:

Database credentials. Make sure the database exists. I recommend a dedicated user for Firefly III
 For other database types, please see the FAQ: https://docs.firefly-iii.org/support/faq
 If you use Docker or similar, you can set these variables from a file by appending them with _FILE
 Use "mysql" for MySQL and MariaDB. Use "sqlite" for SQLite.
 DB_CONNECTION=mysql
 DB_HOST=127.0.0.1
 DB_PORT=3306
 DB_DATABASE=firefly
 DB_USERNAME=fireflyuser
 DB_PASSWORD=your_password_here

Save the file and exit.

After that, switch back to Firefly III root directory and update all packages and requirements using commands below:

cd /var/www/firefly-iii
sudo php artisan migrate:refresh --seed
sudo php artisan firefly-iii:upgrade-database
sudo php artisan passport:install

Next, you will need to change the root folder permissions. To do that, run the commands below:

sudo chown -R www-data:www-data /var/www/firefly-iii/
sudo chmod -R 755 /var/www/firefly-iii/

Step 6 :  Configure Nginx for Firefly III

To configure Nginx for Firefly III, you will need to create a new configuration file named firefly.conf. To do that, run the commands below:

sudo nano /etc/nginx/sites-available/firefly.conf

After create configuration file, copy and paste the below content into the configuration file and save it. Replace the highlighted line with your own domain name and directory root location:

server {
    listen 80;
    listen [::]:80;

    server_name  example.com www.example.com;
    root   /var/www/firefly-iii/public;
    index  index.php;
    
    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;

    client_max_body_size 100M;
  
    autoindex off;

    location / {
    try_files $uri $uri/ /index.php$is_args$args;
      }

    location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
         include fastcgi_params;
         fastcgi_intercept_errors on;
    }
}

Save the configuration file and exit.

Next, run the commands below to enable VirtualHost:

sudo ln -s /etc/nginx/sites-available/firefly.conf /etc/nginx/sites-enabled/

Restart the Nginx:

sudo systemctl restart nginx.service

Step 7 : Launch Firefly III

At this stage, Firefly III is installed and ready to use. To launch it, open your favorite web browser and browse to the server domain name http://example.com.

http://example.com

It will open the Firefly III register screen as show below:

At the register screen, Create an admin account and click on Register button.

Now you can login to Firefly III dashboard.


That’s all

If you face any error and issue in above steps , please use comment box below to report.

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top