Browse Source

first commit

master
BARRAUX Arthur 2 years ago
commit
c366134929
  1. 36
      docker-compose.yaml
  2. 4
      php/Dockerfile
  3. 27
      php/src/index.php

36
docker-compose.yaml

@ -0,0 +1,36 @@
version: '3.8'
services:
php-apache-environment:
container_name: php-apache
build:
context: ./php
dockerfile: Dockerfile
depends_on:
- db
volumes:
- ./php/src:/var/www/html
ports:
- 5000:80
db:
container_name: db
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD
MYSQL_DATABASE: MY_DATABASE
MYSQL_USER: MYSQL_USER
MYSQL_PASSWORD: MYSQL_PASSWORD
ports:
- 9906:3306
phpmyadmin:
container_name: phpmyadmin
image: phpmyadmin/phpmyadmin
ports:
- 5050:80
restart: always
environment:
PMA_HOST: db
depends_on:
- db

4
php/Dockerfile

@ -0,0 +1,4 @@
FROM php:8.0-apache
RUN docker-php-ext-install mysqli \
&& docker-php-ext-enable mysqli
RUN apt update && apt upgrade -y

27
php/src/index.php

@ -0,0 +1,27 @@
<?php
echo "Hello World";
$host = 'db'; // Nom dans le docker-compose
$user = 'MYSQL_USER';
$pass = 'MYSQL_PASSWORD';
$my_database = "MY_DATABASE";
$conn = new mysqli($host, $user, $pass, $my_database);
$sql = 'SELECT * FROM users';
if ($result = $conn->query($sql)) {
while ($data = $result->fetch_object()) {
$users[] = $data;
}
}
foreach ($users as $user) {
echo "<br>";
echo $user->username . " " . $user->password;
echo "<br>";
}
?>
Loading…
Cancel
Save