ວິທີການຕິດຕັ້ງ Lighttpd ກັບ PHP ແລະ MariaDB ໃນ CentOS/RHEL 8/7


Lighttpd ແມ່ນໂປແກຼມເປີດເວັບທີ່ມີຄວາມປອດໄພ, ວ່ອງໄວ, ປ່ຽນແປງໄດ້ແລະມີການເພີ່ມປະສິດທິພາບຫລາຍຂື້ນທີ່ອອກແບບມາ ສຳ ລັບສະພາບແວດລ້ອມທີ່ມີຄວາມໄວສູງດ້ວຍການ ນຳ ໃຊ້ຫນ່ວຍຄວາມ ຈຳ ໜ້ອຍ ລົງເມື່ອທຽບກັບເຄື່ອງແມ່ຂ່າຍເວັບອື່ນໆ.

ມັນສາມາດຈັດການກັບການເຊື່ອມຕໍ່ໄດ້ເຖິງ 10,000 ຂະ ໜານ ໃນເຄື່ອງແມ່ຂ່າຍດຽວກັບການຄວບຄຸມ CPU-load ທີ່ມີປະສິດຕິພາບແລະມາພ້ອມກັບຊຸດຄຸນນະສົມບັດທີ່ກ້າວ ໜ້າ ເຊັ່ນ FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting ແລະອີກຫຼາຍໆຢ່າງ.

Lighttpd ແມ່ນໂຊລູຊັ່ນທີ່ດີເລີດ ສຳ ລັບທຸກໆ server ຂອງ Linux, ເນື່ອງຈາກພື້ນຖານໂຄງລ່າງທີ່ມີຄວາມໄວສູງທີ່ຊ່ວຍໃຫ້ພວກເຮົາສາມາດປັບຂະ ໜາດ ການເຮັດວຽກທີ່ດີກວ່າເກົ່າຫລາຍຄັ້ງກັບຮາດແວດຽວກັນກ່ວາກັບເຄື່ອງແມ່ຂ່າຍເວັບອື່ນ.

ໃນບົດແນະ ນຳ ນີ້, ພວກເຮົາຈະອະທິບາຍວິທີການຕິດຕັ້ງ Lighttpd ດ້ວຍ PHP, PHP-FPM, ແລະ MariaDB ກ່ຽວກັບການແຈກຈ່າຍ CentOS/RHEL 8/7 ກັບ hostname linux-console.net ແລະທີ່ຢູ່ IP 192.168.0.103.

ຂັ້ນຕອນທີ 1: ຕິດຕັ້ງ Lighttpd Web Server

1. ເພື່ອຕິດຕັ້ງ Lighttpd, ທຳ ອິດ, ທ່ານ ຈຳ ເປັນຕ້ອງປັບປຸງໂປແກຼມໂປຼແກຼມລະບົບຂອງທ່ານແລະຫໍສະ ໝຸດ ທີ່ມີໂດຍໃຊ້ ຄຳ ສັ່ງ yum ຕໍ່ໄປນີ້.

# yum -y update

2. ຕໍ່ໄປ, ທ່ານ ຈຳ ເປັນຕ້ອງເປີດໃຊ້ຫ້ອງເກັບ EPEL ໃນລະບົບຂອງທ່ານແລະປັບປຸງແພັກເກດຊອບແວໂດຍໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

# yum -y install epel-release
# yum -y update

3. ເມື່ອທ່ານເປີດໃຊ້ຫໍສະຫມຸດ EPEL ແລ້ວ, ຕອນນີ້ທ່ານສາມາດຕິດຕັ້ງ Lighttpd ໂດຍການເຮັດວຽກຕາມ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

# yum install lighttpd

4. ເມື່ອແພັກເກດ Lighttpd ຖືກຕິດຕັ້ງແລ້ວ, ທ່ານສາມາດເລີ່ມຕົ້ນແລະເຮັດໃຫ້ການບໍລິການເລີ່ມຕົ້ນໂດຍອັດຕະໂນມັດໃນເວລາບູດແລະໃຫ້ແນ່ໃຈວ່າກວດສອບສະຖານະພາບໂດຍໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

# systemctl start lighttpd
# systemctl enable lighttpd
# systemctl status lighttpd

5. ຕອນນີ້ກວດສອບລຸ້ນຂອງ Lighttpd ທີ່ຕິດຕັ້ງໄວ້ໃນລະບົບຂອງທ່ານໂດຍໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

# lighttpd -v

lighttpd/1.4.55 (ssl) - a light and fast webserver

6. ຕອນນີ້ທ່ານ ຈຳ ເປັນຕ້ອງອະນຸຍາດໃຫ້ມີການຈາລະຈອນ HTTP ແລະ HTTPS ຢູ່ໃນ ກຳ ແພງໄຟຂອງທ່ານ.

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload

