A Docker Compose framework designed to make it simple to test different versions of Apache, PHP, and MySQL. Whether you are looking to perform major version upgrades or simply need to test your app against various software stacks, this repo might be able to help. With easy-to-use configuration files, you can simultaneously switch between multiple software versions to ensure your application runs smoothly under any setup.
For a more detailed review of the functionality of this repo as well as the inspiration, check out my blog post.
- Nginx Load Balancer - Latest Version
- Apache PHP - Latest Version
- Apache PHP - v7.4.33
- MySQL - Latest Version
- PHPMyAdmin for MySQL - Latest Version
- MySQL - v5.7.43
- PHPMyAdmin for MySQL - v5.7.43
- Docker and Supported OS
- On the docker host
Starting containers:
$ docker compose up -d
Viewing containers:
$ docker ps
Stopping containers:
$ docker compose down
- Accessing Resources
Web URLs:
- localhost:8080 - Apache PHP v8.2.x
- localhost:8081 - Apache PHP v7.4.33
- localhost:8090 - PHPMyAdmin for MySQL v8.1.x
- localhost:8091 - PHPMyAdmin for MySQL v5.7.43
MySQL:
$ mysql --host=localhost --port=3380 --user=root -p --protocol=tcp
$ mysql --host=localhost --port=3381 --user=root -p --protocol=tcp
MySQL Database Import Example:
$ mysql --host=localhost --port=3381 --user=root -p --protocol=tcp DATABASE_NAME < FILE.sql
MySQL Database Dump Example:
$ mysqldump --host=localhost --port=3381 --user=root -p --protocol=tcp DATABASE_NAME > FILE.sql
- Place PHP source code into the following versioned directories:
$ apache-php-latest/src/
$ apache-php-7.4.33/src/
- Update database connection strings to
db
anddb_legacy
to test between MySQL containers.
Using the db_legacy
container running MySQL 5.7:
<?php
// MySQL Server Host
// 'db_legacy' is the Docker Compose service name for MySQL
$host = 'db_legacy';
// MySQL Root Password
// Same as MYSQL_ROOT_PASSWORD in docker-compose.yml
$rootPassword = 'mysql-root-sdlc';
// Connect to MySQL server with root credentials
$rootPdo = new PDO("mysql:host=$host", 'root', $rootPassword);
MySQL data is stored in docker volumes defined in the compose.yml
file.
volumes:
db_data:
db_legacy_data:
Volumes can be listed using the docker cli and are preserved between container creations and destroys.
$ docker volume ls
local docker-lamp-version-sandbox_db_data
local docker-lamp-version-sandbox_db_legacy_data
View images:
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx-latest latest a2bc4287970f 3 hours ago 187MB
apache-php-7.4.33 latest 4c2c4df02190 2 days ago 479MB
apache-php-latest latest a93bcf0730b4 3 days ago 531MB
phpmyadmin latest b5821d22d3db 8 days ago 562MB
mysql latest 99afc808f15b 5 weeks ago 577MB
mysql-latest latest e645c1e8d39e 5 weeks ago 577MB
mysql-5.7 latest 3e51c56d1e0b 6 weeks ago 581MB
Delete specific image:
$ docker image rm IMAGE_NAME