-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration_Web
Responsable : Simon Kinet
Statut de l'étape : Validé
Dans un premier on crée WEB puis ensuite Web-dmz et enfin Db
mdkir WEB
cd WEB
mkdir Db
mkdir Web-dmz
version: "3.3"
services:
web-dmz:
build:
context: ./Web-dmz
dockerfile: Dockerfile
ports:
- "80:80"
- "443:443"
volumes:
- ./Web-dmz/www/:/var/www/
- ./Web-dmz/sites-available/:/etc/apache2/sites-available/
- ./Web-dmz/apache2.conf:/etc/apache2/apache2.conf
container_name: web-dmz
database:
build:
context: ./Db
dockerfile: Dockerfile
command: --default-authentication-plugin=mysql_native_password
ports:
- "5000:3306"
volumes:
- ./Db/sql/:/data/
environment:
MYSQL_ROOT_PASSWORD: admin
container_name: mysql-db
Dans Web-dmz on retrouve le Dockerfile.
FROM romeoz/docker-apache-php
# Installez quelques outils utiles pour le débogage
RUN apt-get update && apt full-upgrade -y \
&& apt-get install nano -y
# Ajoutez les fichiers nécessaires au serveur apache pour initialiser tous les hôtes virtuels.
ADD ./www/ /var/www/
ADD ./sites-available/ /etc/apache2/sites-available/
# Encryption port 443 configuration files
RUN apt-get install -y software-properties-common
RUN apt-get install -y python3-certbot-apache
# Fichiers de configuration pour le chiffrement du port 443 et des erreurs.
COPY apache2.conf /etc/apache2/apache2.conf
# Activez les Virtulhosts. (avoir plusieurs site dans un même serveur)
# ADD NEW VirtualHosts HERE !
RUN a2ensite b2b.conf
RUN a2ensite www.conf
# Redémarrez le service apache pour "activer" les hôtes virtuels
RUN service apache2 reload
# activer le HTTPS
RUN a2enmod ssl
RUN service apache2 restart
# certbot --apache
WORKDIR /var/www/
mkdir /var/www/b2b
touch /var/www/b2b/index.php
touch /var/www/index.html
<?php
$mysqli = new mysqli("176.96.231.209:5000",'root','admin','woodytoys_db');
// Check connection
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
?>
<html>
<head>
</head>
<body>
<h1>Bienvenu sur le site B2B (revendeurs) de WoodyToys m1-5 !</h1>
<?php
$query = "SELECT * FROM toys;";
mysqli_query($mysqli, $query) or die('Error querying database.');
$result = mysqli_query($mysqli, $query);
while ($row = mysqli_fetch_array($result)) {
echo $row['id_toys'] . ': ' . $row['toyName'] . ' ' . $row['toyPrice'] . ' <br />';
}
?>
</body>
</html>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WoodyToys m1-5</title>
</head>
<body>
<h1>Bienvenue sur le site vitrine de WoodyToys m1-5 !</h1>
</body>
</html>
cd /etc/apache2/sites-available
touch b2b.conf
touch www.conf
<VirtualHost *:80>
ServerAdmin s.kinet@students.ephec.be
ServerName b2b.m1-5.ephec-ti.be
DocumentRoot /var/www/b2b/
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /var/www/b2b/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin s.kinet@students.ephec.be
ServerName www.m1-5.ephec-ti.be
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
cd /etc/apache2/sites-available
a2ensite b2b.conf
a2ensite www.conf
service apache2 reload
Dans le dossier Db il y a :
- un DockerFile
- un dossier "init_db"
Dans le dossier Db, on retrouve le Dockerfile.
FROM mysql:latest
# .sh, .sql, .. files in the docker-entrypoint-initdb.d directory
# will be executed by the root user when the container is started.
COPY ./init_db/ /docker-entrypoint-initdb.d/
CREATE USER 'woody_admin'@'176.96.231.209' IDENTIFIED BY 'admin';
CREATE USER 'woody_admin' IDENTIFIED BY 'admin';
CREATE DATABASE woodytoys_db;
GRANT ALL PRIVILEGES ON woodytoys_db.* TO 'woody_admin'@'176.96.231.209';
GRANT ALL PRIVILEGES ON woodytoys_db.* TO 'woody_admin';
USE woodytoys_db;
CREATE TABLE toys(
id_toys INTEGER NOT NULL AUTO_INCREMENT,
toyName CHAR(50) NOT NULL,
toyPrice DECIMAL(8,2) NOT NULL,
CONSTRAINT pk_toys PRIMARY KEY(id_toys)
);
INSERT INTO toys (toyName,toyPrice)
VALUES ('White Horse',32.19),
('Ukulele',59.99),
('Train locomotive',128.49);
docker build
docker-compose up -d
docker-compose down
docker stop conteneur id
docker ps
docker exec -ti (container id db) /ban/bash
mysql -u root -p
Password : admin
USE woodytoys_db;
SELECT * from toys;
Le dossier WEB_Public est divisé en db et Web-dmz. dans db on retrouve son Dockerfile ainsi que dans un sous-dossier le "sql.db".
Dans le dossier principal on retrouve le docker-compose.yml. Dans Web-dmz on retrouve le Dockerfile, ainsi que "apache2.conf". Dans sites-available on retrouve "b2b.conf" et "www.conf" qui sont les fichiers de config pour les virtuals hosts. Dans un deuxième temps dans Web-dmz on retrouve un dossier www suivi de "index.html" qui est le site statique. A côté de cela il y a b2b avec "index.php" qui est le site dynamique.
Il y a évidemment une liason avec le DNS pour faire fonctionner le site.
Vous pouvez le résultat de la configuration sur le repository dans le WEB_Public.
Les sites sont accessibles aux adresses :