Bii o ṣe le Fi Lighttpd sii pẹlu PHP ati MariaDB lori CentOS/RHEL 8/7


Lighttpd jẹ orisun-ṣiṣi, aabo, iyara, irọrun, ati olupin ayelujara ti o dara julọ ti a ṣe apẹrẹ fun awọn agbegbe to ṣe pataki iyara pẹlu lilo iranti ti o kere si bi a ṣe akawe si awọn olupin ayelujara miiran.

O le mu to awọn asopọ 10,000 ti o jọra ni olupin kan pẹlu iṣakoso Sipiyu-fifuye to munadoko ati pe o wa pẹlu ẹya ẹya ti ilọsiwaju ti o ni irufẹ bi FastCGI, SCGI, Auth, Ṣiṣejade Ijade-jade, URL-atunkọ ati ọpọlọpọ diẹ sii.

Lighttpd jẹ ojutu ti o dara julọ fun gbogbo olupin Linux, nitori iyara io-amayederun giga rẹ ti o fun laaye wa lati ṣe iwọn awọn igba pupọ iṣẹ to dara julọ pẹlu hardware kanna ju pẹlu awọn olupin ayelujara miiran miiran.

Ninu ẹkọ yii, a yoo ṣalaye bi o ṣe le fi Lighttpd sori ẹrọ pẹlu PHP, PHP-FPM, ati MariaDB lori awọn pinpin CentOS/RHEL 8/7 pẹlu orukọ hostname linux-console.net ati adiresi IP 192.168.0.103.

Igbesẹ 1: Fi Server Server Webt sori ẹrọ

1. Lati fi sori ẹrọ Lighttpd, akọkọ, o nilo lati ṣe imudojuiwọn awọn idii sọfitiwia eto rẹ ati awọn ibi ipamọ ti o wa nipa lilo pipaṣẹ yum atẹle.

# yum -y update

2. Itele, o nilo lati mu ibi ipamọ EPEL ṣiṣẹ lori eto rẹ ati mu awọn idii sọfitiwia ṣiṣẹ nipa lilo awọn ofin wọnyi.

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

3. Lọgan ti o ba ti mu ibi ipamọ EPEL ṣiṣẹ, o le fi Lighttpd sori ẹrọ bayi nipa ṣiṣe pipaṣẹ atẹle.

# yum install lighttpd

4. Lọgan ti a ba fi awọn idii Lighttpd sori ẹrọ, o le bẹrẹ ati mu iṣẹ naa ṣiṣẹ lati bẹrẹ laifọwọyi ni akoko bata ati rii daju lati ṣayẹwo ipo naa nipa lilo awọn ofin wọnyi.

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

5. Bayi ṣayẹwo ẹya ti Lighttpd ti a fi sori ẹrọ lori eto rẹ nipa lilo pipaṣẹ atẹle.

# lighttpd -v

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

6. Bayi o nilo lati gba laaye ijabọ HTTP ati HTTPS lori ogiriina rẹ.

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

7. Bayi ṣii ẹrọ aṣawakiri rẹ ki o tọka si URL atẹle lati wo oju-iwe ayelujara Lighttpd rẹ ti n ṣiṣẹ.

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

Ilana gbongbo iwe aṣẹ aiyipada fun Lighttpd jẹ/var/www/lighttpd/ati faili iṣeto akọkọ ti wa labẹ /etc/lighttpd/lighttpd.conf.

Igbese 2: Fifi MariaDB sii bi MySQL ni CentOS 7

8. Nigbamii, fi sori ẹrọ atilẹyin MySQL fun Lighttpd nipa lilo awọn ofin wọnyi.

# yum -y install mariadb mariadb-server

9. Lọgan ti fifi sori ẹrọ ba pari, bẹrẹ, muu ṣiṣẹ, ati ṣayẹwo ipo ti MariaDB nipa lilo awọn ofin wọnyi.

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

10. Lakotan, iwọ yoo nilo lati ni aabo fifi sori ẹrọ MariaDB rẹ nipasẹ ipinfunni aṣẹ atẹle.

# mysql_secure_installation

