Skip to content
Snippets Groups Projects
Commit fc7a2152 authored by Muhammad Rifko Favian's avatar Muhammad Rifko Favian
Browse files

fix: setup docker to connect db

parent c7ec16ff
Branches
Tags
No related merge requests found
FROM php:8.0-apache
\ No newline at end of file
FROM php:8.0-apache
RUN docker-php-ext-install pdo pdo_mysql
\ No newline at end of file
......@@ -2,7 +2,12 @@ version: '3.3'
services:
web:
image: php:8.0-apache
build:
context: ./
dockerfile: Dockerfile
container_name: tubes-1
depends_on:
- db
ports:
- 8008:80
volumes:
......@@ -16,5 +21,3 @@ services:
- 3306:3306
volumes:
- ./db:/docker-entrypoint-initdb.d
depends_on:
- web
<!DOCTYPE html>
<html>
<head>
<title>PHP TITLE</title>
<title>PHP TITLE</title>
</head>
<body>
<h1>HAI HAI HAI HAI</h1>
<p>lalalalala</p>
<?php
$host = 'db'; // Service name from docker-compose
$dbname = 'tubes1_WBD'; // Your database name
$user = 'root'; // Your database user
$pass = ''; // Your database password
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
echo "Connected successfully!";
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
// PHP code
$phpVersion = phpversion();
echo "<p>PHP Version: $phpVersion</p>";
......@@ -15,4 +28,5 @@
<p>asdf</p>
</body>
</html>
</html>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment