Lighttpd:n asentaminen PHP:n ja MariaDB:n avulla CentOS/RHEL 8/7:ään


Lighttpd on avoimen lähdekoodin, turvallinen, nopea, joustava ja paremmin optimoitu verkkopalvelin, joka on suunniteltu nopeuskriittisiin ympäristöihin, joissa on vähemmän muistia muihin verkkopalvelimiin verrattuna.

Se pystyy käsittelemään jopa 10 000 rinnakkaista yhteyttä yhdellä palvelimella tehokkaan suorittimen kuormituksen hallinnan avulla, ja siinä on edistynyt ominaisuussarja, 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 selitämme, kuinka Lighttpd asennetaan PHP:llä, PHP-FPM:llä ja MariaDB:llä verkkotunnukseen CentOS/RHEL 8/7 -jakelut isäntänimellä linux-console.net ja IP-osoitteella 192.168.0.103.

Vaihe 1: Asenna Lighttpd-verkkopalvelin

1. Asentaaksesi Lighttpd, sinun on ensin päivitettävä järjestelmäohjelmistopaketit ja käytettävissä olevat tietovarastot käyttämällä seuraavaa yum-komentoa.

yum -y update

2. Seuraavaksi sinun on otettava EPEL-varasto käyttöön 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 suorittamalla seuraavan komennon.

yum install lighttpd

4. Kun Lighttpd-paketit on asennettu, voit käynnistää palvelun ja ottaa sen käyttöön automaattisesti käynnistyksen yhteydessä ja varmistaa tilan seuraavien komentojen avulla.

systemctl start lighttpd
systemctl enable lighttpd
systemctl status lighttpd

5. Tarkista nyt järjestelmääsi asennettu Lighttpd-versio käyttämällä seuraavaa komentoa.

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

Asiakirjan Lighttpd:n oletusjuurihakemisto on /var/www/lighttpd/ ja pääasetustiedosto sijaitsee osoitteessa /etc/lighttpd/lighttpd.conf.

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

8. Asenna seuraavaksi MySQL-tuki Lighttpd:lle käyttämällä seuraavia komentoja.

yum -y install mariadb mariadb-server

9. Kun asennus on valmis, käynnistä, ota käyttöön ja tarkista MariaDB:n tila seuraavien komentojen avulla.

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 muutama eri kysymys MariaDB-asennuksestasi ja siitä, kuinka haluat suojata sen. Voit vaihtaa tietokannan pääkäyttäjän salasanan, poistaa testitietokannan käytöstä, poistaa anonyymit käyttäjät käytöstä ja poistaa pääkäyttäjän kirjautumisen käytöstä etänä.

Näytelähtö
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 tietokantapalvelimesi olemassa olevat tietokannat seuraavilla päätteen komennoilla.

mysql -u root -p
Näytelähtö
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 asentaminen FastCGI:llä CentOS 7:ään

12. Jotta voit ottaa PHP-FPM käyttöön FastCGI-tuen kanssa, sinun on ensin asennettava PHP ja tarvittavat laajennukset käyttämällä seuraavaa komentoa.

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

13. Kun PHP on asennettu, ota nyt käyttöön PHP-FPM- ja FastCGI-tuki 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äksi ja ryhmäksi 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

Myös PHP-FPM käyttää oletusarvoisesti /var/run/php/php7.0-fpm.sock -liitäntää, sinun on tehtävä PHP-FPM. käyttääksesi TCP-yhteyttä. Tee kuuntele-rivistä seuraavanlainen:

;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äynnistyksen yhteydessä seuraavien komentojen avulla.

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

Vaihe 4: Ota PHP ja PHP-FPM käyttöön FastCGI:llä Lighttpd:ssä

16. Tässä meidän on muokattava kolmea tiedostoa /etc/php.ini, /etc/lighttpd/modules.conf ja /etc/lighttpd/conf.d/fastcgi.conf ottaaksesi PHP-tuen käyttöön Lighttpd:lle.

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

vi /etc/php.ini

Poista kommentti seuraavalta riviltä, 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 seuraavalta riviltä, jossa lukee include "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 alaosaan ja tallenna se.

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

Käynnistä Lighttpd-palvelu uudelleen, jotta muutokset näkyvät ja PHP-tuki otetaan käyttöön.

systemctl restart lighttpd

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

17. Kuten yllä totesimme, Lighttpd-asiakirjan oletusjuuri on /var/www/lighttpd/. Joten tässä luomme tähän hakemistoon phpinfo.php-tiedoston.

vi /var/www/lighttpd/info.php

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

<?php
phpinfo();
?>

18. Avaa selaimesi 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 toimintatiedot sekä monet muut moduulit, jotka ovat jo käytössä.