Wéi installéiere Dir Lighttpd mat PHP a MariaDB op CentOS/RHEL 8/7


Lighttpd ass en Open-Source, sécheren, séier, flexibelen a méi optimiséierte Webserver entwéckelt fir Geschwindegkeetskritesch Ëmfeld mat manner Gedächtnisverbrauch am Verglach mat anere Webserver.

Et kann bis zu 10.000 Verbindungen parallel an engem Server mat effektiver CPU-Laaschtmanagement handhaben a kënnt mat engem fortgeschrattem Feature-Set wéi FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting a vill méi.

Lighttpd ass eng exzellent Léisung fir all Linux Server, wéinst senger High-Speed io-Infrastruktur, déi et eis erlaabt e puer Mol besser Leeschtung mat der selwechter Hardware ze skaléieren wéi mat aneren alternativen Webserveren.

An dësem Tutorial erkläre mir wéi Dir Lighttpd mat PHP, PHP-FPM, a MariaDB op CentOS/RHEL 8/7 Verdeelunge mat Hostnumm linux-console.net an IP Adress 192.168.0.103 installéiere wëllt.

Schrëtt 1: Installéiert Lighttpd Web Server

1. Fir Lighttpd z'installéieren, musst Dir als éischt Är System Software Packagen a verfügbare Repositories aktualiséieren mat dem folgenden yum Kommando.

# yum -y update

2. Als nächst musst Dir EPEL Repository op Ärem System aktivéieren an Software Packagen aktualiséieren mat de folgende Kommandoen.

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

3. Wann Dir den EPEL Repository aktivéiert hutt, kënnt Dir elo Lighttpd installéieren andeems Dir de folgende Kommando ausféiert.

# yum install lighttpd

4. Soubal d'Lighttpd Packagen installéiert sinn, kënnt Dir de Service starten an aktivéieren fir automatesch bei der Bootzäit unzefänken a sécherzestellen datt de Status mat de folgende Kommandoen z'iwwerpréiwen.

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

5. Elo iwwerpréift d'Versioun vu Lighttpd op Ärem System installéiert mat dem folgenden Kommando.

# lighttpd -v

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

6. Elo musst Dir HTTP an HTTPS Traffic op Ärer Firewall erlaben.

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

7. Elo Äre Browser opmaachen a weisen op déi folgend URL fir ze gesinn datt Äre Lighttpd Webserver funktionnéiert.

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

De Standarddokumentroot Verzeechnes fir Lighttpd ass /var/www/lighttpd/ an d'Haaptkonfiguratiounsdatei ass ënner /etc/lighttpd/lighttpd.conf.

Schrëtt 2: MariaDB als MySQL an CentOS 7 installéieren

8. Als nächst installéiert MySQL Support fir Lighttpd mat de folgende Kommandoen.

# yum -y install mariadb mariadb-server

9. Wann d'Installatioun fäerdeg ass, starten, aktivéieren a verifizéieren de Status vu MariaDB mat de folgende Kommandoen.

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

10. Schlussendlech musst Dir Är MariaDB Installatioun sécheren andeems Dir de folgende Kommando ausstellt.

# mysql_secure_installation

Dir wäert e puer verschidde Froen iwwer Är MariaDB Installatioun opgefuerdert ginn a wéi Dir se wëllt sécheren. Dir kënnt d'Datebankroot Benotzer Passwuert änneren, d'Testdatenbank auszeschalten, anonym Benotzer auszeschalten, a Root Login op afstand deaktivéieren.

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. Probéiert mat MySQL Server ze verbannen an iwwerpréift déi existent Datenbanken op Ärem Datebankserver mat de folgende Kommandoen um Terminal.

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

Schrëtt 3: PHP a PHP-FPM mat FastCGI op CentOS 7 installéieren

12. Fir PHP-FPM mat FastCGI Ënnerstëtzung z'aktivéieren, musst Dir als éischt PHP installéieren zesumme mat noutwendege Verlängerungen mat dem folgenden Kommando.

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

13. Wann PHP installéiert ass, aktivéiert elo PHP-FPM a FastCGI Support fir Lighttpd, fir dëst ze maachen, musst Dir dës Packagen och installéieren.

# yum -y install php-fpm lighttpd-fastcgi

14. Elo öffnen eng Datei mam Numm /etc/php-fpm.d/www.conf.

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

Setzt de Benotzer a Grupp op 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

Och PHP-FPM benotzt par défaut /var/run/php/php7.0-fpm.sock Socket, Dir musst PHP-FPM maachen fir eng TCP Verbindung ze benotzen. Maacht d'lauschteren Linn wéi follegt:

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

15. Start elo PHP-FPM Service a gitt sécher datt et aktivéiert gëtt fir automatesch bei der Bootzäit mat de folgende Kommandoen ze starten.

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

Schrëtt 4: PHP a PHP-FPM mat FastCGI an Lighttpd aktivéieren

16. Hei musse mir dräi Dateien änneren /etc/php.ini, /etc/lighttpd/modules.conf an /etc/lighttpd/conf.d/fastcgi.conf fir PHP-Ënnerstëtzung fir Lighttpd z'aktivéieren.

Öffnen déi éischt Datei /etc/php.ini.

# vi /etc/php.ini

Un-kommentéieren déi folgend Zeil déi seet Linn 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

Da öffnen déi zweet Datei mam Numm /etc/lighttpd/modules.conf.

# vi /etc/lighttpd/modules.conf

Un-kommentéieren déi folgend Zeil déi seet enthalen conf.d/fastcgi.conf.

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

Als nächst, öffnen déi drëtt Datei mam Numm /etc/lighttpd/conf.d/fastcgi.conf.

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

Füügt elo de folgende Container um Enn vun der Datei a späichert et.

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

Restart de Lighttpd Service fir Ännerungen ze reflektéieren an PHP Support z'aktivéieren.

# systemctl restart lighttpd

Schrëtt 5: Testen PHP a PHP-FPM mat FastCGI Support am Lighttpd

17. Wéi mir uewen gesot hunn, datt d'Standarddokumentroot fir Lighttpd /var/www/lighttpd/ ass. Also, hei wäerte mir eng phpinfo.php Datei an dësem Verzeechnes erstellen.

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

Füügt déi folgend Zeilen derbäi. Dëst klengt Stéck Code weist Informatiounen iwwer PHP Installatioun mat hire Versiounen.

<?php
phpinfo();
?>

18. Öffnen Äre Browser a navigéiert op déi folgend Linken.

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

Dir gesitt Aarbechtsinformatioun vu PHP, PHP-FPM, a MySQL mat villen anere Moduler déi scho aktivéiert sinn.