Cách cài đặt phần mềm diễn đàn ElkArte trên Ubuntu 22.04

theanh

Administrator
Nhân viên
ElkArte là phần mềm diễn đàn mã nguồn mở và miễn phí được viết bằng ngôn ngữ PHP. Nó dựa trên Simple Machines Forum, giúp bạn dễ dàng tạo diễn đàn cộng đồng. Nó đã phát triển thành một gói diễn đàn hiện đại và giàu tính năng để đáp ứng nhu cầu của người dùng diễn đàn tin nhắn ngày nay. Nó cung cấp nhiều Theme và Addon do cộng đồng tạo ra giúp bạn mở rộng chức năng của ElkArte.

Hướng dẫn này sẽ chỉ cho bạn cách cài đặt ElkArte trên Ubuntu 22.04 với Let's Encrypt SSL.

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

  • Một máy chủ chạy Ubuntu 22.04.
  • Một tên miền hợp lệ được trỏ đến 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ủa bạn.

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

ElkArte chạy trên máy chủ web dựa trên PHP và sử dụng MariaDB làm cơ sở dữ liệu phụ trợ. Vì vậy, 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.

Trước tiên, hãy cài đặt máy chủ Apache và MariaDB bằng lệnh sau:
Mã:
apt install apache2 mariadb-server
Tiếp theo, bạn sẽ cần cài đặt PHP phiên bản 7.4 và các tiện ích mở rộng bắt buộc khác trên máy chủ của mình. Theo mặc định, Ubuntu 22.04 được cài sẵn phiên bản PHP 8.1 trong kho lưu trữ mặc định. Vì vậy, bạn sẽ cần cài đặt kho lưu trữ Ondrej PHP vào máy chủ của mình.
Mã:
apt install software-properties-common -y
add-apt-repository ppa:ondrej/php -y
Sau khi kho lưu trữ PHP được thêm vào máy chủ của bạn, bạn có thể cài đặt PHP bằng lệnh sau:
Mã:
apt install php7.4 libapache2-mod-php7.4 php7.4-common php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-mysql php7.4-gd php7.4-pgsql php7.4-xml php7.4-cli php7.4-imagick php7.4-bcmath php7.4-gmp php7.4-zip unzip -y
Sau khi tất cả các gói được cài đặt, hãy mở tệp php.ini và thay đổi mặc định cài đặt:
Mã:
nano /etc/php/7.4/apache2/php.ini
Thay đổi các dòng sau:
Mã:
Change the following lines:
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = Asia/Kolkata
Lưu và đóng tệp, sau đó khởi động lại dịch vụ Apache để áp dụng thay đổi:
Mã:
systemctl restart apache2

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

Trước tiên, hãy bảo mật cài đặt MariaDB và đặt mật khẩu gốc MariaDB bằng lệnh sau:
Mã:
mysql_secure_installation
Trả lời tất cả các câu hỏi như được hiển thị bên dưới:
Mã:
Enter current password for root (enter for none):
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
Tiếp theo, đăng nhập vào shell MariaDB bằng lệnh sau:
Mã:
mysql -u root -p
Sau khi đăng nhập, hãy tạo cơ sở dữ liệu và người dùng cho ElkArte:
Mã:
MariaDB [(none)]> CREATE DATABASE elkdb;
MariaDB [(none)]> CREATE USER 'elk'@'localhost' IDENTIFIED BY 'password';
Tiếp theo, cấp tất cả các quyền cho elkdb bằng lệnh sau:
Mã:
MariaDB [(none)]> GRANT ALL ON elkdb.* TO 'elk'@'localhost' WITH GRANT OPTION;
Tiếp theo, xóa các quyền và thoát khỏi shell MariaDB bằng lệnh sau lệnh:
Mã:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
Sau khi cấu hình xong cơ sở dữ liệu, bạn có thể tiến hành bước tiếp theo.

Tải xuống ElkArte​

Trước tiên, hãy tải xuống phiên bản mới nhất của ElkArte từ kho lưu trữ Git bằng lệnh sau:
Mã:
wget https://github.com/elkarte/Elkarte/releases/download/v1.1.8/ElkArte_v1-1-8_install.zip
Sau khi tải xuống hoàn tất, hãy giải nén tệp đã tải xuống vào web Apache thư mục gốc bằng lệnh sau:
Mã:
unzip ElkArte_v1-1-8_install.zip -d /var/www/html/elkarte
Tiếp theo, cấp quyền thích hợp cho thư mục elkarte bằng lệnh sau:
Mã:
chown -R www-data:www-data /var/www/html/elkarte/
chmod -R 755 /var/www/html/elkarte/
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 ElkArte​

