Ricerca nel sito web

Come installare Lighttpd con PHP e MariaDB su CentOS/RHEL 8/7


Lighttpd è un server web open source, sicuro, veloce, flessibile e più ottimizzato progettato per ambienti critici per la velocità con un minore utilizzo della memoria rispetto ad altri server web.

Può gestire fino a 10.000 connessioni parallele in un server con un'efficace gestione del carico della CPU e viene fornito con un set di funzionalità avanzate come FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting e molto altro.

Lighttpd è un'eccellente soluzione per ogni server Linux, grazie alla sua infrastruttura io ad alta velocità che ci consente di scalare prestazioni molte volte migliori con lo stesso hardware rispetto ad altri server web alternativi.

In questo tutorial spiegheremo come installare Lighttpd con PHP, PHP-FPM, e MariaDB su distribuzioni CentOS/RHEL 8/7 con nome host linux-console.net e indirizzo IP 192.168.0.103.

Passaggio 1: installare il server Web Lighttpd

1. Per installare Lighttpd, devi prima aggiornare i pacchetti software di sistema e i repository disponibili utilizzando il seguente comando yum.

yum -y update

2. Successivamente, devi abilitare il repository EPEL sul tuo sistema e aggiornare i pacchetti software utilizzando i seguenti comandi.

yum -y install epel-release
yum -y update

3. Dopo aver abilitato il repository EPEL, ora puoi installare Lighttpd eseguendo il seguente comando.

yum install lighttpd

4. Una volta installati i pacchetti Lighttpd, puoi avviare e abilitare il servizio per l'avvio automatico all'avvio e assicurarti di verificare lo stato utilizzando i seguenti comandi.

systemctl start lighttpd
systemctl enable lighttpd
systemctl status lighttpd

5. Ora verifica la versione di Lighttpd installata sul tuo sistema utilizzando il seguente comando.

lighttpd -v

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

6. Ora devi consentire il traffico HTTP e HTTPS sul tuo firewall.

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

7. Ora apri il browser e punta al seguente URL per vedere il tuo server web Lighttpd in funzione.

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

La directory root dei documenti predefinita per Lighttpd è /var/www/lighttpd/ e il file di configurazione principale si trova in /etc/lighttpd/lighttpd.conf.

Passaggio 2: installazione di MariaDB come MySQL in CentOS 7

8. Successivamente, installa il supporto MySQL per Lighttpd utilizzando i seguenti comandi.

yum -y install mariadb mariadb-server

9. Una volta completata l'installazione, avvia, abilita e verifica lo stato di MariaDB utilizzando i seguenti comandi.

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

10. Infine, dovrai proteggere la tua installazione MariaDB emettendo il seguente comando.

mysql_secure_installation

Ti verranno poste alcune domande diverse riguardanti la tua installazione di MariaDB e come vorresti proteggerla. È possibile modificare la password dell'utente root del database, disabilitare il database di test, disabilitare gli utenti anonimi e disabilitare l'accesso root da remoto.

Uscita del campione
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. Prova a connetterti al server MySQL e rivedi i database esistenti sul tuo server database con i seguenti comandi sul terminale.

mysql -u root -p
Uscita del campione
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)]>

Passaggio 3: installazione di PHP e PHP-FPM con FastCGI su CentOS 7

12. Per abilitare PHP-FPM con il supporto FastCGI, devi prima installare PHP insieme alle estensioni necessarie utilizzando il seguente comando.

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

13. Una volta installato PHP, ora abilita il supporto PHP-FPM e FastCGI per Lighttpd , per fare ciò è necessario installare anche questi pacchetti.

yum -y install php-fpm lighttpd-fastcgi

14. Ora apri un file chiamato /etc/php-fpm.d/www.conf.

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

Imposta l'utente e il gruppo su 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

Inoltre, PHP-FPM per impostazione predefinita utilizza il socket /var/run/php/php7.0-fpm.sock, devi creare PHP-FPM per utilizzare una connessione TCP. Rendi la riga listen come segue:

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

15. Ora avvia il servizio PHP-FPM e assicurati di abilitarlo per l'avvio automatico all'avvio utilizzando i seguenti comandi.

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

Passaggio 4: abilitare PHP e PHP-FPM con FastCGI in Lighttpd

16. Qui dobbiamo modificare tre file /etc/php.ini, /etc/lighttpd/modules.conf e /etc/lighttpd/conf.d/fastcgi.conf per abilitare il supporto PHP per Lighttpd.

Apri il primo file /etc/php.ini.

vi /etc/php.ini

Decommenta la seguente riga che dice line 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

Quindi apri il secondo file chiamato /etc/lighttpd/modules.conf.

vi /etc/lighttpd/modules.conf

Decommentare la seguente riga che dice include "conf.d/fastcgi.conf".

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

Successivamente, apri il terzo file chiamato /etc/lighttpd/conf.d/fastcgi.conf.

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

Ora aggiungi il seguente contenitore nella parte inferiore del file e salvalo.

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

Riavvia il servizio Lighttpd per riflettere le modifiche e abilitare il supporto PHP.

systemctl restart lighttpd

Passaggio 5: testare PHP e PHP-FPM con supporto FastCGI in Lighttpd

17. Come abbiamo detto sopra, la radice del documento predefinita per Lighttpd è /var/www/lighttpd/. Quindi, qui creeremo un file phpinfo.php in questa directory.

vi /var/www/lighttpd/info.php

Aggiungi le seguenti righe. Questo piccolo pezzo di codice mostrerà le informazioni sull'installazione di PHP con le relative versioni.

<?php
phpinfo();
?>

18. Apri il browser e vai ai seguenti link.

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

Vedrai le informazioni di funzionamento di PHP, PHP-FPM e MySQL con molti altri moduli già abilitati.