Installazione di LAMP su CentOS 6.9

In questo articolo seguiremo passo passo l’installazione dell’ambiente LAMP (Linux-Apache-Mysql-PHP), partendo da una macchina CentOS 6.9 minimal.

Partiamo da un ambiente in cui è presente una scheda di rete collegata su internet e portiamo il sistema ad una situazione stabile, aggiornando tutti i pacchetti del sistema:

sudo yum update

Installiamo il web server HTTPD:

sudo yum install httpd vim

e inseriamo le seguenti impostazioni in modo che il web server Httpd parta  in automatico all’avvio (di default runlevel 2,3,4,5)

sudo chkconfig httpd on

sudo service httpd start

A questo punto  installiamo il database Mysql

sudo yum install mysql-server
sudo chkconfig mysqld on
sudo service mysqld start

Al primo startup di Mysql, verranno richieste alcune operazioni da eseguire; qui un esempio di output:

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password ‘new-password’
/usr/bin/mysqladmin -u root -h localhost.localdomain password ‘new-password’

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

Impostiamo la password di root di Mysql:

sudo /usr/bin/mysqladmin -u root password 'new-password'

al posto di new-password, inseririamo la password da noi scelta. Quindi effettuiamo il test di accesso:

sudo mysql -u root -p

Una volta inserita la nostra password, avremo il seguente output:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, 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>

A questo punto rendiamo sicuro Mysql con il seguente comando:

sudo /usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, 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):

Inseriamo la password precedentemente impostata

You already have a root password set, so you can safely answer ‘n’.

Change the root password? [Y/n]

Il sistema ci chiederà se vogliamo cambiare la password di root, perciò facciamo n e invio

Remove anonymous users? [Y/n]

mentre quando ci chiede se vogliamo rimuovere utenti anonimi e facciamo y e invio

Disallow root login remotely? [Y/n]

Al momento non permettiamo collegamenti remoti con root (phpmyadmin è permesso, workbench sql no), perciò facciamo n e invio

Remove test database and access to it? [Y/n]

Permettiamo la rimozione del database test e quindi fare y e invio

Reload privilege tables now? [Y/n]

così come i reload dei privilegi , quindi y e invio.

All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Per un’ installazione senza particolari vincoli di hardening a livello di sistema operativo è possibile disabilitare sia il tool selinux che iptables (di solito le aziende usano firewall esterni al sistema operativo, per bloccare le porte in ingresso e in uscita):

vim /etc/selinux/config

Modificare il seguente file di configurazione di selinux, da SELINUX=enforcing a SELINUX=DISABLED

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing – SELinux security policy is enforced.
# permissive – SELinux prints warnings instead of enforcing.
# disabled – No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted – Targeted processes are protected,
# mls – Multi Level Security protection.
SELINUXTYPE=targeted

sudo setenforce 0

sudo service iptables stop

sudo service ip6tables stop

sudo chkconfig iptables off

sudo chkconfig ip6tables off

Installiamo il linguaggio PHP

sudo yum install php php-mysql

Verifichiamo che lo stack LAMP funzioni correttamente visitando da un qualsiasi web browser http://ip_server

lamp centos 6 9

mentre per verificare che anche vengo lette le pagine dinamiche PHP,  creiamo una pagina di esempio

vim /var/www/html/info.php

<?php

phpinfo();

?>

modifichiamo la configurazione del server web

vim /etc/httpd/conf/httpd.conf

ed aggiungiamo alla direttiva DirectoryIndex index.php

DirectoryIndex index.php index.html index.html.var

visitiamo il seguente indirizzo http://ip_server/info.php ed avremo

lamp centos 6 9

installazione terminata.

 

Potrebbero interessarti anche...

Lascia un commento

Il tuo indirizzo email non sarà pubblicato.

Utilizzando il sito, accetti l'utilizzo dei cookie da parte nostra. maggiori informazioni

Questo sito utilizza i cookie per fornire la migliore esperienza di navigazione possibile. Continuando a utilizzare questo sito senza modificare le impostazioni dei cookie o cliccando su "Accetta" permetti il loro utilizzo.

Chiudi