-
-
Save midhun1993/9ca902ca470d979256a638013666cca0 to your computer and use it in GitHub Desktop.
Updated version of: docker-compose with Php 7.2.6, Mysql 8.0.16, Phpmyadmin 4.8 & Apache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create a directory with the following structure: | |
├── docker-compose.yml | |
├── Dockerfile | |
├── dump | |
│ └── myDb.sql | |
└── www | |
└── index.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3" | |
services: | |
www: | |
build: . | |
ports: | |
- "8001:80" | |
volumes: | |
- ./www:/var/www/html/ | |
links: | |
- db | |
networks: | |
- default | |
db: | |
image: mysql:8.0.16 | |
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password'] | |
ports: | |
- "3306:3306" | |
environment: | |
MYSQL_DATABASE: myDb | |
MYSQL_USER: user | |
MYSQL_PASSWORD: test | |
MYSQL_ROOT_PASSWORD: test | |
volumes: | |
- ./dump:/docker-entrypoint-initdb.d | |
- persistent:/var/lib/mysql | |
networks: | |
- default | |
phpmyadmin: | |
image: phpmyadmin/phpmyadmin:4.8 | |
links: | |
- db:db | |
ports: | |
- 8000:80 | |
environment: | |
MYSQL_USER: user | |
MYSQL_PASSWORD: test | |
MYSQL_ROOT_PASSWORD: test | |
volumes: | |
persistent: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM php:7.2.6-apache | |
RUN docker-php-ext-install mysqli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$conn = mysqli_connect('db', 'user', 'test', 'myDb', 3306); | |
mysqli_set_charset($conn, "utf8"); | |
$query = 'SELECT * From Person'; | |
$result = mysqli_query($conn, $query); | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Demo</title> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet"> | |
<style>body{font-family:Nunito,sans-serif;min-height:90vh;align-items:center;justify-content:center;display:flex}</style> | |
</head> | |
<body> | |
<p> | |
<?php | |
while ($value = $result->fetch_array(MYSQLI_ASSOC)) { | |
foreach ($value as $element) { | |
echo ' - ' . $element; | |
} | |
} | |
$result->close(); | |
mysqli_close($conn); | |
?> | |
- | |
</p> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE IF NOT EXISTS myDb; | |
USE myDb; | |
SET | |
SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; | |
SET | |
time_zone = "+01:00"; | |
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | |
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | |
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | |
CREATE TABLE `Person` ( | |
`id` int(11) NOT NULL, | |
`name` varchar(20) NOT NULL | |
) ENGINE = InnoDB DEFAULT CHARSET = latin1; | |
INSERT INTO | |
`Person` (`id`, `name`) | |
VALUES | |
(1, 'Conf'), | |
(2, 'Nipsu'), | |
(3, 'Beyar'); | |
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | |
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | |
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment