本教程适用于以下操作系统版本

  • Ubuntu 22.04(Jammy Jellyfish)
  • Ubuntu 18.04(Bionic Beaver)

本页内容

  • 前置条件
  • 安装 Apache、MariaDB 和 PHP
  • 配置 MariaDB 数据库
  • 安装 Akaunting
  • 为 Akaunting 配置 Apache
  • 使用 Let's Encrypt SSL 保护 Akaunting
  • 访问 Akaunting Web 界面
  • 结论

Akaunting 是一款面向小型企业和自由职业者的开源、自托管会计软件应用。它基于 Laravel、Bootstrap、jQuery 和 RESTful API 构建。它通过 Web 浏览器用于创建和管理发票、报价与财务。它提供了一个出色的应用商店(App Store),供用户和开发者扩展 Akaunting 的功能。

在本教程中,我将向你展示如何在 Ubuntu 22.04 上使用 Apache 和 Let's Encrypt SSL 安装 Akaunting 会计软件。

前置条件

  • 一台运行 Ubuntu 22.04 的服务器。
  • 已解析到你服务器 IP 的有效域名。
  • 服务器上已配置 root 密码。

安装 Apache、MariaDB 和 PHP

首先,你需要在服务器上安装 Apache、MariaDB、PHP 以及其他 PHP 扩展。你可以通过运行以下命令来安装它们全部:

apt-get install apache2 mariadb-server php libapache2-mod-php php-common php-imap php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-bcmath php-ldap php-zip php-curl unzip curl -y

安装完所有软件包后,编辑 PHP 配置文件并更改默认设置:

nano /etc/php/8.1/apache2/php.ini
Change the following lines:
memory_limit = 256M
upload_max_filesize = 16M
post_max_size = 16M
max_execution_time = 300
date.timezone = UTC

保存并关闭文件,然后重启 Apache 服务以应用配置更改:

systemctl restart apache2

配置 MariaDB 数据库

Akaunting 使用 MariaDB/MySQL 作为数据库后端。因此你需要为 Akaunting 创建一个数据库和用户。

首先,使用以下命令登录到 MariaDB:

mysql

登录后,使用以下命令为 Akaunting 创建数据库和用户:

MariaDB [(none)]> CREATE DATABASE akaunting_db;
MariaDB [(none)]> CREATE USER 'akaunting_user'@'localhost' IDENTIFIED BY 'password';

接下来,使用以下命令向 Akaunting 数据库授予所有权限:

MariaDB [(none)]> GRANT ALL ON akaunting_db.* TO 'akaunting_user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

接下来,使用以下命令刷新权限并退出 MariaDB:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

安装 Akaunting

首先,访问 Akaunting 官方下载页面,并使用以下命令下载最新版本:

wget -O Akaunting.zip https://akaunting.com/download.php?version=latest

下载完成后,将下载的文件解压到 Apache 的 Web 根目录:

mkdir -p /var/www/html/akaunting
unzip Akaunting.zip -d /var/www/html/akaunting

接下来,更改 Akaunting 目录的所有者和权限:

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

完成后,你可以继续下一步。

为 Akaunting 配置 Apache

接下来,你需要为 Akaunting 创建一个 Apache 虚拟主机配置文件。你可以使用以下命令创建它:

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

添加以下行:

<VirtualHost *:80>
ServerAdmin 
[email protected]

DocumentRoot /var/www/html/akaunting
ServerName akaunting.example.com
DirectoryIndex index.html index.php
<Directory /var/www/html/akaunting/>
Options +FollowSymlinks
AllowOverride All
Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/akaunting_error.log
CustomLog ${APACHE_LOG_DIR}/akaunting_access.log combined

</VirtualHost>

保存并关闭文件,然后使用以下命令启用 Apache 虚拟主机和 rewrite 模块:

a2ensite akaunting
a2enmod rewrite

接下来,重启 Apache 服务以应用更改:

systemctl restart apache2

现在你可以使用以下命令检查 Apache 的状态:

systemctl status apache2

你将看到以下输出:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-11-12 13:45:47 UTC; 10s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 16032 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 16036 (apache2)
      Tasks: 6 (limit: 464122)
     Memory: 14.2M
     CGroup: /system.slice/apache2.service
             ??16036 /usr/sbin/apache2 -k start
             ??16037 /usr/sbin/apache2 -k start
             ??16038 /usr/sbin/apache2 -k start
             ??16039 /usr/sbin/apache2 -k start
             ??16040 /usr/sbin/apache2 -k start
             ??16041 /usr/sbin/apache2 -k start

Nov 12 13:45:47 ubuntu22041 systemd[1]: Starting The Apache HTTP Server...

使用 Let's Encrypt SSL 保护 Akaunting

接下来,使用 Let's Encrypt SSL 保护你的网站是个好主意。首先,使用以下命令安装 Certbot 客户端:

apt-get install certbot python3-certbot-apache -y

安装完成后,运行以下命令使用 Let's Encrypt SSL 保护你的网站:

certbot --apache -d akaunting.example.com

系统会要求你提供电子邮件并同意服务条款,如下所示:

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 akaunting.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/akaunting-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/akaunting-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/akaunting-le-ssl.conf

接下来,选择是否将 HTTP 流量重定向到 HTTPS,如下所示:

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

输入 2 并按 Enter 键为你的网站安装 Let's Encrypt SSL:

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

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

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/akaunting.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/akaunting.example.com/privkey.pem
   Your cert will expire on 2023-02-12. 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

访问 Akaunting Web 界面

现在,打开你的 Web 浏览器,并使用 URL http://akaunting.example.com 访问 Akaunting Web 界面。你将看到以下屏幕:

如何在 Ubuntu 22.04 上安装 Akaunting 开源会计系统

选择你的语言并点击“下一步”按钮。你将看到数据库配置屏幕:

如何在 Ubuntu 22.04 上安装 Akaunting 开源会计系统

填写你的数据库详细信息并点击“下一步”按钮。你将看到管理员用户账户创建屏幕:

如何在 Ubuntu 22.04 上安装 Akaunting 开源会计系统

填写你的公司名称、电子邮件、密码并点击“下一步”按钮。你将看到 Akaunting 登录屏幕:

如何在 Ubuntu 22.04 上安装 Akaunting 开源会计系统

填写你的管理员用户名、密码并点击“登录”按钮。你将看到以下屏幕:

如何在 Ubuntu 22.04 上安装 Akaunting 开源会计系统

点击“跳过”按钮。你将看到货币屏幕:

如何在 Ubuntu 22.04 上安装 Akaunting 开源会计系统

启用你的货币并点击“下一步”按钮。你将看到插件屏幕:

如何在 Ubuntu 22.04 上安装 Akaunting 开源会计系统

安装你所需的模块并点击“下一步”按钮。你将看到以下屏幕:

如何在 Ubuntu 22.04 上安装 Akaunting 开源会计系统

你现在可以从上述屏幕创建你的第一张发票。

结论

恭喜!你已成功在 Ubuntu 22.04 服务器上使用 Apache 和 Let's Encrypt SSL 安装了 Akaunting。你现在可以在你的组织中托管 Akaunting 软件,以便随时随地管理你的发票、报价和财务。如果你有任何疑问,欢迎随时向我提问。