Kako instalirati Lighttpd s PHP-om i MariaDB-om na CentOS/RHEL 8/7


Lightpd je otvoreni kod, siguran, brz, fleksibilan i optimizirani web poslužitelj dizajniran za okruženja kritična za brzinu s manjim korištenjem memorije u usporedbi s drugim web poslužiteljima.

Može obraditi do 10.000 paralelnih veza na jednom poslužitelju s učinkovitim upravljanjem opterećenjem CPU-a i dolazi s naprednim skupom značajki kao što su FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting i mnoge druge.

Lightpd je izvrsno rješenje za svaki Linux poslužitelj, zbog svoje brze io-infrastrukture koja nam omogućuje skaliranje nekoliko puta boljih performansi s istim hardverom nego s drugim alternativnim web-poslužiteljima.

U ovom vodiču objasnit ćemo kako instalirati Lightpd s PHP, PHP-FPM, i MariaDB na < distribucijeCentOS/RHEL 8/7 s nazivom hosta linux-console.net i IP adresom 192.168.0.103.

Korak 1: Instalirajte Lighttpd web poslužitelj

1. Da biste instalirali Lighttpd, prvo morate ažurirati softverske pakete vašeg sustava i dostupna spremišta pomoću sljedeće naredbe yum.

yum -y update

2. Zatim trebate omogućiti EPEL repozitorij na vašem sustavu i ažurirati softverske pakete pomoću sljedećih naredbi.

yum -y install epel-release
yum -y update

3. Nakon što ste omogućili EPEL repozitorij, sada možete instalirati Lighttpd pokretanjem sljedeće naredbe.

yum install lighttpd

4. Nakon što su paketi Lighttpd instalirani, možete pokrenuti i omogućiti uslugu da se automatski pokrene prilikom pokretanja i provjerite status pomoću sljedećih naredbi.

systemctl start lighttpd
systemctl enable lighttpd
systemctl status lighttpd

5. Sada provjerite verziju Lightpd instaliranu na vašem sustavu pomoću sljedeće naredbe.

lighttpd -v

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

6. Sada trebate dopustiti HTTP i HTTPS promet na vašem vatrozidu.

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

7. Sada otvorite svoj preglednik i pokažite na sljedeći URL da vidite kako vaš Lightpd web poslužitelj radi.

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

Zadani korijenski direktorij dokumenta za Lighttpd je /var/www/lighttpd/, a glavna konfiguracijska datoteka nalazi se pod /etc/lighttpd/lighttpd.conf.

Korak 2: Instaliranje MariaDB kao MySQL u CentOS 7

8. Zatim instalirajte MySQL podršku za Lightpd pomoću sljedećih naredbi.

yum -y install mariadb mariadb-server

9. Nakon dovršetka instalacije pokrenite, omogućite i provjerite status MariaDB-a pomoću sljedećih naredbi.

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

10. Konačno, morat ćete osigurati svoju instalaciju MariaDB izdavanjem sljedeće naredbe.

mysql_secure_installation

Od vas će se tražiti nekoliko različitih pitanja u vezi s vašom instalacijom MariaDB-a i načinom na koji je želite osigurati. Možete promijeniti zaporku root korisnika baze podataka, onemogućiti testnu bazu podataka, onemogućiti anonimne korisnike i daljinski onemogućiti root prijavu.

Uzorak izlaza
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. Pokušajte se spojiti na MySQL poslužitelj i pregledajte postojeće baze podataka na svom poslužitelju baze podataka sa sljedećim naredbama na terminalu.

mysql -u root -p
Uzorak izlaza
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)]>

Korak 3: Instalirajte PHP i PHP-FPM s FastCGI na CentOS 7

12. Da biste omogućili PHP-FPM s podrškom za FastCGI, prvo morate instalirati PHP zajedno s potrebnim proširenjima pomoću sljedeće naredbe.

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

13. Nakon instaliranja PHP sada omogućite PHP-FPM i FastCGI podršku za Lightpd , da biste to učinili, trebate instalirati i ove pakete.

yum -y install php-fpm lighttpd-fastcgi

14. Sada otvorite datoteku pod nazivom /etc/php-fpm.d/www.conf.

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

Postavite korisnika i grupu na Lightpd.

; 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

Također, PHP-FPM prema zadanim postavkama koristi /var/run/php/php7.0-fpm.sock utičnicu, morate napraviti PHP-FPM za korištenje TCP veze. Neka redak listen izgleda ovako:

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

15. Sada pokrenite uslugu PHP-FPM i provjerite jeste li je omogućili da se automatski pokrene prilikom podizanja sustava pomoću sljedećih naredbi.

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

Korak 4: Omogućite PHP i PHP-FPM s FastCGI u Lighttpd

16. Ovdje moramo modificirati tri datoteke /etc/php.ini, /etc/lighttpd/modules.conf i /etc/lighttpd/conf.d/fastcgi.conf za omogućavanje PHP podrške za Lightpd.

Otvorite prvu datoteku /etc/php.ini.

vi /etc/php.ini

Uklonite komentar iz sljedećeg retka koji kaže linija 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

Zatim otvorite drugu datoteku pod nazivom /etc/lighttpd/modules.conf.

vi /etc/lighttpd/modules.conf

Uklonite komentar iz sljedećeg retka koji kaže include “conf.d/fastcgi.conf”.

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

Zatim otvorite treću datoteku pod nazivom /etc/lighttpd/conf.d/fastcgi.conf.

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

Sada dodajte sljedeći spremnik na dno datoteke i spremite ga.

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

Ponovno pokrenite uslugu Lightpd kako biste odrazili promjene i omogućili podršku za PHP.

systemctl restart lighttpd

Korak 5: Testiranje PHP-a i PHP-FPM-a s podrškom za FastCGI u Lighttpd-u

17. Kao što smo gore rekli, zadani korijen dokumenta za Lightpd je /var/www/lighttpd/. Dakle, ovdje ćemo stvoriti datoteku phpinfo.php u ovom direktoriju.

vi /var/www/lighttpd/info.php

Dodajte mu sljedeće retke. Ovaj mali dio koda prikazat će informacije o PHP instalaciji s njihovim verzijama.

<?php
phpinfo();
?>

18. Otvorite svoj preglednik i idite na sljedeće veze.

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

Vidjet ćete informacije o radu PHP, PHP-FPM, i MySQL s puno drugih modula koji su već omogućeni.