Kā instalēt Lighttpd ar PHP un MariaDB uz CentOS/RHEL 8/7


Lighttpd ir atvērtā koda, drošs, ātrs, elastīgs un optimizētāks tīmekļa serveris, kas paredzēts ātruma kritiskai videi ar mazāku atmiņas izmantošanu salīdzinājumā ar citiem tīmekļa serveriem.

Tas spēj apstrādāt līdz pat 10 000 savienojumu paralēli vienā serverī ar efektīvu procesora slodzes pārvaldību, un tam ir papildu funkciju kopums, piemēram, FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting un daudz kas cits.

Lighttpd ir lielisks risinājums katram Linux serverim, pateicoties tā ātrgaitas io-infrastruktūrai, kas ļauj mums vairākas reizes uzlabot veiktspēju ar to pašu aparatūru nekā ar citiem alternatīviem tīmekļa serveriem.

Šajā apmācībā mēs paskaidrosim, kā instalēt Lighttpd ar PHP, PHP-FPM un MariaDB CentOS/RHEL 8/7 izplatījumos ar resursdatora nosaukumu linux-console.net un IP adresi 192.168.0.103.

1. darbība: instalējiet Lighttpd tīmekļa serveri

1. Lai instalētu Lighttpd, vispirms jāatjaunina sistēmas programmatūras pakotnes un pieejamie krātuves, izmantojot šādu komandu yum.

# yum -y update

2. Pēc tam jūsu sistēmā jāiespējo EPEL repozitorijs un jāatjaunina programmatūras pakotnes, izmantojot šādas komandas.

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

3. Kad esat iespējojis EPEL repozitoriju, tagad varat instalēt Lighttpd, izpildot šo komandu.

# yum install lighttpd

4. Kad Lighttpd pakotnes ir instalētas, varat sākt un iespējot pakalpojumu automātiski startēt sāknēšanas laikā un pārliecināties, vai esat pārbaudījis statusu, izmantojot šādas komandas.

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

5. Tagad pārbaudiet sistēmā instalēto Lighttpd versiju, izmantojot šādu komandu.

# lighttpd -v

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

6. Tagad ugunsmūrī ir jāļauj atļaut HTTP un HTTPS datplūsma.

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

7. Tagad atveriet pārlūkprogrammu un norādiet uz šo URL, lai redzētu, kā darbojas jūsu Lighttpd tīmekļa serveris.

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

Noklusējuma dokumenta saknes direktorijs Lighttpd ir/var/www/lighttpd /, un galvenais konfigurācijas fails atrodas zem /etc/lighttpd/lighttpd.conf.

2. darbība: MariaDB kā MySQL instalēšana CentOS 7

8. Pēc tam instalējiet MySQL atbalstu Lighttpd, izmantojot šādas komandas.

# yum -y install mariadb mariadb-server

9. Kad instalēšana ir pabeigta, sāciet, iespējojiet un pārbaudiet MariaDB statusu, izmantojot šādas komandas.

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

10. Visbeidzot, jums būs jānodrošina sava MariaDB instalācija, izsniedzot šādu komandu.

# mysql_secure_installation

Jums tiks piedāvāti daži dažādi jautājumi par jūsu MariaDB instalēšanu un to, kā vēlaties to nodrošināt. Jūs varat mainīt datu bāzes saknes lietotāja paroli, atspējot testa datu bāzi, atspējot anonīmus lietotājus un attāli atspējot root pieteikšanos.

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. Mēģiniet izveidot savienojumu ar MySQL serveri un pārskatiet esošās datu bāzes servera datu bāzes, izmantojot šādas komandas terminālā.

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

3. solis: PHP un PHP-FPM ar FastCGI instalēšana CentOS 7

12. Lai iespējotu PHP-FPM ar FastCGI atbalstu, vispirms jāinstalē PHP kopā ar nepieciešamajiem paplašinājumiem, izmantojot šo komandu.

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

13. Kad PHP ir instalēts, tagad iespējojiet PHP-FPM un FastCGI atbalstu Lighttpd, lai to izdarītu, jums jāinstalē arī šīs paketes.

# yum -y install php-fpm lighttpd-fastcgi

14. Tagad atveriet failu ar nosaukumu /etc/php-fpm.d/www.conf.

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

Iestatiet lietotāju un grupu uz 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

Arī PHP-FPM pēc noklusējuma izmanto /var/run/php/php7.0-fpm.sock ligzdu, lai izveidotu TCP savienojumu, jums jāizveido PHP-FPM. Līnijai klausīties izskatieties šādi:

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

15. Tagad sāciet pakalpojumu PHP-FPM un pārliecinieties, vai tas ļauj automātiski startēt sāknēšanas laikā, izmantojot šādas komandas.

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

4. darbība: PHP un PHP-FPM iespējošana ar FastCGI programmā Lighttpd

16. Šeit mums ir jāpārveido trīs faili /etc/php.ini, /etc/lighttpd/modules.conf un /etc/lighttpd/conf.d/fastcgi.conf, lai iespējotu PHP atbalstu Lighttpd.

Atveriet pirmo failu /etc/php.ini.

# vi /etc/php.ini

Noņemiet komentāru šajā rindā, kurā teikts: 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

Pēc tam atveriet otro failu ar nosaukumu /etc/lighttpd/modules.conf.

# vi /etc/lighttpd/modules.conf

Noņemiet komentāru šajā rindā, kurā teikts “conf.d/fastcgi.conf”.

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

Pēc tam atveriet trešo failu ar nosaukumu /etc/lighttpd/conf.d/fastcgi.conf.

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

Tagad faila apakšdaļā pievienojiet šādu konteineru un saglabājiet to.

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

Restartējiet Lighttpd pakalpojumu, lai atspoguļotu izmaiņas un iespējotu PHP atbalstu.

# systemctl restart lighttpd

5. darbība: PHP un PHP-FPM pārbaude ar FastCGI atbalstu Lighttpd

17. Kā mēs teicām iepriekš, noklusējuma dokumenta sakne Lighttpd ir/var/www/lighttpd /. Tātad, šeit mēs izveidosim phpinfo.php failu šajā direktorijā.

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

Pievienojiet tai šādas rindas. Šajā nelielajā koda fragmentā tiks parādīta informācija par PHP instalēšanu ar to versijām.

<?php
phpinfo();
?>

18. Atveriet pārlūkprogrammu un dodieties uz šīm saitēm.

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

Jūs redzēsiet PHP, PHP-FPM un MySQL darba informāciju ar daudziem citiem jau iespējotiem moduļiem.