Skip to content

omurphy27/jwdmc-docker-environment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

JWDMC PHP 5.6 and Mysql 5.5 Docker Environment

Starting and Stopping Docker Containers

Start with docker-compose up -d

Stop with docker-compose stop

Overview

This is a simple Docker enviroment intended for local development with Apache, PHP 5.6 and Mysql 5.5.

This pulls in an extended version of the official Docker php:5.6-apache image with much needed PHP extensions, such as mcrypt, opcache, pdo, pdo_mysql and mysqli. The PHP Apache container is mapped to port 8080 and will be accessible from localhost:8080. Application code should be placed in the application/ directory.

It also pulls in the official mysql:5.5 docker image. The Mysql container's port is mapped to localhost:3306, so that you can connect to it with a GUI like Sequel Pro. A mysql database and user are also created based on variables in the docker-compose.yml file. The mysql root password is also set based on the docker-compose.yml file.

Important Notes

Use db instead of localhost

To connect to mysql from your application code, you will need to connect to it with db as the host. For instance, in Wordpress, you would put the following in your WP Config:

define('DB_HOST', 'db');

Giving the newly created mysql user all privileges

You will need to change the permissions of the mysql user that we created in our docker compose file. Follow the below steps to do so:

  1. docker exec -it ##ContainerID## mysql -p -u root
  2. enter password that was set in the docker-compose.yml file
  3. GRANT ALL PRIVILEGES ON *.* TO 'homestead'@'%';
  4. Note that *.* grants permissions to all databases to the homestead user. To only grant permission to the homestead database, instead use the following: homestead.*
  5. FLUSH PRIVILEGES;

Importing a database

docker exec -i ##ContainerID## mysql -uhomestead -psecret homestead < db-to-import.sql

NOTE: If you receive the following error when doing the above import, Unknown collation: 'utf8mb4_unicode_520_ci', then you will need to alter your .sql file as described below.

  • In your sql file, find and replace all occurrences of utf8mb4_unicode_520_ci with utf8mb4_unicode_ci
  • Save the file and retry the import. More details on the error available from here

Exporting a database

docker exec -i ##ContainerID## mysqldump -psecret -uhomestead homestead > db-exported.sql

Note on importing and exporting

It is insecure to expose the mysql user password on the command line, but it's not an issue here since this is only meant for local development. See more info about connecting to mysql without using a password on the command line from here which is important for production.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages