Installazione ambiente LAMP (Linux Apache Mysql PHP) su Ubuntu 16.04

In questo tutorial andremo ad installare l’ambiente LAMP (Linux Apache MySQL PHP) su Ubuntu Server 16.04 LTS.

Consideriamo di partire da un sistema Ubuntu Server 16.04 (per l’installazione leggere l’articolo qui) e procediamo all’installazione dell’ ambiente LAMP (Linux Apache Mysql Php).

Partiamo dall’installazione del Web server Apache 2:

sudo apt-get update

sudo apt-get install apache2

verifichiamo che la configurazione del web server sia corretta, innanzitutto attraverso il comando

sudo apache2ctl configtest

dovremo avere questo output

AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message
Syntax OK

l’eccezione (AH00558) sollevata dalla configurazione è dovuta al fatto di non aver impostato  il Server Name globale ( l’impostazione è da inserire nel file /etc/apache2/apache2.conf, aggiungendo la direttiva ServerName ip_server_o_dominio ), ma la sintassi come è possibile notare è OK.  Un’ ulteriore riscontro è l’accesso diretto tramite url (porta standard 80):

http://ip_server_ubuntu/

dovremo avere il seguente risultato

Procediamo con l’ installazione del database server Mysql

sudo apt-get install mysql-server

durante la fase d’installazione verrà richiesta la password dell’utente principale root, dovremo inserirla per due volte. Il file di configurazione principale di Mysql è presente al seguente percorso:

/etc/mysql/my.cnf

quest’ultimo è stato creato con impostazioni standard. Rendiamo il Mysql sicuro seguendo la procedura guidata dettata dal comando:

mysql_secure_installation

come output avremo

Securing the MySQL server deployment.

Enter password for user root:Yes

andremo ad impostare la password inserita in fase d’installazione

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

nella precedente schermata ci viene richiesta la volontà di installare il plugin di validazione della password, ma per semplicità metteremo No. Ci viene chiesta successivamente il cambio password di root

Change the password for root ? ((Press y|Y for Yes, any other key for No) : No

eliminiamo utenti anonimi

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) : Yes

Success

non permettiamo di collegarsi da remoto con root

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) : Yes

Success.

eliminiamo il database di test

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) : Yes
– Dropping test database…
Success.

– Removing privileges on test database…
Success.

ricarichiamo i privilegi con le nuove impostazioni

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) : Yes
Success.

All done!

A questo punto abbiamo terminato l’installazione e la messa a punto del database Mysql.

Installiamo il linguaggio PHP con i suoi moduli:

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

WordPress è un sito web costruito prevalentemente in php, il file contattato dal web server Apache è index.php e non index.html, quindi per far sì che questo accada dovremo modificare le configurazioni di default del file dir.conf, in particolare:

sudo vim /etc/apache2/mods-enabled/dir.conf

modifichiamolo mettendo in prima posizione index.php, in questo modo

<IfModule mod_dir.c>
          DirectoryIndex index.php index.cgi index.pl index.html index.xhtml index.htm
</IfModule>

quindi riavviamo apache2

sudo systemctl restart apache2

Controlliamo che il tutto funzioni correttamente creando il noto file info.php nella directory di dafault di Apache2:

sudo vim /var/www/html/info.php

con il seguente codice (cat /var/www/html/info.php):

<?php
phpinfo();
?>

accedendo all’indirizzo http//indirizzo_server_ubuntu/info.php avremo:

L’installazione dell’ambiente LAMP su Ubuntu 16 è finita.

Potrebbero interessarti anche...