firefly-iii Ubuntun20.04安装

项目github地址

https://github.com/firefly-iii/firefly-iii

Getting Started

install it on your server.

  • Install a LAMP stack with PHP 8.2
    sudo apt update && sudo apt -y upgrade
    sudo apt install php8.2
    /*
    出现找不到php8.2 的问题是运行以下命令
    sudo apt autoremove #Clean APT cache after the upgrade.
    [ -f /var/run/reboot-required ] && sudo reboot -f
    # Install few dependency packages before adding the repo.
     sudo apt update
     sudo apt install -y lsb-release gnupg2 ca-certificates apt-transport-https software-properties-common
     # Run the following commands in your terminal to add Surý PPA to your system.
     sudo add-apt-repository ppa:ondrej/php
     sudo apt update
     */
     sudo apt install php8.2
     apt install -y php8.2-{cli,zip,gd,fpm,json,common,mysql,zip,mbstring,curl,xml,bcmath,imap,ldap,intl}
    
  • Install Nginx(apache2方案太复杂,未成功)
    apt install nginx curl -y
    # backup nginx file
    cd /etc/nginx/sites-enabled/
    mv default{,.bak}
    # create firefly.conf in sites-enabled folder and then paste in the config below
    nano /etc/nginx/sites-enabled/firefly.conf
    
      server {
              listen       80 default_server;
              listen       [::]:80 default_server;
              #server_name  subdomain.domain.com;
              root         /var/www/html/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/php7.4-fpm.sock;
              fastcgi_index index.php;
              fastcgi_read_timeout 240;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
              fastcgi_split_path_info ^(.+.php)(/.+)$;
              }
    
          }
      # restart
      systemctl restart nginx 
    
  • Install Mysql
    sudo apt install mysql-server
    sudo mysql
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
    mysql> exit
    mysql -u root -p
    CREATE DATABASE firefly_db;
    GRANT ALL PRIVILEGES ON firefly_db.* TO 'root'@'localhost';
    FLUSH PRIVILEGES;
    exit;
    
  • Install composer
    curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
    composer -v
    
  • Install Firefly III
    # Browse to /var/www
    composer create-project grumpydictator/firefly-iii --no-dev --prefer-dist firefly-iii 6.0.18
    sudo chown -R www-data:www-data firefly-iii
    sudo chmod -R 775 firefly-iii/storage
    
  • Configuration /var/www/html/firefly-iii/.env (隐藏文件)
    DEFAULT_LANGUAGE=zh_CN
    TZ=Asia/Shanghai
    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=firefly_db
    DB_USERNAME=root
    DB_PASSWORD=***
    
  • Initialize the database
    php artisan firefly-iii:upgrade-database
    php artisan firefly-iii:correct-database
    php artisan firefly-iii:report-integrity
    php artisan passport:install
    
  • Now you should be able to visit http://localhost:port
  • 备份恢复
    备份sudo mysqldump -u root -p firefly_db> /var/www/firefly_db_backup.sql;
    恢复source /var/www/firefly_db_backup.sql;
  • 升级
    程序本身不支持后台自动升级,需要自行手动安装
    在你的安装目录运行以下命令:

    cd /var/www
    composer create-project grumpydictator/firefly-iii --no-dev --prefer-dist firefly-iii-updated v6.0.30
    

    这时候目录中就有 firefly-iii-updated 文件夹。
    然后分别执行以下命令:

    cp firefly-iii/.env firefly-iii-updated/.env	#复制现有的 .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
    cd ..
    

    完成升级,现在只需将 firefly-iii-updated 更名为 firefly-iii 即可。

    mv firefly-iii firefly-iii-old
    mv firefly-iii-updated firefly-iii
    

    如果提示 500 Error,那么还是要设置一下权限:

    sudo chown -R www-data:www-data firefly-iii
    sudo chmod -R 775 firefly-iii/storage
    

可能出现的问题

  • 安装php8.2后,项目却报 环境要求>=’8.2.0′
    # 重新清理apt缓存后再次下载
    sudo apt autoremove
    sudo apt update
    sudo apt install -y lsb-release gnupg2 ca-certificates apt-transport-https software-properties-common
    sudo add-apt-repository ppa:ondrej/php
    sudo apt install php8.2
    
  • firefly-iii页面提示货币格式化异常,服务器缺少必要的软件包
    sudo apt-get install -y language-pack-nl-base
    sudo locale-gen
    # 重启后看看是否解决问题。如果还是不行的话,在服务器上单独安装中文语言包试试看:
    apt install language-pack-zh-hans-base
    apt install language-pack-zh-hans
    
  • php升级到8.3(php升级完成后可以按照之前的firefly升级操作进行升级)

    firefly-iii从v6.1.6版本开始,需要php8.3.0版本,移除了对php8.2的支持。php8.3升级参考链接:

    https://cloud.tencent.com/developer/article/2362695

    # 1.添加 ondrej/php 存储库
    # Ubuntu
    sudo add-apt-repository ppa:ondrej/php # Press enter when prompted.
    sudo apt update
    # Debian
    sudo apt install apt-transport-https
    sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
    sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
    sudo apt update
    # 2.安装新的PHP 8.3包
    sudo apt install php8.3-common php8.3-cli php8.3-fpm php8.3-{curl,bz2,mbstring,intl}
    # 3.Web服务器集成
    sudo a2enconf php8.3-fpm
    sudo a2disconf php8.2-fpm # When upgrading from an older PHP version
    sudo systemctl restart apache2
    # 4.迁移配置 此步骤仅适用于从较旧的PHP版本更新到PHP 8.3时
    sudo phpdismod -v 8.3 -s fpm phar 
    # 5.完成更改后,重新启动PHP 8.3-FPM:
    sudo phpdismod -v 8.3 -s fpm phar 
    # 6.删除旧的PHP版本 此时firefly-iii访问会报错,缺少需要的软件包
    sudo apt purge php8.2*
    # 7.重新安装php软件包
    apt install -y php8.2-{cli,zip,gd,fpm,common,mysql,zip,mbstring,curl,xml,bcmath,imap,ldap,intl}
    

    更新php版本后,需要对nginx firefly.conf配置进行修改,并重启服务

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.3-fpm.sock; # 从8.2php8.3-fpm.sock改成php8.3-fpm.sock
        fastcgi_index index.php;
        fastcgi_read_timeout 240;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_split_path_info ^(.+.php)(/.+)$;
    }
    

相关命令

    sudo systemctl start nginx # 启动nginx
    systemctl enable nginx.service # 开机自启

参考链接

https://computingforgeeks.com/how-to-install-php-8-2-on-ubuntu/?expand_article=1

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-22-04

https://gist.github.com/Engr-AllanG/34e77a08e1482284763fff429cdd92fa

https://docs.firefly-iii.org/firefly-iii/installation/self-hosted/

版本升级参考:https://www.yydnas.cn/2023/03/2023.03.18-FireFly III:一款个人财务管理平台/index.html