What's new

Closed Php Crud Tutorial using Docker

Status
Not open for further replies.

pixkit

Honorary Poster
Joined
Mar 30, 2019
Posts
411
Reaction
197
Points
170
This tutorial is a derivative of the tutorial on https://phcorner.net/threads/706511/ which came from https://phcorner.net/#forbidden#2KDy85c

What's different with this tutorial?
You get to do everything in containers using Docker!

What is Docker?
Docker provides container software that is ideal for developers and teams looking to get started and experimenting with container-based applications. You do not have permission to view the full content of this post. Log in or register now. provides an integrated container-native development experience; it launches as an application from your Mac or Windows toolbar and provides access to the largest library of community and certified Linux and Windows Server content from You do not have permission to view the full content of this post. Log in or register now..
You do not have permission to view the full content of this post. Log in or register now.
In layman's terms, Docker is a lightweight virtual machine that allows you to run multiple machines separately.

Here's an example: You can run VirtualBox on your Windows or Mac machine. With VirtualBox, you can run multiple Linux distros. With Docker, you can run multiple Php, MySQL, Java, etc servers inside a distro as if they are separate distros. In this way you don't have to install another Ubuntu distro just to install another version of Php, MySQL, Java. The biggest benefit is everything is just pure text to setup a machine.

For example, if I want to run a MySQL server, all I need to do is pop a terminal, and type this:
Code:
docker run --rm --name mysql-server-instance \
    -p 3307:3306  \
    -e MYSQL_ROOT_PASSWORD=bar \
    mysql:5.7.25

Instant MySQL server. Of course you have to install Docker first from You do not have permission to view the full content of this post. Log in or register now.. It's like you can't run Linux distro on your Windows, without installing VirtualBox or VMWare.

Okay, here's the TUTORIAL

Let's run a MySQL server first

1. Open a terminal
2. Copy and paste this
Code:
docker run --rm --name mysql-server-instance \
    -p 3307:3306  \
    -e MYSQL_ROOT_PASSWORD=bar \
    mysql:5.7.25

Let's run PhpMyAdmin that's hosted under Nginx server (similar to IIS and Apache)
1. Open another terminal
2. Copy and paste this
Code:
docker run --rm --name nginx-phpymyadmin-instance \
    -e PMA_HOST=192.168.1.15 \
    -e PMA_USER=root \
    -e PMA_PASSWORD=bar \
    -e PMA_PORT=3307 \
    -p 8082:80 \
    phpmyadmin/phpmyadmin
Note: Update the PMA_HOST ip to match your machine's local IP (not your IP from internet provider). In most cases this is either 127.0.0.1 or localhost. I'm on Mac so there's some quirkiness with the IP.

That's it. You got PhpMyAdmin and MySQL running!

Open a browser and go to You do not have permission to view the full content of this post. Log in or register now. and you should see PhpMyAdmin

591259


Let's setup the database
1. Go to this link
Code:
https://bit.ly/2KDy85c
2. Download the project (bottom-most section).
3. Unzip the project on a directory, ie L`/home/project` (Mac/Linux) or C:\project (Windows)
4. Follow the instructions on that original tutorial on how to create the db and import the database records in PhpMyAdmin.

Let's import the whole project to our Nginx server (otherwise we won't see the project)
1. Open a terminal
2. Copy and paste this
Code:
docker cp /home/project/ nginx-phpymyadmin-instance:/var/www/html/
Note: Replace /home/project/ with the directory where you originally unzipped your file!
3. Now go to You do not have permission to view the full content of this post. Log in or register now. and you should see the project running:

591260



Cleaning up
To stop our MySQL and PhpMyAdmin/Nginx servers, just do:

Code:
docker stop mysql-server-instance
docker stop nginx-phpymyadmin-instance

Other notes
You can do the same to test other languages and frameworks without messing your local machine's files. You can run MariaDb in the same manner as with MySQL. The same goes with PostGres. Just Google them.

MariaDB database
Code:
docker run --rm --name mariadb-instance \
    -p 3306:3306  \
    -e MYSQL_ROOT_PASSWORD=bar \
    mariadb:10.4.3-bionic
[code]

PostGres database
[code]
docker run --name postgres-instance -p 5433:5432 \
      -e POSTGRES_PASSWORD=mysecretpassword \
      -d postgres
[code]

RabbitMQ
[code]
docker run -d --rm --hostname rabbitmq-mgmt-host \
    --name rabbitmq-mgmt-instance \
    -e RABBITMQ_DEFAULT_USER=guest \
    -e RABBITMQ_DEFAULT_PASS=guest \
    -p 5672:5672 \
    -p 15672:15672 \
    rabbitmq:3.8.0-beta.3-management
[code]

Sure you can do the same by downloading them and installing manually on your Windows or download set of virtual images in VirtualBox and ssh to each box and download and install them all manually. But why?

I can run for versions of MySQL on the same machine via:
[code]
docker run --rm --name mysql-instance \
    -p 3307:3306  \
    -e MYSQL_ROOT_PASSWORD=bar \
    mysql:5

docker run --rm --name mysql-instance \
    -p 3308:3306  \
    -e MYSQL_ROOT_PASSWORD=bar \
    mysql:6

docker run --rm --name mysql-instance \
    -p 3309:3306  \
    -e MYSQL_ROOT_PASSWORD=bar \
    mysql:7

docker run --rm --name mysql-instance \
    -p 3310:3306  \
    -e MYSQL_ROOT_PASSWORD=bar \
    mysql:8
[code]

This assumes there is MySQL version 5, 6, 7, 8. Make sure you update the ports. You can't map all of them on 3306 otherwise you won't know which you are connecting with. Once you run these, you have four independent MySQL servers running in your machine via Docker.
 

Attachments

Last edited:
Status
Not open for further replies.
Back
Top