Tiếp theo, tạo một tệp cấu hình máy chủ ảo Apache mới cho ElkArte.
Mã:
nano /etc/apache2/sites-available/elkarte.conf
Thêm các dòng sau:
Mã:
 ServerAdmin [emailprotected] ServerName elk.linuxbuz.com DocumentRoot /var/www/html/elkarte  Options FollowSymlinks AllowOverride All Require all granted  ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined
Lưu và đóng tệp khi bạn hoàn tất. Sau đó, kích hoạt máy chủ ảo Apache và viết lại mô-đun bằng lệnh sau:
Mã:
a2ensite elkarte.conf
a2enmod rewrite
Cuối cùng, khởi động lại dịch vụ Apache để triển khai các thay đổi.
Mã:
systemctl restart apache2
Bạn cũng có thể kiểm tra trạng thái 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 Sun 2022-09-11 13:35:46 UTC; 9s ago Docs: https://httpd.apache.org/docs/2.4/ Process: 30485 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) Main PID: 30490 (apache2) Tasks: 6 (limit: 4579) Memory: 14.9M CPU: 90ms CGroup: /system.slice/apache2.service ??30490 /usr/sbin/apache2 -k start ??30549 /usr/sbin/apache2 -k start ??30550 /usr/sbin/apache2 -k start ??30551 /usr/sbin/apache2 -k start ??30552 /usr/sbin/apache2 -k start ??30553 /usr/sbin/apache2 -k start
Sep 11 13:35:46 ubuntu2204 systemd[1]: Starting The Apache HTTP Server...

Truy cập Giao diện web ElkArte​

Bây giờ, hãy mở trình duyệt web của bạn và nhập URL Bạn sẽ được chuyển hướng đến Trang chào mừng của ElkArte:


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


Nhấp vào nút Tiếp tục. Bạn sẽ thấy trang cài đặt máy chủ cơ sở dữ liệu:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22386%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 tục. Bạn sẽ thấy trang cài đặt Diễn đàn:


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


Cung cấp URL Diễn đàn, Tên Diễn đàn và nhấp vào nút Tiếp tục. Bạn sẽ thấy trang sau:


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


Nhấp vào nút Tiếp tục. Bạn sẽ thấy trang tạo tài khoản Quản trị viên:


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


Cung cấp tên người dùng, mật khẩu, email quản trị viên và nhấp vào nút Tiếp tục. Sau khi quá trình cài đặt hoàn tất, bạn sẽ thấy trang sau:


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


Nhấp vào diễn đàn mới cài đặt của bạn. Bạn sẽ thấy bảng điều khiển ElkArte trên trang sau:


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

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

Trước tiên, hãy cài đặt Certbot Let's Encrypt Client để quản lý SSL cho trang web:
Mã:
apt-get install certbot python3-certbot-apache -y
Sau khi Certbot được cài đặt, hãy chạy lệnh sau để tải xuống và cài đặt Let's Encrypt SSL cho trang web của bạn:
Mã:
certbot --apache -d elk.linuxbuz.com
Bạn sẽ được yêu cầu cung cấp địa chỉ email và chấp nhận các điều khoản dịch vụ như được hiển thị bên dưới:
Mã:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
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
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for elk.linuxbuz.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/elk-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/elk-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/elk-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 để hoàn tất cài đặt như hiển thị bên dưới.
Mã:
Redirecting vhost in /etc/apache2/sites-enabled/elk.conf to ssl vhost in /etc/apache2/sites-available/elk-le-ssl.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://elk.linuxbuz.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=elk.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/elk.linuxbuz.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/elk.linuxbuz.com/privkey.pem Your cert will expire on 2020-08-19. 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" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - 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 - We were unable to subscribe you the EFF mailing list because your e-mail address appears to be invalid. You can try again later by visiting https://act.eff.org.
Lúc này, ElkArte của bạn được bảo mật bằng Let's Encrypt SSL.

Kết luận​

Xin chúc mừng! bạn đã cài đặt thành công ElkArte với Let's Encrypt SSL trên Ubuntu 22.04. Bây giờ bạn có thể dễ dàng lưu trữ diễn đàn cộng đồng của riêng mình bằng ElkArte. 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