Iwọ yoo beere lọwọ awọn ibeere oriṣiriṣi diẹ nipa fifi sori ẹrọ MariaDB rẹ ati bii iwọ yoo ṣe fẹ lati ni aabo. O le yi ọrọ igbaniwọle olumulo olumulo gbongbo ṣiṣẹ, mu ibi ipamọ data idanwo, mu awọn olumulo alailorukọ, ki o mu wiwọle root kuro latọna jijin.

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. Gbiyanju lati sopọ si olupin MySQL ki o ṣe atunyẹwo awọn apoti isura data ti o wa lori olupin data rẹ pẹlu awọn ofin wọnyi lori ebute naa.

# 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)]>

Igbesẹ 3: Fifi PHP ati PHP-FPM sii pẹlu FastCGI lori CentOS 7

12. Lati mu PHP-FPM ṣiṣẹ pẹlu atilẹyin FastCGI, akọkọ, o nilo lati fi PHP sii pẹlu awọn amugbooro ti o wulo nipa lilo pipaṣẹ atẹle.

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

13. Lọgan ti a fi PHP sii, ni bayi mu PHP-FPM ati atilẹyin FastCGI ṣiṣẹ fun Lighttpd, lati ṣe eyi o nilo lati fi awọn idii wọnyi sii.

# yum -y install php-fpm lighttpd-fastcgi

14. Bayi ṣii faili kan ti a pe ni /etc/php-fpm.d/www.conf.

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

Ṣeto olumulo ati ẹgbẹ si 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

Pẹlupẹlu, PHP-FPM nipasẹ awọn lilo aiyipada /var/run/php/php7.0-fpm.sock socket, o nilo lati ṣe PHP-FPM lati lo asopọ TCP kan. Jẹ ki laini tẹtisi wo bi atẹle:

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

15. Bayi bẹrẹ iṣẹ PHP-FPM ati rii daju lati muu ṣiṣẹ lati bẹrẹ laifọwọyi ni akoko bata nipa lilo awọn ofin wọnyi.

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

Igbesẹ 4: Ṣiṣe PHP ati PHP-FPM ṣiṣẹ pẹlu FastCGI ni Lighttpd

16. Nibi, a nilo lati yipada awọn faili mẹta /etc/php.ini, /etc/lighttpd/modules.conf ati /etc/lighttpd/conf.d/fastcgi.conf lati jẹki atilẹyin PHP fun Lighttpd.

Ṣii faili akọkọ /etc/php.ini.

# vi /etc/php.ini

Ṣe asọye laini atẹle ti o sọ laini 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

Lẹhinna ṣii faili keji ti a pe /etc/lighttpd/modules.conf.

# vi /etc/lighttpd/modules.conf

Un-ṣe asọye laini atẹle ti o sọ pẹlu “conf.d/fastcgi.conf”.

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

Nigbamii, ṣii faili kẹta ti a pe /etc/lighttpd/conf.d/fastcgi.conf.

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

Bayi ṣafikun eiyan atẹle ni isalẹ faili ki o fipamọ.

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

Tun iṣẹ Lighttpd tun bẹrẹ lati ṣe afihan awọn ayipada ati mu atilẹyin PHP ṣiṣẹ.

# systemctl restart lighttpd

Igbesẹ 5: Idanwo PHP ati PHP-FPM pẹlu Atilẹyin FastCGI ni Lighttpd

17. Bi A ṣe sọ loke pe gbongbo iwe aiyipada fun Lighttpd jẹ/var/www/lighttpd /. Nitorinaa, nibi a yoo ṣẹda faili phpinfo.php sinu itọsọna yii.

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

Ṣafikun awọn ila wọnyi si o. Apakan koodu kekere yii yoo han alaye nipa fifi sori PHP pẹlu awọn ẹya wọn.

<?php
phpinfo();
?>

18. Ṣi ẹrọ aṣawakiri rẹ ki o lọ kiri si awọn ọna asopọ atẹle.

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

Iwọ yoo wo alaye iṣẹ ti PHP, PHP-FPM, ati MySQL pẹlu ọpọlọpọ awọn modulu miiran ti o ti ṣiṣẹ tẹlẹ.