Hướng dẫn cài đặt OpenLitespeed 1.7, PHP 8, MariaDB 10 trên CentOS 7
BÀI VIẾT

Hướng dẫn cài đặt OpenLitespeed 1.7, PHP 8, MariaDB 10 trên CentOS 7

3.9K
author Bùi Tấn Việt - 2021-10-14 17:04:45 (GMT+7)

Giới thiệu

OpenLiteSpeed là web server mã nguồn mở dựa trên bản thương mại LiteSpeed. OpenLiteSpeed tích hợp tính năng caching phía server, tương thích với nhiều loại mã nguồn website phổ biến như WordPress. Nếu máy chủ chạy web server OpenLiteSpeed, bạn có thể sử dụng plugin LiteSpeed Cache cho website WordPress của mình. Giúp tối ưu và tăng tốc độ truy cập, giảm tài nguyên sử dụng của máy chủ.

OpenLiteSpeed tự động nhận file .htaccess giống như web server Apache. Vì vậy bạn không cần cấu hình rewrite rule thêm.

Mục đích

  • Cài đặt OpenLiteSpeed 1.7 bản mới nhất, PHP 8 mới nhất, MariaDB Server 10 mới nhất

  • Tương thích với WordPress, sử dụng được plugin LiteSpeed Cache. Chức năng cache phía server hoạt động tốt.

  • Phân quyền mỗi virtualhost chạy một user riêng để chống tấn công local attack. User khác nhau không thể đọc được file của nhau.

  • Tạo điều kiện để sử dụng vsftpd cho mỗi user sau này.

Yêu cầu thiết yếu

Để thực hiện hướng dẫn này, bạn cần các yêu cầu sau:

  • Máy chủ sử dụng CentOS 7

  • Quyền root

Bước 1: Cài đặt OpenLiteSpeed

Trước khi cài đặt, thực hiện update hệ thống

bash (root)
yum update -y 

Khởi động lại máy chủ

bash (root)
reboot

Cài các gói và repository phụ thuộc

bash (root)
yum install epel-release autoconf git rcs wget make unzip -y

Cài đặt OpenLiteSpeed

bash (root)
rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el7.noarch.rpm
bash (root)
yum install openlitespeed -y

Cho OpenLiteSpeed khởi động cùng hệ thống

bash (root)
systemctl enable lsws

Bước 2: Cài đặt PHP 8

Thực hiện cài đặt PHP 8 và các gói PHP mở rộng cần thiết.

bash (root)
yum install lsphp80 lsphp80-mysqlnd lsphp80-gd lsphp80-process lsphp80-mbstring lsphp80-xml lsphp80-pdo lsphp80-imap lsphp80-soap lsphp80-bcmath lsphp80-zip lsphp80-opcache -y

PHP đã cài đặt, kiểm tra bằng lệnh: /usr/local/lsws/lsphp80/bin/php -v

bash (root)
/usr/local/lsws/lsphp80/bin/php -v
PHP 8.0.9 (cli) (built: Aug 20 2021 11:42:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.9, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.9, Copyright (c), by Zend Technologies

Bước 3: Cài đặt MariaDB 10

Cài đặt MariaDB repository

bash (root)
cd /usr/local/src/
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
./mariadb_repo_setup

Cài đặt MariaDB Server bản mới nhất

bash (root)
yum install MariaDB-server MariaDB-client -y

Khởi động MariaDB và cho MariaDB khởi động cùng hệ thống

bash (root)
systemctl start mariadb.service
systemctl enable mariadb.service

Kiểm tra MariaDB bằng lệnh mysql

bash (root)
mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 39
Server version: 10.6.4-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Mặc định, MariaDB không đặt mật khẩu cho user root, để bảo mật, bạn cần đặt mật khẩu root cho MariaDB bằng lệnh mariadb-secure-installation.

Bạn thực hiện enter để đồng ý cho đến khi dòng New password: xuất hiện, lúc này bạn cần đặt mật khẩu cho user root của MariaDB. Thực hiện điền lại mật khẩu root tương tự tại Re-enter new password:. Tiếp tục enter để đồng ý cho đến khi xuất hiện dòng thông báo thành công Thanks for using MariaDB!

bash (root)
mariadb-secure-installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n]
Enabled successfully!
Reloading privilege tables..
 ... Success!

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Bước 4: Đăng nhập vào OpenLiteSpeed Web Admin

Thực hiện đăng nhập với thông tin như sau:

  • URL: https://IP:7080/

  • Usernamepassword được lưu tại: /usr/local/lsws/adminpasswd

Thay IP bằng IP máy chủ của bạn. Bạn có thể dùng lệnh sau để xem username và password: cat /usr/local/lsws/adminpasswd

Bước 5: Tạo Listener

Mặc định OpenLiteSpeed sau khi cài đặt chỉ listen ở port 8088. Chúng ta tạo listener cho port 80 như sau: Vào Listener -> Add.

