Contexte :
Nous partirons d’un système de base sous CentOS 6 installé.
Nous allons installer une stack Linux (E)nginx (nginx est prononcé engine X) Mysql Php.
Installation :
MySQL :
$ sudo yum - y install mysql - server
mysql_install_db
WARNING : The host 'templatex64.alasta.com' could not be looked up with resolveip .
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version . The MySQL daemon , mysqld , should work
normally with the exception that host name resolving will not work .
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables ...
OK
Filling help tables ...
OK
To start mysqld at boot time you have to copy
support - files / mysql . server to the right place for your system
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 templatex64 . alasta . com 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 ; /us r / bin / mysqld_safe &
You can test the MySQL daemon with mysql - test - run . pl
cd /usr/m ysql - test ; perl mysql - test - run . pl
Please report any problems with the /usr/ bin / mysqlbug script!
20 : 55 root @templatex64 ~ # service mysqld start
Démarrage de mysqld : [ OK ]
20 : 55 root @templatex64 ~ # /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):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
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? [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, 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? [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 MySQL
installation should now be secure .
Thanks for using MySQL !
$ sudo chkconfig -- level 2345 mysqld on
nginx
Ajouter le fichier de repository nginx /etc/yum.repos.d/nginx.repo
[ nginx ]
name = nginx repo
baseurl = http :/ / nginx . org / packages / centos / $releasever / $basearch /
gpgcheck = 0
enabled = 1
$ sudo yum - y install nginx
$ sudo service nginx start
$ sudo chkconfig -- level 2345 nginx on
php
$ sudo yum - y install php - common php - fpm php - mysql
$ sudo service php - fpm start
Configuration :
nginx
Edition du fichier de d’origine /etc/nginx/conf.d/default.conf
server {
listen 80 ;
server_name localhost ;
location / {
root /usr/s hare / nginx / html ;
index index . php index . html index . htm ;
}
error_page 500 502 503 504 / 50 x . html ;
location = /50x.html {
root /us r / share / nginx / html ;
}
location ~ \. php $ {
fastcgi_pass 127.0 . 0.1 : 9000 ;
fastcgi_index index . php ;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /usr/s hare / nginx / html $fastcgi_script_name ;
include fastcgi_params ;
}
}
Note : la directive fastcgi_param par défaut ne fonctionne pas (no $document_root qui indique /etc/nginx/html/ …), j’ai du forcer le path de root !
Redémarrer nginx
$ sudo service nginx restart
page de test
$ sudo echo '<?php phpinfo(); ?>'
Test :
$ curl http :/ / www . alasta . lab
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd" >
< html >< head >
< style type = "text/css" >
body { background - color: #ffffff; color: #000000;}
body , td , th , h1 , h2 { font - family: sans - serif ;}
pre { margin: 0 px ; font - family: monospace ;}
a :link { color: #000099; text-decoration: none; back
-- SNiP --
Bonus :
Masquer la version nginx
Avant
$ $ curl - I www . alasta . lab
HTTP / 1.1 200 OK
Server : nginx / 1.8 . 0
Date : Sun , 19 Jul 2015 20 : 02 : 28 GMT
Content - Type : text / html
Connection : keep - alive
X - Powered - By : PHP / 5.3 . 3
Modification
Ajouter dans /etc/nginx/nginx.conf la ligne suivante dans la section http :
server_tokens off ;
Redémarrage de nginx
$ sudo service nginx restart
Après
$ curl - I www . alasta . lab
HTTP / 1.1 200 OK
Server : nginx
Date : Sun , 19 Jul 2015 20 : 02 : 28 GMT
Content - Type : text / html
Connection : keep - alive
X - Powered - By : PHP / 5.3 . 3
Masquer la version de php
Modification
Dans le curl précédent on voit bien que la version de php est affichée, pour pallier à cela il suit de passer la directive expose_php à off dans /etc/php.ini
; Decides whether PHP may expose the fact that it is installed on the server
; ( e . g . by adding its signature to the Web server header ) . It is no security
; threat in any way , but it makes it possible to determine whether you use PHP
; on your server or not .
; http :/ / www . php . net / manual / en / ini . core . php #ini.expose-php
; expose_php = On
expose_php = Off
$ sudo service php - fpm restart
Après
$ curl - I www . alasta . lab
HTTP / 1.1 200 OK
Server : nginx
Date : Sun , 19 Jul 2015 20 : 07 : 39 GMT
Content - Type : text / html
Connection : keep - alive