-
-
Save maikeldaloo/2f42c7f0670712e950b0f4771f725f04 to your computer and use it in GitHub Desktop.
docker-compose with php/mysql/phpmyadmin/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 this directories structure: | |
. | |
├── docker-compose.yml | |
├── Dockerfile | |
├── dump | |
│ └── db_name.sql | |
├── sessions | |
└── 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
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; | |
SET time_zone = "+00: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 */; | |
/*!40101 SET NAMES utf8mb4 */; | |
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, 'William'), | |
(2, 'Marc'), | |
(3, 'John'); | |
/*!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 */; |
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.8" | |
services: | |
www: | |
build: . | |
ports: | |
- "8000:80" | |
volumes: | |
- ./www:/var/www/html/ | |
links: | |
- db | |
networks: | |
- default | |
db: | |
image: mysql:latest | |
ports: | |
- "3306:3306" | |
environment: | |
MYSQL_DATABASE: db_name | |
MYSQL_USER: db_user | |
MYSQL_PASSWORD: db_pass | |
MYSQL_ROOT_PASSWORD: root | |
volumes: | |
- ./dump:/docker-entrypoint-initdb.d | |
- persistent:/var/lib/mysql | |
networks: | |
- default | |
phpmyadmin: | |
image: phpmyadmin/phpmyadmin:latest | |
links: | |
- db:db | |
ports: | |
- 8001:80 | |
environment: | |
MYSQL_USER: db_user | |
MYSQL_PASSWORD: db_pass | |
MYSQL_ROOT_PASSWORD: root | |
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:8.2-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
<html> | |
<head> | |
<title>Hello...</title> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<div class="container"> | |
<?php echo "<h1>Hi! I'm happy</h1>"; ?> | |
<?php | |
$conn = mysqli_connect('db', 'stgeorge_user', 'stgeorge_pass', 'stgeorge_db'); | |
$query = 'SELECT * From Person'; | |
$result = mysqli_query($conn, $query); | |
echo '<table class="table table-striped">'; | |
echo '<thead><tr><th></th><th>id</th><th>name</th></tr></thead>'; | |
while($value = $result->fetch_array(MYSQLI_ASSOC)){ | |
echo '<tr>'; | |
echo '<td><a href="#"><span class="glyphicon glyphicon-search"></span></a></td>'; | |
foreach($value as $element){ | |
echo '<td>' . $element . '</td>'; | |
} | |
echo '</tr>'; | |
} | |
echo '</table>'; | |
$result->close(); | |
mysqli_close($conn); | |
?> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment