Cách cài đặt Akaunting với Apache và Let's Encrypt SSL trên Ubuntu 22.04

theanh

Administrator
Nhân viên
Akaunting là một ứng dụng phần mềm kế toán tự lưu trữ và mã nguồn mở dành cho các doanh nghiệp nhỏ và người làm nghề tự do. Ứng dụng này được xây dựng bằng Laravel, Bootstrap, jQuery và RESTful API. Ứng dụng này được sử dụng để tạo và quản lý hóa đơn, báo giá và tài chính thông qua trình duyệt web. Ứng dụng này cung cấp một App Store tuyệt vời cho người dùng và nhà phát triển để mở rộng chức năng của Akaunting.

Trong hướng dẫn này, tôi sẽ chỉ cho bạn cách cài đặt phần mềm kế toán Akaunting với Apache và Let's Encrypt SSL trên Ubuntu 22.04.

Điều kiện tiên quyết​

  • Một máy chủ chạy Ubuntu 22.04.
  • Tên miền hợp lệ được trỏ bằng IP máy chủ của bạn.
  • Một mật khẩu gốc được cấu hình trên máy chủ.

Cài đặt Apache, MariaDB và PHP​

Trước tiên, bạn sẽ cần cài đặt Apache, MariaDB, PHP và các tiện ích mở rộng PHP khác trên máy chủ của mình. Bạn có thể cài đặt tất cả chúng bằng cách chạy lệnh sau:
Mã:
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
Sau khi cài đặt tất cả các gói, hãy chỉnh sửa tệp cấu hình PHP và thay đổi giá trị mặc định cài đặt:
Mã:
nano /etc/php/8.1/apache2/php.ini
Mã:
Change the following lines:
Mã:
memory_limit = 256M
upload_max_filesize = 16M
post_max_size = 16M
max_execution_time = 300
date.timezone = UTC
Lưu và đóng sau đó, tệp khởi động lại dịch vụ Apache để áp dụng các thay đổi cấu hình:
Mã:
systemctl restart apache2

Cấu hình cơ sở dữ liệu MariaDB​

Akaunting sử dụng MariaDB/MySQL làm cơ sở dữ liệu phụ trợ. Vì vậy, bạn sẽ cần tạo cơ sở dữ liệu và người dùng cho Akaunting.

Đầu tiên, hãy đăng nhập vào MariaDB bằng lệnh sau:
Mã:
mysql
Sau khi đăng nhập, hãy tạo cơ sở dữ liệu và người dùng cho Akaunting bằng lệnh sau:
Mã:
MariaDB [(none)]> CREATE DATABASE akaunting_db;
MariaDB [(none)]> CREATE USER 'akaunting_user'@'localhost' IDENTIFIED BY 'password';
Tiếp theo, cấp tất cả các quyền cho Cơ sở dữ liệu Akaunting bằng lệnh sau:
Mã:
MariaDB [(none)]> GRANT ALL ON akaunting_db.* TO 'akaunting_user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
Tiếp theo, xóa các đặc quyền và thoát khỏi MariaDB bằng lệnh sau:
Mã:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Cài đặt Akaunting​

Đầu tiên, hãy truy cập trang tải xuống chính thức của Akaunting và tải xuống phiên bản mới nhất bằng cách sử dụng lệnh sau lệnh:
Mã:
wget -O Akaunting.zip https://akaunting.com/download.php?version=latest
Sau khi tải xuống hoàn tất, hãy giải nén tệp đã tải xuống vào thư mục gốc web Apache:
Mã:
mkdir -p /var/www/html/akaunting
unzip Akaunting.zip -d /var/www/html/akaunting
Tiếp theo, hãy thay đổi quyền sở hữu và quyền của Akaunting thư mục:
Mã:
chown -R www-data:www-data /var/www/html/akaunting/
chmod -R 755 /var/www/html/akaunting/
Sau khi hoàn tất, bạn có thể tiến hành bước tiếp theo.

Cấu hình Apache cho Akaunting​

