Sådan installeres Lighttpd med PHP og MariaDB på CentOS/RHEL 8/7


Lighttpd er en open source, sikker, hurtig, fleksibel og mere optimeret webserver designet til hastighedskritiske miljøer med mindre hukommelsesudnyttelse sammenlignet med andre webservere.

Det kan håndtere op til 10.000 forbindelser parallelt på en server med effektiv CPU-load-styring og leveres med et avanceret funktionssæt såsom FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting og mange flere.

Lighttpd er en fremragende løsning til enhver Linux-server på grund af dens io-infrastruktur med høj hastighed, der giver os mulighed for at skalere flere gange bedre ydeevne med den samme hardware end med andre alternative webservere.

I denne vejledning forklarer vi, hvordan du installerer Lighttpd med PHP, PHP-FPM og MariaDB på CentOS/RHEL 8/7 distributioner med værtsnavn linux-console.net og IP-adresse 192.168.0.103.

Trin 1: Installer Lighttpd Web Server

1. For at installere Lighttpd skal du først opdatere dine systemsoftwarepakker og tilgængelige arkiver ved hjælp af følgende yum-kommando.

# yum -y update

2. Dernæst skal du aktivere EPEL-lager på dit system og opdatere softwarepakker ved hjælp af følgende kommandoer.

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

3. Når du har aktiveret EPEL-arkivet, kan du nu installere Lighttpd ved at køre følgende kommando.

# yum install lighttpd

4. Når Lighttpd-pakkerne er installeret, kan du starte og aktivere tjenesten til automatisk at starte ved opstartstid og sørge for at bekræfte status ved hjælp af følgende kommandoer.

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

5. Bekræft nu den version af Lighttpd, der er installeret på dit system ved hjælp af følgende kommando.

# lighttpd -v

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

6. Nu skal du tillade HTTP og HTTPS-trafik på din firewall.

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

7. Åbn nu din browser og peg på følgende URL for at se din Lighttpd webserver arbejde.

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

Standarddokumentets rodmappe til Lighttpd er/var/www/lighttpd /, og hovedkonfigurationsfilen findes under /etc/lighttpd/lighttpd.conf.

Trin 2: Installation af MariaDB som MySQL i CentOS 7

8. Installer derefter MySQL-understøttelse af Lighttpd ved hjælp af følgende kommandoer.

# yum -y install mariadb mariadb-server

9. Når installationen er afsluttet, skal du starte, aktivere og kontrollere status for MariaDB ved hjælp af følgende kommandoer.

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

10. Endelig skal du sikre din MariaDB-installation ved at udstede følgende kommando.

# mysql_secure_installation

Du vil blive bedt om et par forskellige spørgsmål vedrørende din MariaDB-installation, og hvordan du vil sikre den. Du kan ændre databasens root-brugeradgangskode, deaktivere testdatabasen, deaktivere anonyme brugere og deaktivere root-login eksternt.

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. Prøv at oprette forbindelse til MySQL-serveren, og gennemgå de eksisterende databaser på din databaseserver med følgende kommandoer på terminalen.

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

Trin 3: Installation af PHP og PHP-FPM med FastCGI på CentOS 7

12. For at aktivere PHP-FPM med FastCGI-support skal du først installere PHP sammen med nødvendige udvidelser ved hjælp af følgende kommando.

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

13. Når PHP er installeret, skal du nu aktivere PHP-FPM og FastCGI support til Lighttpd. For at gøre dette skal du også installere disse pakker.

# yum -y install php-fpm lighttpd-fastcgi

14. Åbn nu en fil med navnet /etc/php-fpm.d/www.conf.

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

Indstil brugeren og gruppen til 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

Også PHP-FPM bruger som standard /var/run/php/php7.0-fpm.sock-stik, du skal oprette PHP-FPM for at bruge en TCP-forbindelse. Få lyt linjen til at se således ud:

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

15. Start nu PHP-FPM-tjenesten, og sørg for at aktivere den til automatisk at starte ved opstartstid ved hjælp af følgende kommandoer.

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

Trin 4: Aktivering af PHP og PHP-FPM med FastCGI i Lighttpd

16. Her skal vi ændre tre filer /etc/php.ini, /etc/lighttpd/modules.conf og /etc/lighttpd/conf.d/fastcgi.conf for at muliggøre PHP-understøttelse af Lighttpd.

Åbn første fil /etc/php.ini.

# vi /etc/php.ini

Fjern kommentar til den følgende linje, der siger linje 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

Åbn derefter den anden fil, der hedder /etc/lighttpd/modules.conf.

# vi /etc/lighttpd/modules.conf

Fjern kommentar til den følgende linje, der siger, inkluderer "conf.d/fastcgi.conf".

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

Åbn derefter den tredje fil, der hedder /etc/lighttpd/conf.d/fastcgi.conf.

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

Tilføj nu den følgende container i bunden af filen, og gem den.

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

Genstart Lighttpd-tjenesten for at afspejle ændringer og aktivere PHP-support.

# systemctl restart lighttpd

Trin 5: Test af PHP og PHP-FPM med FastCGI Support i Lighttpd

17. Som vi sagde ovenfor, er standarddokumentroden for Lighttpd/var/www/lighttpd /. Så her opretter vi en phpinfo.php-fil i denne mappe.

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

Føj følgende linjer til det. Dette lille stykke kode vil vise oplysninger om PHP-installation med deres versioner.

<?php
phpinfo();
?>

18. Åbn din browser, og naviger til følgende links.

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

Du vil se arbejdsoplysninger om PHP, PHP-FPM og MySQL med mange andre moduler, der allerede er aktiveret.