From 6f467ebc2d85361aa3c466710fe863ed089f4f75 Mon Sep 17 00:00:00 2001 From: Hidayatullah Wildan Ghaly Buchary <16521502@std.stei.itb.ac.id> Date: Thu, 2 Nov 2023 10:02:02 +0700 Subject: [PATCH] fix: change docker setup still not final --- .env.example | 7 +++++++ config/.env.example | 7 ------- config/config.php | 2 +- config/db_config.php | 36 ---------------------------------- docker-compose.yml | 46 ++++++++++++++++++++++++++------------------ 5 files changed, 35 insertions(+), 63 deletions(-) create mode 100644 .env.example delete mode 100644 config/.env.example delete mode 100644 config/db_config.php diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..1be74ad --- /dev/null +++ b/.env.example @@ -0,0 +1,7 @@ +DB_HOST=db +DB_NAME=mahasiswa_leveling +DB_PORT=3307 +DB_USER=u1 +DB_PASSWORD=a +WEB_PORT=6666 +PHPMYADMIN_PORT=8001 \ No newline at end of file diff --git a/config/.env.example b/config/.env.example deleted file mode 100644 index e24e01a..0000000 --- a/config/.env.example +++ /dev/null @@ -1,7 +0,0 @@ -DB_HOST=db -DB_NAME=dabest -DB_PORT=3306 -DB_USER=willy -DB_PASSWORD=duar -WEB_PORT=8080 -PHPMYADMIN_PORT=8001 \ No newline at end of file diff --git a/config/config.php b/config/config.php index 8f4e1d4..80d3c7d 100644 --- a/config/config.php +++ b/config/config.php @@ -1,7 +1,7 @@ <?php require_once 'dotenv.php'; -(new DotEnv(__DIR__ .'/.env'))->load(); +(new DotEnv(__DIR__ .'/../.env'))->load(); define('BASEURL', getenv('BASEURL')); define('DB_HOST', getenv('DB_HOST')); diff --git a/config/db_config.php b/config/db_config.php deleted file mode 100644 index 3adecd3..0000000 --- a/config/db_config.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -// Database connection -$server = "localhost:3308"; // NOTE: ini 3308 port yang dipake Willy, defaultnya 3306 -$username = "root"; -$password = ""; -$database = "Mahasiswa_Leveling"; - -$conn = new mysqli($server, $username, $password); -if ($conn->connect_error) { - die("Connection failed: " . $conn->connect_error); -} - -$query = "CREATE DATABASE IF NOT EXISTS $database"; -$conn->query($query); -$conn->close(); - -$conn = new mysqli($server, $username, $password, $database); -if ($conn->connect_error) { - die("Connection failed: " . $conn->connect_error); -} - -$tableExists = $conn->query("SHOW TABLES LIKE 'users'"); -if ($tableExists->num_rows == 0) { - // Table doesn't exist, so create it - $createTableSQL = "CREATE TABLE users ( - id INT PRIMARY KEY AUTO_INCREMENT, - username TEXT NOT NULL, - email TEXT NOT NULL, - password TEXT NOT NULL, - isAdmin INT DEFAULT 0 - )"; - $conn->query($createTableSQL); -} - -?> \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index c6a942e..e9e6056 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,25 +1,33 @@ version: '3.3' services: - www: + mhslvl-app: image: php:8.0-apache volumes: - - "./:/var/www/html" # sync project dir with container + - "./:/var/www/html" ports: - - ${WEB_PORT}:80 + - 8080:80 - 443:443 - db: - image: mysql:latest - environment: - - MYSQL_DATABASE=${DB_NAME} - - MYSQL_USER=${DB_USER} - - MYSQL_PASSWORD=${DB_PASSWORD} # this should live in a env var - - MYSQL_ALLOW_EMPTY_PASSWORD=1 # equivalent to True - volumes: - - "./db:/docker-entrypoint-initdb.d" # sync persistent sql files with container - phpmyadmin: - image: phpmyadmin/phpmyadmin - ports: - - ${PHPMYADMIN_PORT}:80 - environment: - - PMA_HOST=${DB_HOST} - - PMA_PORT=${DB_PORT} \ No newline at end of file + env_file: + - .env + + # mhslvl-app-db: + # image: mysql:latest + # ports: + # - ${DB_PORT}:3306 + # environment: + # - MYSQL_DATABASE=${DB_NAME} + # - MYSQL_USER=${DB_USER} + # - MYSQL_PASSWORD=${DB_PASSWORD} + # - MYSQL_ALLOW_EMPTY_PASSWORD=1 + # volumes: + # - "./db:/docker-entrypoint-initdb.d" + + # phpmyadmin: + # image: phpmyadmin/phpmyadmin + # env_file: + # - .env + # ports: + # - ${PHPMYADMIN_PORT}:80 + # environment: + # - PMA_HOST=${DB_HOST} + # - PMA_PORT=${DB_PORT} \ No newline at end of file -- GitLab