Tiếp theo, bạn sẽ cần tạo tệp cấu hình máy chủ ảo Apache cho Akaunting. Bạn có thể tạo nó bằng lệnh sau:
Mã:
nano /etc/apache2/sites-available/akaunting.conf
Thêm các dòng sau:
Mã:
ServerAdmin [emailprotected]
DocumentRoot /var/www/html/akaunting
ServerName akaunting.example.com
DirectoryIndex index.html index.php

Options +FollowSymlinks
AllowOverride All
Require all granted

ErrorLog ${APACHE_LOG_DIR}/akaunting_error.log
CustomLog ${APACHE_LOG_DIR}/akaunting_access.log combined
Lưu và đóng tệp sau đó kích hoạt máy chủ ảo Apache và viết lại mô-đun bằng lệnh sau lệnh:
Mã:
a2ensite akaunting
a2enmod rewrite
Tiếp theo, khởi động lại dịch vụ Apache để áp dụng các thay đổi:
Mã:
systemctl restart apache2
Bây giờ bạn có thể kiểm tra trạng thái của Apache bằng lệnh sau lệnh:
Mã:
systemctl status apache2
Bạn sẽ nhận được kết quả sau:
Mã:
? 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...

Bảo mật Akaunting bằng Let's Encrypt SSL​

Tiếp theo, bạn nên bảo mật trang web của mình bằng Let's Encrypt SSL. Trước tiên, hãy cài đặt ứng dụng khách Certbot bằng lệnh sau:
Mã:
apt-get install certbot python3-certbot-apache -y
Sau khi cài đặt, hãy chạy lệnh sau để bảo mật trang web của bạn bằng Let's Encrypt SSL:
Mã:
certbot --apache -d akaunting.example.com
Bạn sẽ được yêu cầu cung cấp email và chấp nhận điều khoản dịch vụ như hiển thị bên dưới:
Mã:
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): [emailprotected]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
Tiếp theo, chọn có chuyển hướng lưu lượng HTTP sang HTTPS hay không như hiển thị bên dưới:
Mã:
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
Nhập 2 và nhấn Enter để cài đặt Let's Encrypt SSL cho trang web:
Mã:
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

Truy cập Giao diện Web Akaunting​

Bây giờ, hãy mở trình duyệt web của bạn và truy cập vào giao diện web Akaunting bằng URL Bạn sẽ thấy màn hình sau:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22384%22%3E%3C/svg%3E


Chọn ngôn ngữ của bạn và nhấp vào nút Tiếp theo. Bạn sẽ nhận được màn hình cấu hình cơ sở dữ liệu:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22387%22%3E%3C/svg%3E


Cung cấp thông tin chi tiết về cơ sở dữ liệu của bạn và nhấp vào nút Tiếp theo. Bạn sẽ thấy màn hình tạo tài khoản người dùng Quản trị:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22374%22%3E%3C/svg%3E


Cung cấp tên công ty, email, mật khẩu của bạn và nhấp vào nút Tiếp theo. Bạn sẽ nhận được màn hình đăng nhập Akaunting:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22367%22%3E%3C/svg%3E


Cung cấp tên người dùng quản trị, mật khẩu và nhấp vào nút Đăng nhập. Bạn sẽ nhận được màn hình sau:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22508%22%3E%3C/svg%3E


Nhấp vào nút Bỏ qua. Bạn sẽ thấy màn hình Tiền tệ:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22455%22%3E%3C/svg%3E


Bật tiền tệ của bạn và nhấp vào nút Tiếp theo. Bạn sẽ nhận được màn hình plugin:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22472%22%3E%3C/svg%3E


Cài đặt các module bạn cần và nhấp vào nút Tiếp theo. Bạn sẽ nhận được màn hình sau:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22378%22%3E%3C/svg%3E


Bây giờ bạn có thể tạo hóa đơn đầu tiên của mình từ màn hình trên.

Kết luận​

Xin chúc mừng! bạn đã cài đặt thành công Akaunting với Apache và Let's Encrypt SSL trên máy chủ Ubuntu 22.04. Bây giờ bạn có thể lưu trữ phần mềm Akaunting trong tổ chức của mình để quản lý hóa đơn, báo giá và tài chính từ bất kỳ đâu. Hãy thoải mái hỏi tôi nếu bạn có bất kỳ câu hỏi nào.
 
Back
Bên trên