7. ຕອນນີ້ເປີດ browser ຂອງທ່ານແລະຊີ້ໄປທີ່ URL ຕໍ່ໄປນີ້ເພື່ອເບິ່ງ Lighttpd webserver ຂອງທ່ານເຮັດວຽກ.

http://Your-Domain.com
OR
http://Your-IP-addr

ໄດເລກະທໍລີຮາກຖານຂອງເອກະສານ ສຳ ລັບ Lighttpd ແມ່ນ/var/www/lighttpd/ແລະເອກະສານການຕັ້ງຄ່າຕົ້ນຕໍແມ່ນຕັ້ງຢູ່ພາຍໃຕ້ /etc/lighttpd/lighttpd.conf.

ຂັ້ນຕອນທີ 2: ການຕິດຕັ້ງ MariaDB ເປັນ MySQL ໃນ CentOS 7

8. ຕໍ່ໄປ, ຕິດຕັ້ງ MySQL ສະ ໜັບ ສະ ໜູນ ສຳ ລັບ Lighttpd ໂດຍໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

# yum -y install mariadb mariadb-server

9. ເມື່ອການຕິດຕັ້ງ ສຳ ເລັດແລ້ວ, ເລີ່ມຕົ້ນ, ເປີດໃຊ້, ແລະກວດສອບສະຖານະພາບຂອງ MariaDB ໂດຍໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

# systemctl start mariadb.service
# systemctl enable mariadb.service
# systemctl status mariadb.service

10. ສຸດທ້າຍ, ທ່ານ ຈຳ ເປັນຕ້ອງຮັບປະກັນການຕິດຕັ້ງ MariaDB ຂອງທ່ານໂດຍການອອກ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

# mysql_secure_installation

ທ່ານຈະໄດ້ຮັບການຖາມ ຄຳ ຖາມທີ່ແຕກຕ່າງກັນເລັກນ້ອຍກ່ຽວກັບການຕິດຕັ້ງ MariaDB ຂອງທ່ານແລະວິທີທີ່ທ່ານຕ້ອງການຮັບປະກັນມັນ. ທ່ານສາມາດປ່ຽນລະຫັດລັບຜູ້ໃຊ້ຮາກຖານຂໍ້ມູນ, ປິດການໃຊ້ງານຖານຂໍ້ມູນການທົດສອບ, ປິດການໃຊ້ງານຂອງຜູ້ໃຊ້ທີ່ບໍ່ລະບຸຊື່ແລະປິດການເຂົ້າລະບົບ root ຈາກໄລຍະໄກ.

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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): Enter OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorization. Set root password? [Y/n] y 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] y ... 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] y ... 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] y - 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] y ... 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!

11. ພະຍາຍາມເຊື່ອມຕໍ່ກັບ MySQL server ແລະທົບທວນຖານຂໍ້ມູນທີ່ມີຢູ່ໃນ server server ຂອງທ່ານດ້ວຍ ຄຳ ສັ່ງຕໍ່ໄປນີ້ຢູ່ປາຍຍອດ.

# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.60-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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]>

ຂັ້ນຕອນທີ 3: ການຕິດຕັ້ງ PHP ແລະ PHP-FPM ກັບ FastCGI ໃນ CentOS 7

12. ເພື່ອໃຫ້ສາມາດໃຊ້ PHP-FPM ດ້ວຍການສະ ໜັບ ສະ ໜູນ FastCGI, ທຳ ອິດ, ທ່ານ ຈຳ ເປັນຕ້ອງຕິດຕັ້ງ PHP ພ້ອມກັບການຂະຫຍາຍທີ່ ຈຳ ເປັນໂດຍໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

# yum -y install php php-mysqlnd php-pdo php-gd php-mbstring

13. ເມື່ອ PHP ຕິດຕັ້ງແລ້ວ, ຕອນນີ້ໃຫ້ການສະ ໜັບ ສະ ໜູນ PHP-FPM ແລະ FastCGI ສຳ ລັບ Lighttpd, ເພື່ອເຮັດສິ່ງນີ້ທ່ານຕ້ອງການຕິດຕັ້ງແພກເກດເຫລົ່ານີ້ເຊັ່ນກັນ.

# yum -y install php-fpm lighttpd-fastcgi

14. ຕອນນີ້ເປີດເອກະສານທີ່ເອີ້ນວ່າ /etc/php-fpm.d/www.conf.

# vi /etc/php-fpm.d/www.conf

ຕັ້ງຜູ້ໃຊ້ແລະກຸ່ມໃຫ້ Lighttpd.

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = lighttpd
; RPM: Keep a group allowed to write in log dir.
group = lighttpd

