LAMP è l'acronimo di Linux Apache MySQL PHP; si tratta
di un gruppo di software Open source che vengono generalmente installati insieme.
In questa breve tutorial installeremo questo insieme di software Open Source su un ambiente Linux ma,
il tutto, è possibile farlo anche in ambiente Windows e MAC OS X; la progedura sarà leggermente
di versa ma il risultato è identico.
Lo scopo di questo Stack Open Source è quella di consentire ad un server (nel mio caso una macchina
virtuale) di ospitare applicazioni web.
Procediamo ad effettuare un aggiorna la lista dei pacchetti contenuti nei repositorydi Ubuntu e poi ad installare il pacchetto apache2
# sudo apt-get update # sudo apt-get install -y apache2
con il comando :
# sudo apt list --upgradable
ci viene restituita una lista dei pacchetti per cui è disponibile un aggiornamento.
Ad esempio :
... ubuntu-standard/focal-updates 1.450.2 amd64 [upgradable from: 1.450.1] udev/focal-updates 245.4-4ubuntu3.3 amd64 [upgradable from: 245.4-4ubuntu3.2] unattended-upgrades/focal-updates 2.3ubuntu0.1 all [upgradable from: 2.3] util-linux/focal-updates 2.34-0.1ubuntu9.1 amd64 [upgradable from: 2.34-0.1ubuntu9] uuid-runtime/focal-updates 2.34-0.1ubuntu9.1 amd64 [upgradable from: 2.34-0.1ubuntu9] wireless-regdb/focal-updates,focal-security 2020.11.20-0ubuntu1~20.04.1 all [upgradable from: 2018.05.09-0ubuntu1] xz-utils/focal-updates 5.2.4-1ubuntu1 amd64 [upgradable from: 5.2.4-1] zlib1g/focal-updates 1:1.2.11.dfsg-2ubuntu1.2 amd64 [upgradable from: 1:1.2.11.dfsg-2ubuntu1]
Il vero aggiornamento del sistema lo facciamo con il comando :
# sudo apt-get upgrade
Continuiamo con l'installazione di Apache.
In genere, prima di eseguire l'installazione di Apache la situazione del firewall
di Ubuntu dovrebbe essere simile alla seguente :
# sudo ufw app list Available applications: OpenSSH
subito dopo aver terminato l'installazione del pacchetto apache2, la situazione del firewall dovrebbe essere diventata simile alla seguente :
# sudo ufw app list Available applications: Apache Apache Full Apache Secure OpenSSH
Nel dettaglio, abbiamo :
Apache: Questo profilo apre solo la porta 80 (normal, unencrypted web traffic).
Apache Full: Questo profilo apre entrambe ler porte; la porta 80
(normal, unencrypted web traffic) e la porta (TLS/SSL encrypted traffic).
Apache Secure: Questo profilo apre solo la porta 443 (TLS/SSL encrypted traffic).
se così non fosse, basta aggiungere l'Apache alla lista con il seguente comando :
# sudo ufw allow in "Apache"
Nel mio caso, per comodità, dato che si tratta di un server di test, il firewall è disabilitato :
# sudo ufw status Status: inactive
Quello che ci rimane da fare adesso, è verificare che l'Apache si stato installato correttamente.
Questo lo possiamo verificare semplicemente aprendo un browser e inserendo l'indirizzo ip del nostro server.
Recuperiamo l'ip del server :
# ifconfig -a ... enp0s3: flags=4163mtu 1500 inet 192.168.1.106 netmask 255.255.255.0 broadcast 192.168.1.255 ...
Incolliamo nel browser :
La parte di Apache è completata.
Per l'installazione di MySQL, procediamo nel seguente modo :
# sudo apt-get install mysql-server -y
Al termine dell'installazione si consiglia di eseguire uno script, già presente in MySQL, per
la sicurezza.
Quello che dobbiamo fare è rimuovere alcune impostazioni predefinite non sicure e procedere
al blocco dell'accesso al Database.
# sudo mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 50 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y Success. All done!
Verifichiamo di essere abilitati ad accedere al MySQL :
# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.22-0ubuntu0.20.04.3 (Ubuntu) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> # sudo mysql mysql> mysql> SELECT user,authentication_string,plugin,host FROM mysql.user; +------------------+------------------------------------------------------------------------+-----------------------+-----------+ | user | authentication_string | plugin | host | +------------------+------------------------------------------------------------------------+-----------------------+-----------+ ..... | root | | auth_socket | localhost | +------------------+------------------------------------------------------------------------+-----------------------+-----------+ 5 rows in set (0.00 sec) mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; mysql> FLUSH PRIVILEGES; mysql> SELECT user,authentication_string,plugin,host FROM mysql.user; +------------------+------------------------------------------------------------------------+-----------------------+-----------+ | user | authentication_string | plugin | host | +------------------+------------------------------------------------------------------------+-----------------------+-----------+ ...... | root | *B167DCB9AFAE1FA2F6938C2B839BF9067782D49C | mysql_native_password | localhost | +------------------+------------------------------------------------------------------------+-----------------------+-----------+ 5 rows in set (0.00 sec)In questo modo abbiamo configurato la password per l'account di root
usciamo
mysql> exit
Procediamo all'installazione di PHP.
Eseguiamo il seguente comando :
# sudo apt-get install -y php libapache2-mod-php php-mysql
Vediamo che versione di php è stata installata :
# php -v PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
Volendo fare un'ulteriore verifica, possiamo mettere nella DocumentRoot di Apache (/var/www/html) un file index.php con dentro la seguente istruzione :
e poi procediamo come abbiamo fatto prima per verificare il corretto funzionamento di Apache, copiamo
l'ip del server nel browser.
dovremmo ottenere una pagina tipo la seguente :