Điền các cấu hình như sau:

  • Listener name: public port 80

  • IP Address: ANY IPv4

  • Port: 80

  • Binding: Process 1

  • Enable REUSEPORT: Yes

  • Secure: No

Chọn vào biểu tượng lưu bên phải để lưu.

Cấu hình cho web server tự đọc file .htaccess bằng cách vào Server Configuration > General -> Rewrite Control -> chọn Edit, chọn Yes

Bước 6: Tạo Virtualhost cho OpenLiteSpeed

Tạo Virtualhost với mục đích như sau:

  • Tên miền cho website là testhost.com

  • User riêng cho virtualhost này tên là testhost

  • Thư mục chứa website sẽ là /home/testhost/public_html

Thực hiện tạo user hệ thống và thư mục chứa mã nguồn website bằng các lệnh sau:

bash (root)
useradd testhost -s /sbin/nologin
bash (root)
usermod -a -G testhost nobody
bash (root)
mkdir /home/testhost/public_html
chown testhost. -R /home/testhost/
chmod 750 /home/testhost

Tạo virtualhost cho OpenLiteSpeed:

Vào phần Virtualhost -> chọn Add.

Điền thông tin như sau:

  • Virtual Host Name: testhost

  • Virtual Host Root: /home/testhost/public_html

  • Config File: conf/vhosts/testhost/vhconf.conf

  • Follow Symbolic Link: No

  • Enable Scripts/ExtApps: Yes

  • Restrained: Yes

  • External App Set UID Mode: Server UID

  • suEXEC User: testhost

  • suEXEC Group: testhost

Chọn Save, sau đó bấm vào CLICK TO CREATE để hệ thống tạo mới file virtualhost, sau đó bấm Save để lưu.

Tiếp tục vào Virtual Host -> testhost > General, chọn Edit tại mục General.

Điền thông tin

  • Document Root : /home/testhost/public_html

  • Domain Name: testhost.com

  • Enable GZIP Compression: Yes

Tại mục Index Files chọn Edit. Điền các thông tin sau:

  • Use Server Index Files: No

  • Index Files: index.php,index.html

  • Auto Index: Yes

Bước 7: Map Listener vào Virtualhost

Vào Listener, chọn public port 80, Tại Virtual Host Mappings chọn Add.

  • Virtual Host: Chọn testhost

  • Domains: Điền testhost.com

Bấm Save để lưu.

Bước 8: Đổi phiên bản PHP sang lsphp80

  • Vào Server Configuration > External App, chọn Edit tại LiteSpeed SAPI App

  • Tại Command, đổi từ lsphp73 thành lsphp80. Cụ thể dòng này là: $SERVER_ROOT/lsphp73/bin/lsphp, sau đó chọn Save để lưu.

Restart lsws để cập nhật các thay đổi cấu hình

bash (root)
systemctl restart lsws

Chạy lệnh sau để hệ thống kill tất cả các tiến trình lsphp, giúp nhanh chóng cập nhật thay đổi:

bash (root)
for i in `ps -aufx | grep lsphp | awk '{print $2}'`; do kill -9 $i; done

Tạo file /home/testhost/public_html/info.php với nội dung như sau để kiểm tra kết quả

/home/testhost/public_html/info.php
<?php
phpinfo();

Trỏ tên miền về IP của máy chủ, nếu tên miền chưa đăng ký, bạn có thể sử dụng phương pháp trỏ file hosts trên máy tính để kiểm tra. Sau đó truy cập cập vào http://testhost.com/info.php sẽ thấy kết quả web server với PHP 8 đã hoạt động.

Tổng kết

Hướng dẫn trên đã giúp bạn hoàn tất các bước cài đặt OpenLiteSpeed, PHP 8, MariaDB, đồng thời tạo virtualhost cho hosting testhost.com hoạt động. Các phần mềm trên đều được cài đặt bản mới nhất, giúp tương thích với WordPress và đạt hiệu năng tốt nhất.

Tiếp theo, bạn có thể tham khảo Hướng dẫn cài đặt WordPress trên web server OpenLitespeed.


Bạn có làm được theo hướng dẫn này không?

Bài liên quan

Lệnh kiểm tra ứng dụng được cài bằng gói RPM nào
Lệnh kiểm tra ứng dụng được cài bằng gói RPM nào
Hướng dẫn cài đặt và cấu hình máy chủ Email với Exim, Roundcube và Dovecot trên CentOS 7
Hướng dẫn cài đặt và cấu hình máy chủ Email với Exim, Roundcube và Dovecot trên CentOS 7
Hướng dẫn cấu hình SSH Key trên CentOS 7
Hướng dẫn cấu hình SSH Key trên CentOS 7

Object Storage

Chuẩn S3, không giới hạn băng thông

Object Storage

Thuê Server Riêng

Chi phí thấp, cấu hình cao

Thuê Server Riêng
Thông tin tác giả
Bùi Tấn Việt

Co-Founder & CEO at 123HOST

Bình luận

Tính năng đang được phát triển

Đang tải bình luận
Liên hệ chúng tôi