====== Firefly III ======


"Firefly III" is a (self-hosted) manager for your personal finances. It can help you keep track of your expenses and income, so you can spend less and save more. Firefly III supports the use of budgets, categories and tags. Using a bunch of external tools, you can import data. It also has many neat financial reports available.

Firefly III should give you **insight** into and **control** over your finances. Money should be useful, not scary. You should be able to see where it is going, to feel your expenses and to... wow, I'm going overboard with this aren't I?

But you get the idea: this is your money. These are your expenses. Stop them from controlling you. I built this tool because I started to dislike money. Having money, not having money, paying bills with money, you get the idea. But no more. I want to feel "safe", whatever my balance is. And I hope this tool can help you. I know it helps me.
Purpose

Firefly III on iPad

Personal financial management is pretty difficult, and everybody has their own approach to it. Some people make budgets, other people limit their cashflow by throwing away their credit cards, others try to increase their current cashflow. There are tons of ways to save and earn money. Firefly III works on the principle that if you know where your money is going, you can stop it from going there.

By keeping track of your expenses and your income you can budget accordingly and save money. Stop living from paycheck to paycheck but give yourself the financial wiggle room you need.

You can read more about the purpose of Firefly III in the [[https://docs.firefly-iii.org/|documentation]].

[[https://github.com/firefly-iii/firefly-iii|Github]]

[[https://www.firefly-iii.org/|Website]]


Check also [[https://techsaviours.org/news/en/your-own-open-source-finance-tool-firefly-iii|our news]] which contains some explanations and screenshots. The installation there is Docker based if you prefer that way.


===== Packages =====

<code>
pacman -S composer php-sodium
</code>


===== PHP configuration =====

See also [[/en/server/services/php|php installation]]

<code>
nano /etc/php/php.ini
</code>

<code>
extension=bcmath
extension=curl
extension=gd
extension=iconv
extension=intl
extension=pdo_mysql
extension=sodium
extension=zip
</code>

<code>
systemctl restart php-fpm.service
</code>


===== Firefly III =====


==== Installation ====

Check [[https://version.firefly-iii.org/|latest version]] number and change the command below:

<code>
cd /srv/http
composer create-project grumpydictator/firefly-iii --no-dev --prefer-dist firefly-iii 5.7.18
chown -R http: firefly-iii/
chmod -R 775 firefly-iii/storage
</code>


==== Configure .env ====

Check also [[/en/server/services/redis|redis]] and create a [[/en/server/services/mariadb#create_local_user|user]] & [[/en/server/services/mariadb#create_database|database]].

Just the important ones will be listed here. Change the rest to your needs:

<code>
nano .env
</code>

<code>
TRUSTED_PROXIES=**
DB_CONNECTION=mysql
DB_DATABASE=firefly
DB_USERNAME=firefly
DB_PASSWORD=PASSWORD
DB_SOCKET=/run/mysqld/mysqld.sock
CACHE_DRIVER=redis
SESSION_DRIVER=redis
REDIS_SCHEME=unix
REDIS_PATH=/run/redis/redis.sock
# Leave it empty
REDIS_HOST=
REDIS_PORT=
REDIS_PASSWORD=yourPASSWORD
REDIS_DB="0"
REDIS_CACHE_DB="1"
APP_URL=https:/firefly.home
</code>


==== Upgrade ====

Create the update script in ''/srv/http'':

<code>
nano update_firefly.sh
</code>

<code>
#!/bin/bash

# Modify next line to where your firefly-iii instance is installed to.
cd /srv/http 

# Remove old version of firefly-iii
rm -r firefly-iii-old

# Get latest version of firefly
latestversion=$(curl -s https://api.github.com/repos/firefly-iii/firefly-iii/releases/latest  | grep -oP '"tag_name": "\K(.*)(?=")')

# Install latest version
yes | composer create-project grumpydictator/firefly-iii --no-dev --prefer-dist firefly-iii-updated $latestversion
cp firefly-iii/.env firefly-iii-updated/.env
cp firefly-iii/storage/upload/* firefly-iii-updated/storage/upload/
cp firefly-iii/storage/export/* firefly-iii-updated/storage/export/
cd firefly-iii-updated
rm -rf bootstrap/cache/*
php artisan cache:clear
php artisan migrate --seed
php artisan firefly-iii:upgrade-database
php artisan passport:install
php artisan cache:clear

# Serve next version, make sure rights are ok, restart nginx
cd ..
mv firefly-iii firefly-iii-old
mv firefly-iii-updated firefly-iii
sleep 10
cd firefly-iii
php artisan cache:clear
sleep 10
cd ..
chown -R http: firefly-iii
sleep 10
chmod -R 775 firefly-iii/storage
sleep 10
systemctl restart nginx.service
</code>

<code>
chmod u+x update_firefly.sh
./update_firefly.sh
</code>


===== Data importer =====

This data importer is a universal importer, which means it can import from any sources you can think of. And if it can't, well then drop me a line and make me add your favorite data source.

The data import supports a variety of sources:

  * You can import **CSV files** from any source: your bank, YNAB, Tiller or any other source of financial data.
  * You can import from your bank directly using a secure connection.

Because it is very difficult for a poor open source developer like me to build custom-made secure connections to every single bank out there, I've called in the help from two companies that already solved that enigma. They cannot get enough credit:

  * Salt Edge is a fintech solution whose Spectre API supports over 5000 banks.
  * Nordigen is a fintech solution whose API supports over 2100 banks.

If those institutes do not support your financial institution, be sure you can still import CSV files. Other formats are still on the roadmap. That should cover your needs.


==== Installation ====

Check [[https://version.firefly-iii.org/|latest version]] number and change the command below:

<code>
cd /srv/http
composer create-project firefly-iii/data-importer --no-dev --prefer-dist firefly-iii-data-importer 0.9.17
chown -R http: firefly-iii-data-importer/
chmod -R 775 firefly-iii-data-importer/storage
</code>


=== Create access token ===

Go to your https://firefly.home/profile and create a new  access token and name it `Importer` or whatever suits you.


==== Configure .env ====

Check also [[/en/server/services/redis|redis]].

Just the important ones will be listed here. Change the rest to your needs:

<code>
nano .env
</code>

<code>
FIREFLY_III_URL=https://firefly.home
FIREFLY_III_ACCESS_TOKE=yourTOKEN
TRUSTED_PROXIES=**
REDIS_SCHEME=unix
REDIS_PATH=/run/redis/redis.sock
# Leave it empty
REDIS_HOST=
REDIS_PORT=
REDIS_PASSWORD=yourPASSWORD
REDIS_DB="0"
REDIS_CACHE_DB="1"
APP_URL=https://firefly-import.home
</code>


==== Upgrade ====

Create the update script in ''/srv/http'':

<code>
nano update_firefly-importer.sh
</code>

<code>
#!/bin/bash

# Modify next line to where your firefly-iii instance is installed to.
cd /srv/http 

# Remove old version of firefly-iii
rm -r firefly-iii-data-importer-old

# Get latest version of firefly
latestversion=$(curl -s https://api.github.com/repos/firefly-iii/data-importer/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')

# Install latest version
yes | composer create-project firefly-iii/data-importer --no-dev --prefer-dist firefly-iii-data-importer-updated $latestversion
cp firefly-iii-data-importer/.env firefly-iii-data-importer-updated/.env
cp firefly-iii-data-importer/storage/configurations/*.json firefly-iii-data-importer-updated/storage/configurations/

# Serve next version, make sure rights are ok, restart nginx
mv firefly-iii-data-importer firefly-iii-data-importer-old
mv firefly-iii-data-importer-updated firefly-iii-data-importer
sleep 10
chown -R http: firefly-iii-data-importer/
sleep 10
chmod -R 775 firefly-iii-data-importer/storage
sleep 10
systemctl restart nginx.service
</code>

<code>
chmod u+x update_firefly-importer.sh
./update_firefly-importer.sh
</code>
===== Nginx =====

Check also [[/en/server/services/nginx]] and [[/en/server/services/ssl|ssl]].


==== Firefly ====

<code>
nano /etc/nginx/sites-available/firefly.home
</code>

<code>
server {
        listen 80;
        server_name firefly.home;

        rewrite ^ https://$host$request_uri? permanent;
}
server {

        listen 443 ssl http2;
        server_name firefly.home;

        ssl_certificate /etc/nginx/ssl/firefly.home.crt;
        ssl_certificate_key /etc/nginx/ssl/firefly.home.key;
        include conf.d/ssl-params.conf;

        root /srv/http/firefly-iii/public;
        index index.html index.htm index.php;

        location / {
                try_files $uri /index.php$is_args$args;
                autoindex on;
                sendfile off;
       }

        location ~ \.php$ {
                fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_read_timeout 240;
#               fastcgi_param SCRIPT_FILENAME /srv/http/firefly-iii/public/index.php;
                include fastcgi_params;
                fastcgi_split_path_info ^(.+.php)(/.+)$;
                fastcgi_param modHeadersAvailable true;
                fastcgi_param SCRIPT_FILENAME $request_filename;
        }

         access_log /var/log/nginx/firefly-access.log;
         error_log /var/log/nginx/firefly_error.log;

}
</code>

==== Importer ====

<code>
nano /etc/nginx/sites-available/firefly-importer.home
</code>

<code>
server {
        listen 80;
        server_name firefly-importer.home;

        rewrite ^ https://$host$request_uri? permanent;
}
server {
        listen 443 ssl http2;
        server_name firefly-importer.home;

        ssl_certificate /etc/nginx/ssl/firefly-importer.home.crt;
        ssl_certificate_key /etc/nginx/ssl/firefly-importer.home.key;
        include conf.d/ssl-params.conf;

        root /srv/http/firefly-iii-data-importer/public;
        index index.html index.htm index.php;

        location / {
                try_files $uri /index.php$is_args$args;
                autoindex on;
                sendfile off;
       }

        location ~ \.php$ {
                fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_read_timeout 240;
#                fastcgi_param SCRIPT_FILENAME /srv/http/firefly-iii-data-importer/public/index.php;
                include fastcgi_params;
                fastcgi_split_path_info ^(.+.php)(/.+)$;
                fastcgi_param modHeadersAvailable true;
                fastcgi_param SCRIPT_FILENAME $request_filename;

                client_max_body_size 64M;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 4 256k;
                fastcgi_busy_buffers_size 256k;
        }

        access_log /var/log/nginx/firefly-importer-access.log;
        error_log /var/log/nginx/firefly-importer_error.log;
        
}
</code>


===== Conjob =====

<code>
# Firefly III
0 3 * * * /usr/bin/php /srv/http/firefly-iii/artisan firefly-iii:cron
</code>