Giunsa ang Pag-install sa Lighttpd sa PHP ug MariaDB sa CentOS/RHEL 8/7


Ang Lighttpd usa ka open-source, luwas, paspas, flexible, ug mas optimized nga web server nga gidisenyo para sa speed-critical environment nga gamay ra ang memory utilization kon itandi sa ubang web servers.

Makadumala kini hangtod sa 10,000 ka koneksyon nga managsama sa usa ka server nga adunay epektibo nga pagdumala sa pagkarga sa CPU ug adunay usa ka advanced nga set nga bahin sama sa FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting ug daghan pa.

Ang Lighttpd usa ka maayo kaayo nga solusyon alang sa matag server sa Linux, tungod sa iyang high-speed io-infrastructure nga nagtugot kanamo sa pag-scale sa daghang beses nga mas maayo nga performance sa parehas nga hardware kaysa sa ubang mga alternatibong web-server.

Sa kini nga panudlo, among ipasabut kung giunsa ang pag-install sa Lighttpd nga adunay PHP, PHP-FPM, ug MariaDB sa mga distribusyon sa CentOS/RHEL 8/7 nga adunay hostname linux-console.net ug IP address 192.168.0.103.

Lakang 1: I-install ang Lighttpd Web Server

1. Aron ma-install ang Lighttpd, una, kinahanglan nimo nga i-update ang imong mga pakete sa software sa sistema ug magamit nga mga repository gamit ang mosunod nga yum command.

# yum -y update

2. Sunod, kinahanglan nimo nga i-enable ang EPEL repository sa imong system ug i-update ang software packages gamit ang mosunod nga mga command.

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

3. Sa higayon nga imong ma-enable ang EPEL repository, mahimo nimong i-install ang Lighttpd pinaagi sa pagpadagan sa mosunod nga command.

# yum install lighttpd

4. Sa higayon nga ma-install ang Lighttpd packages, mahimo nimong sugdan ug mahimo ang serbisyo nga awtomatikong magsugod sa oras sa pag-boot ug siguroha nga mapamatud-an ang status gamit ang mosunod nga mga sugo.

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

5. Karon pamatud-i ang bersyon sa Lighttpd nga na-install sa imong sistema gamit ang mosunod nga sugo.

# lighttpd -v

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

6. Karon kinahanglan nimong tugutan ang trapiko sa HTTP ug HTTPS sa imong firewall.

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

7. Karon ablihi ang imong browser ug itudlo ang mosunod nga URL aron makita ang imong Lighttpd webserver nga nagtrabaho.

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

Ang default nga direktoryo sa gamut nga dokumento alang sa Lighttpd mao ang /var/www/lighttpd/ ug ang nag-unang configuration file nahimutang ubos sa /etc/lighttpd/lighttpd.conf.

Lakang 2: Pag-instalar sa MariaDB isip MySQL sa CentOS 7

8. Sunod, i-install ang suporta sa MySQL para sa Lighttpd gamit ang mosunod nga mga sugo.

# yum -y install mariadb mariadb-server

9. Kung kompleto na ang instalasyon, sugdi, pagana, ug pamatud-i ang kahimtang sa MariaDB gamit ang mosunod nga mga sugo.

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

10. Sa katapusan, kinahanglan nimo nga masiguro ang imong pag-instalar sa MariaDB pinaagi sa pag-isyu sa mosunod nga sugo.

# mysql_secure_installation

Maaghat ka sa pipila ka lainlaing mga pangutana bahin sa imong pag-install sa MariaDB ug kung giunsa nimo gusto nga ma-secure kini. Mahimo nimong usbon ang password sa root user sa database, pag-disable sa database sa pagsulay, pag-disable sa mga anonymous nga tiggamit, ug pag-disable sa root login sa layo.

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. Sulayi ang pagkonektar sa MySQL server ug ribyuha ang kasamtangan nga mga database sa imong database server gamit ang mosunod nga mga sugo sa terminal.

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

Lakang 3: Pag-instalar sa PHP ug PHP-FPM sa FastCGI sa CentOS 7

12. Aron mahimo ang PHP-FPM nga adunay suporta sa FastCGI, una, kinahanglan nimo nga i-install ang PHP kauban ang kinahanglan nga mga extension gamit ang mosunod nga mando.

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

13. Sa higayon nga ma-install ang PHP, mahimo na karon ang suporta sa PHP-FPM ug FastCGI alang sa Lighttpd, aron mahimo kini kinahanglan nimo nga i-install usab kini nga mga pakete.

# yum -y install php-fpm lighttpd-fastcgi

14. Karon ablihi ang file nga gitawag og /etc/php-fpm.d/www.conf.

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

Ibutang ang user ug grupo sa 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

Usab, ang PHP-FPM pinaagi sa default naggamit sa /var/run/php/php7.0-fpm.sock socket, kinahanglan nimo nga maghimo PHP-FPM aron magamit ang koneksyon sa TCP. Himoa nga ang linya nga paminaw ingon sa mosunod:

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

15. Karon sugdi ang PHP-FPM nga serbisyo ug siguruha nga kini awtomatik nga magsugod sa oras sa pag-boot gamit ang mosunod nga mga sugo.

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

Lakang 4: Pag-enable sa PHP ug PHP-FPM sa FastCGI sa Lighttpd

16. Dinhi, kinahanglan natong usbon ang tulo ka mga file /etc/php.ini, /etc/lighttpd/modules.conf ug /etc/lighttpd/conf.d/fastcgi.conf aron mahimo ang suporta sa PHP alang sa Lighttpd.

Ablihi ang unang file /etc/php.ini.

# vi /etc/php.ini

Un-comment ang mosunod nga linya nga nag-ingon nga linya 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

Dayon ablihi ang ikaduhang file nga gitawag og /etc/lighttpd/modules.conf.

# vi /etc/lighttpd/modules.conf

I-un-comment ang mosunod nga linya nga nag-ingon nga naglakip sa conf.d/fastcgi.conf.

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

Sunod, ablihi ang ikatulo nga payl nga gitawag og /etc/lighttpd/conf.d/fastcgi.conf.

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

Karon idugang ang mosunod nga sudlanan sa ubos sa file ug i-save kini.

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

I-restart ang serbisyo sa Lighttpd aron mapakita ang mga pagbag-o ug mahimo ang suporta sa PHP.

# systemctl restart lighttpd

Lakang 5: Pagsulay sa PHP ug PHP-FPM nga adunay Suporta sa FastCGI sa Lighttpd

17. Sama sa among giingon sa ibabaw nga ang default nga dokumento nga gamut alang sa Lighttpd mao ang /var/www/lighttpd/. Busa, dinhi kita maghimo ug phpinfo.php file ngadto niini nga direktoryo.

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

Idugang ang mosunod nga mga linya niini. Kining gamay nga piraso sa code magpakita sa impormasyon bahin sa pag-instalar sa PHP uban sa ilang mga bersyon.

<?php
phpinfo();
?>

18. Ablihi ang imong browser ug navigate sa mosunod nga mga link.

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

Makita nimo ang nagtrabaho nga impormasyon sa PHP, PHP-FPM, ug MySQL nga adunay daghang uban pang mga modulo nga nahimo na.