Start with docker-compose up -d
Stop with docker-compose stop
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.
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');
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:
docker exec -it ##ContainerID## mysql -p -u root
- enter password that was set in the docker-compose.yml file
GRANT ALL PRIVILEGES ON *.* TO 'homestead'@'%';
- Note that
*.*
grants permissions to all databases to the homestead user. To only grant permission to the homestead database, instead use the following:homestead.*
FLUSH PRIVILEGES;
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
withutf8mb4_unicode_ci
- Save the file and retry the import. More details on the error available from here
docker exec -i ##ContainerID## mysqldump -psecret -uhomestead homestead > db-exported.sql
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.