Kuinka asentaa Lighttpd PHP: n ja MariaDB: n kanssa CentOS/RHEL 8/7: een


Lighttpd on avoimen lähdekoodin, turvallinen, nopea, joustava ja optimoidumpi verkkopalvelin, joka on suunniteltu nopeuskriittisiin ympäristöihin, joissa muistin käyttö on vähäisempää verrattuna muihin verkkopalvelimiin.

Se pystyy käsittelemään jopa 10 000 yhteyttä yhdellä palvelimella rinnakkain tehokkaalla CPU-kuormanhallinnalla ja mukana tulee edistyksellinen ominaisuusjoukko, kuten FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting ja monet muut.

Lighttpd on erinomainen ratkaisu jokaiselle Linux-palvelimelle nopean io-infrastruktuurinsa ansiosta, jonka avulla voimme skaalata useita kertoja paremman suorituskyvyn samalla laitteistolla kuin muilla vaihtoehtoisilla verkkopalvelimilla.

Tässä opetusohjelmassa kerrotaan, kuinka Lighttpd asennetaan PHP: n, PHP-FPM: n ja MariaDB: n kanssa CentOS/RHEL 8/7 -jakeluihin, joissa on isäntänimi linux-console.net ja IP-osoite 192.168.0.103.

Vaihe 1: Asenna Lighttpd-verkkopalvelin

1. Asenna Lighttpd ensin päivittämällä järjestelmäohjelmistopaketit ja käytettävissä olevat arkistot seuraavalla yum-komennolla.

# yum -y update

2. Seuraavaksi sinun on otettava käyttöön EPEL-arkisto järjestelmässäsi ja päivitettävä ohjelmistopaketit seuraavilla komennoilla.

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

3. Kun olet ottanut EPEL-arkiston käyttöön, voit nyt asentaa Lighttpd: n suorittamalla seuraavan komennon.

# yum install lighttpd

4. Kun Lighttpd-paketit on asennettu, voit käynnistää palvelun ja sallia sen käynnistyvän automaattisesti käynnistyshetkellä ja varmistaa, että tarkistat tilan seuraavilla komennoilla.

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

5. Tarkista nyt järjestelmääsi asennettu Lighttpd-versio seuraavalla komennolla.

# lighttpd -v

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

6. Nyt sinun on sallittava HTTP- ja HTTPS-liikenne palomuurissasi.

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

7. Avaa nyt selaimesi ja osoita seuraavaa URL-osoitetta nähdäksesi Lighttpd-verkkopalvelimesi toimivan.

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

Lighttpd: n oletusasiakirjan juurihakemisto on/var/www/lighttpd/ja pääasetustiedosto sijaitsee /etc/lighttpd/lighttpd.conf -kohdassa.

Vaihe 2: MariaDB: n asentaminen MySQL: nä CentOS 7: ään

8. Asenna seuraavaksi MySQL-tuki Lighttpd: lle seuraavilla komennoilla.

# yum -y install mariadb mariadb-server

9. Kun asennus on valmis, käynnistä, ota käyttöön ja tarkista MariaDB: n tila seuraavilla komennoilla.

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

10. Lopuksi sinun on suojattava MariaDB -asennuksesi antamalla seuraava komento.

# mysql_secure_installation

Sinulta kysytään muutamia erilaisia kysymyksiä MariaDB-asennuksestasi ja siitä, miten haluat suojata sen. Voit vaihtaa tietokannan pääkäyttäjän salasanan, poistaa testitietokannan, poistaa tuntemattomat käyttäjät ja poistaa etätunnuksen.

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. Yritä muodostaa yhteys MySQL-palvelimeen ja tarkista tietokantapalvelimen olemassa olevat tietokannat seuraavilla päätelaitteen komennoilla.

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

Vaihe 3: PHP: n ja PHP-FPM: n asennus FastCGI: n kanssa CentOS 7: een

12. Ota PHP-FPM käyttöön FastCGI-tuella ensin asentamalla PHP ja tarvittavat laajennukset seuraavalla komennolla.

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

13. Kun PHP on asennettu, ota nyt PHP-FPM- ja FastCGI-tuki käyttöön Lighttpd: lle. Tätä varten sinun on asennettava myös nämä paketit.

# yum -y install php-fpm lighttpd-fastcgi

14. Avaa nyt tiedosto nimeltä /etc/php-fpm.d/www.conf.

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

Aseta käyttäjä ja ryhmä Lighttpd: ksi.

; 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

Lisäksi PHP-FPM käyttää oletuksena /var/run/php/php7.0-fpm.sock -liitäntää, sinun on tehtävä PHP-FPM TCP-yhteyden käyttämistä varten. Tee listen -riviltä seuraava:

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

15. Käynnistä nyt PHP-FPM-palvelu ja varmista, että se käynnistyy automaattisesti käynnistyshetkellä seuraavien komentojen avulla.

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

Vaihe 4: PHP: n ja PHP-FPM: n ottaminen käyttöön FastCGI: n kanssa Lighttpd: ssä

16. Tässä on muokattava kolme tiedostoa /etc/php.ini, /etc/lighttpd/modules.conf ja /etc/lighttpd/conf.d/fastcgi.conf, jotta PHP-tuki voidaan ottaa käyttöön Lighttpd: lle.

Avaa ensimmäinen tiedosto /etc/php.ini.

# vi /etc/php.ini

Poista kommentti seuraavasta rivistä, jossa lukee rivi 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

Avaa sitten toinen tiedosto nimeltä /etc/lighttpd/modules.conf.

# vi /etc/lighttpd/modules.conf

Poista kommentti seuraavasta rivistä, joka sanoo "conf.d/fastcgi.conf".

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

Avaa seuraavaksi kolmas tiedosto nimeltä /etc/lighttpd/conf.d/fastcgi.conf.

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

Lisää nyt seuraava säilö tiedoston alareunaan ja tallenna se.

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

Käynnistä Lighttpd-palvelu uudelleen vastaamaan muutoksia ja ottamalla käyttöön PHP-tuki.

# systemctl restart lighttpd

Vaihe 5: PHP: n ja PHP-FPM: n testaaminen FastCGI-tuella Lighttpd: ssä

17. Kuten edellä mainitsimme, Lighttpd: n oletustiedoston juurihakemisto on/var/www/lighttpd /. Joten tässä luomme phpinfo.php-tiedoston tähän hakemistoon.

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

Lisää siihen seuraavat rivit. Tämä pieni koodinpätkä näyttää tietoja PHP-asennuksista ja niiden versioista.

<?php
phpinfo();
?>

18. Avaa selain ja siirry seuraaviin linkkeihin.

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

Näet PHP: n, PHP-FPM: n ja MySQL: n työtiedot, joissa on paljon muita jo käytössä olevia moduuleja.