├── Dockerfile
├── README.md
├── docker-compose.yml
└── src
└── index.php
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM php:7.4-apache
2 | RUN docker-php-ext-install mysqli
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | ## [Please support our YouTube channel by Subscribing!](https://www.youtube.com/channel/UCa0s8d-23qP7RmIMZ54x7Ug)
4 |
5 | ## [Heal our planet AND progress society at the same time?](https://truthseekers.io/support-nuclear/)
6 |
7 | ### Develop your skills with our high quality tutorials on:
8 |
9 | Linux, Docker & Kubernetes, React.js, GraphQL, SQL, Mongo, Emacs & more. Literally anything tech.
10 |
11 | ## [Join our community by signing up for our newsletter!](https://truthseekers.io/latest-tutorials-signup/)
12 |
13 | Just cd into directory and run:
14 |
15 | docker-compose up -d
16 |
17 | to stop:
18 |
19 | docker-compose down
20 |
21 | NOTE: In order for the app to work you will have to create a database named "company1", a "users" table with the columns "name" and "fav_color" in order for the errors to go away.
22 |
23 | You can do this in localhost:8080 (adminer) with "root" as user, "example" as password. "MySQL" selected for the system, and "db" as the server.
24 |
25 | Then create the database & table and you should be able to see the php grab the users and display them.
26 |
27 | https://truthseekers.io/php-docker-simple-environment/ blog post.
28 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | # Use root/example user/password credentials
2 | version: '3.1'
3 |
4 | services:
5 | php:
6 | build:
7 | context: .
8 | dockerfile: Dockerfile
9 | ports:
10 | - 80:80
11 | volumes:
12 | - ./src:/var/www/html/
13 |
14 | db:
15 | image: mysql
16 | command: --default-authentication-plugin=mysql_native_password
17 | restart: always
18 | environment:
19 | MYSQL_ROOT_PASSWORD: example
20 | volumes:
21 | - mysql-data:/var/lib/mysql
22 |
23 | adminer:
24 | image: adminer
25 | restart: always
26 | ports:
27 | - 8080:8080
28 |
29 | volumes:
30 | mysql-data:
31 |
--------------------------------------------------------------------------------
/src/index.php:
--------------------------------------------------------------------------------
1 | query($sql);
9 | $sql = "INSERT INTO users (name, fav_color) VALUES('Nick Jonas', 'Brown')";
10 | $result = $mysqli->query($sql);
11 | $sql = "INSERT INTO users (name, fav_color) VALUES('Maroon 5', 'Maroon')";
12 | $result = $mysqli->query($sql);
13 | $sql = "INSERT INTO users (name, fav_color) VALUES('Tommy Baker', '043A2B')";
14 | $result = $mysqli->query($sql);
15 |
16 |
17 | $sql = 'SELECT * FROM users';
18 |
19 | if ($result = $mysqli->query($sql)) {
20 | while ($data = $result->fetch_object()) {
21 | $users[] = $data;
22 | }
23 | }
24 |
25 | foreach ($users as $user) {
26 | echo "
";
27 | echo $user->name . " " . $user->fav_color;
28 | echo "
";
29 | }
30 |
--------------------------------------------------------------------------------