如何使用 Apache 安装 Akaunting 并在 Ubuntu 22.04 上加密 SSL
本教程适用于这些操作系统版本
- Ubuntu 22.04(果酱水母)
- Ubuntu 18.04(仿生海狸)
在此页
- 先决条件
- 安装 Apache、MariaDB 和 PHP
- 配置 MariaDB 数据库
- 安装 Akaunting
- 为 Akaunting 配置 Apache
- 使用 Lets Encrypt SSL 保护 Akaunting
- 访问 Akaunting Web 界面
- 结论
Akaunting 是一个开源和自托管的会计软件应用程序,适用于小型企业和自由职业者。它是使用 Laravel、Bootstrap、jQuery 和 RESTful API 构建的。它用于通过网络浏览器创建和管理发票、报价和财务。它为用户和开发人员提供了一个很棒的 App Store 来扩展 Akaunting 的功能。
在本教程中,我将向您展示如何在 Ubuntu 22.04 上使用 Apache 和 Lets Encrypt SSL 安装 Akaunting 会计软件。
先决条件
- 一台运行 Ubuntu 22.04 的服务器。
- 用您的服务器 IP 指向的有效域名。
- 在服务器上配置了根密码。
安装 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网站根目录:
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
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 虚拟主机并使用以下命令重写模块:
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...
使用 Lets Encrypt SSL 保护 Akaunting
接下来,最好使用 Lets Encrypt SSL 保护您的网站。首先,使用以下命令安装 Certbot 客户端:
apt-get install certbot python3-certbot-apache -y
安装后,运行以下命令以使用 Lets 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):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 键为您的网站安装 Lets 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 界面。您将看到以下屏幕:

选择您的语言,然后单击“下一步”按钮。您将看到数据库配置屏幕:

提供您的数据库详细信息,然后单击“下一步”按钮。您将看到管理员用户帐户创建屏幕:

提供您的公司名称、电子邮件、密码,然后单击“下一步”按钮。您将获得 Akaunting 登录屏幕:

提供您的管理员用户名和密码,然后单击“登录”按钮。您将看到以下屏幕:

单击跳过按钮。您将看到货币屏幕:

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

安装所需的模块,然后单击“下一步”按钮。您将看到以下屏幕:

您现在可以从上面的屏幕创建您的第一张发票。
结论
恭喜!您已经在 Ubuntu 22.04 服务器上成功安装了 Akaunting with Apache 和 Lets Encrypt SSL。您现在可以在您的组织中托管 Akaunting 软件,以从任何地方管理您的发票、报价和财务。如果您有任何问题,请随时问我。