Installazione LAMP ( Linux Apache Mysql PHP) su Ubuntu 18.04
In questo tutorial andremo ad installare passo passo l’ambiente LAMP ( Linux Apache MariaDB PHP) su Ubuntu 18.04.
Consideriamo di partire da un ambiente Ubuntu 18.04 Server ( per l’installazione leggere il seguente articolo) ed aggiorniamo la macchina virtuale
sudo apt-get update
sudo apt-get upgrade
iniziamo installando il server web
sudo apt-get install apache2
e verifichiamo tramite browser che il server web è funzionante accedendo all’ indirizzo http://ip_server/ (è possibile visualizzarlo facendo ip a s da linea di comando), avremo
successivamente installiamo il database server Mysql
sudo apt-get install mysql-server
rendiamo sicuro il database Mysql utilizzando il seguente comando
sudo mysql_secure_installation
la prima domanda è relativo al cambio password dell’utente root ( per semplicità disabilitiamo il PLUGIN delle password, ma in un ambiente di produzione conviene installare questo componente per avere password forti)
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN 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 plugin?Press y|Y for Yes, any other key for No: No
inseriamo la nuova password
New password: password_a_scelta
Re-enter new password: password_a_scelta
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.
Rimuoviamo l’utente anonimo
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.
Disabilitiamo l’accesso da remoto dell’utente root
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.
rimuoviamo il database di test
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.
eseguiamo il reload dei privilegi
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!
l’installazione del database server Mysql è terminata. Per Mysql versione 5.7 il metodo di autenticazione per l’ utente root avviene tramite linea di comando attraverso il plugin auth_socket, ma se volessimo ritornare al vecchio metodo, quindi tramite mysql_native_password, dovremmo effettuare i seguenti cambiamenti
sudo mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password_scelta_in_precedenza';
mysql> exit
Bye
adesso se provassimo ad entrare direttamente avremo il seguente errore
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
per poter entrare è necessario inserire la password
mysql -u root -p
Installiamo PHP 7.2 con tutti i moduli base per il corretto funzionamento delle pagine web dinamiche e per la connessione con il database
sudo apt-get install php libapache2-mod-php php-mysql
impostiamo il server web Apache2 ad utilizzare le pagine php
sudo vim /etc/apache2/mods-enabled/dir.conf
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
salviamo ed riavviamo il server web
sudo systemctl restart apache2
Abilitiamo all’ avvio i servizi finora
sudo systemctl enable apache2
sudo systemctl enable mysql
A questo punto verifichiamo che le pagine dinamiche php vengano renderizzate dal server web, creiamo una pagina di informazioni php
sudo vim /var/www/html/info.php
<?php
phpinfo();
?>
colleghiamoci all’indirizzo http://ip_server/info.php, avremo