ພ້ອມກັນນັ້ນ, PHP-FPM ໂດຍການ ນຳ ໃຊ້ແບບເລີ່ມຕົ້ນ /var/run/php/php7.0-fpm.sock, ທ່ານ ຈຳ ເປັນຕ້ອງເຮັດ PHP-FPM ເພື່ອໃຊ້ການເຊື່ອມຕໍ່ TCP. ເຮັດໃຫ້ເສັ້ນ ຟັງ ເບິ່ງຄືດັ່ງຕໍ່ໄປນີ້:

;listen = /var/run/php/php7.0-fpm.sock
listen = 127.0.0.1:9000 

15. ຕອນນີ້ເລີ່ມການບໍລິການ PHP-FPM ແລະຮັບປະກັນວ່າມັນຈະຊ່ວຍໃຫ້ມັນເລີ່ມຕົ້ນໂດຍອັດຕະໂນມັດໃນເວລາບູດໂດຍໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

# systemctl start php-fpm.service
# systemctl enable php-fpm.service

ຂັ້ນຕອນທີ 4: ເປີດໃຊ້ PHP ແລະ PHP-FPM ດ້ວຍ FastCGI ໃນ Lighttpd

16. ນີ້, ພວກເຮົາ ຈຳ ເປັນຕ້ອງດັດແປງສາມເອກະສານ /etc/php.ini, /etc/lighttpd/modules.conf ແລະ /etc/lighttpd/conf.d/fastcgi.conf ເພື່ອໃຫ້ສາມາດສະ ໜັບ ສະ ໜູນ PHP ສຳ ລັບ Lighttpd.

ເປີດເອກະສານ ທຳ ອິດ /etc/php.ini.

# vi /etc/php.ini

ຍົກເລີກການສະແດງຄວາມຄິດເຫັນຕໍ່ໄປນີ້ທີ່ເວົ້າວ່າ line cgi.fix_pathinfo = 1.

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=1

ຈາກນັ້ນເປີດໄຟລ໌ທີສອງທີ່ເອີ້ນວ່າ /etc/lighttpd/modules.conf.

# vi /etc/lighttpd/modules.conf

ຫະປະຊາຊາດໃຫ້ ຄຳ ເຫັນຕໍ່ສາຍຕໍ່ໄປນີ້ທີ່ເວົ້າວ່າລວມມີ“ conf.d/fastcgi.conf”.

##
## FastCGI (mod_fastcgi)
##
include "conf.d/fastcgi.conf"

ຕໍ່ໄປ, ເປີດເອກະສານທີສາມທີ່ມີຊື່ວ່າ /etc/lighttpd/conf.d/fastcgi.conf.

# vi /etc/lighttpd/conf.d/fastcgi.conf

ຕອນນີ້ຕື່ມໃສ່ຖັງຕໍ່ໄປນີ້ຢູ່ທາງລຸ່ມຂອງເອກະສານແລະບັນທຶກມັນໄວ້.

fastcgi.server += ( ".php" =>
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)

ເລີ່ມບໍລິການ Lighttpd ເພື່ອສະທ້ອນການປ່ຽນແປງແລະເປີດໃຊ້ການສະ ໜັບ ສະ ໜູນ PHP.

# systemctl restart lighttpd

ຂັ້ນຕອນທີ 5: ການທົດສອບ PHP ແລະ PHP-FPM ດ້ວຍການສະ ໜັບ ສະ ໜູນ FastCGI ໃນ Lighttpd

17. ດັ່ງທີ່ພວກເຮົາໄດ້ກ່າວມາຂ້າງເທິງວ່າຮາກເອກະສານເລີ່ມຕົ້ນ ສຳ ລັບ Lighttpd ແມ່ນ/var/www/lighttpd /. ດັ່ງນັ້ນ, ໃນທີ່ນີ້ພວກເຮົາຈະສ້າງເອກະສານ phpinfo.php ເຂົ້າໃນໄດເລກະທໍລີນີ້.

# vi /var/www/lighttpd/info.php

ຕື່ມສາຍຕໍ່ໄປນີ້ໃສ່ມັນ. ລະຫັດເລັກໆນ້ອຍໆນີ້ຈະສະແດງຂໍ້ມູນກ່ຽວກັບການຕິດຕັ້ງ PHP ກັບລຸ້ນຂອງມັນ.

<?php
phpinfo();
?>

18. ເປີດຕົວທ່ອງເວັບຂອງທ່ານແລະ ນຳ ທາງໄປທີ່ລິ້ງຕໍ່ໄປນີ້.

http://Your-Domain.com/info.php
OR
http://Your-IP-addr/info.php

ທ່ານຈະເຫັນຂໍ້ມູນການເຮັດວຽກຂອງ PHP, PHP-FPM, ແລະ MySQL ພ້ອມດ້ວຍຫລາຍໂມດູນອື່ນໆທີ່ເປີດໃຊ້ງານແລ້ວ.