zgulde / php-container

Docker container for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker container for PHP projects

license

Try your PHP + MySQL projects using Docker containers.

Installation

For Mac users

Install Docker Machine. Create a Docker VM and connect your shell to it.

$ docker-machine create
$ eval "$(docker-machine env default)"

The configuration for the containers is created using envsubst, which is not installed by default. You will need to install it with brew.

brew install gettext
brew link --force gettext

Linux and Mac

To setup the containers, run the following command:

$ cp .env.example .env.sh && make install

Usage

To start a bash session in the container, run the following command:

$ docker-compose run --rm --service-ports web bash

From your container you can use the following command to create a database:

$ database

You will need to provide, a database name, a user and a password. You will be able to use MySQL's client from the container using the following command:

$ mysql -u root -h db -p

The password for the root user is in the .env.sh file. Or you can login with any other user created from the container.

Adding PHP projects

Your projects are meant to be cloned inside the sites folder. This container uses PHP's built-in server to run your applications. You can start the server from your public folder. You can also provide the path to your public folder from the command line.

$ server
$ server -t path/to/public/folder

You can browse your site at http://localhost/. To stop your application, Press CTRL+C from the container.

Mac users need to use the VM's IP (192.168.99.101 for instance).

Configuration

The PHP container will have a user and a group matching your current username, user ID and group ID. You can set the password for MySQL's root user, the container's hostname, and the prefix to be used for the images and containers. Modify the .env.example file if you want to adjust those settings.

# This is the hostname for the PHP container
export CONTAINER_HOSTNAME=your_custom_container_hostname
export CONTAINERS_PREFIX=your_custom_prefix
# You'll get 3 images: your_custom_prefix/dev, your_custom_prefix/db, and your_custom_prefix/data
# And 3 containers: your_custom_prefix_dev, your_custom_prefix_db and your_custom_prefix_data
# This is the password for MySQL's root user
export DB_ROOT_PASSWORD=your_custom_mysql_password

If you create a custom .env.sh from the .env.example file. You only need to run this command to install the container:

$ make install

About

Docker container for PHP

License:MIT License


Languages

Language:PHP 49.9%Language:Makefile 36.3%Language:Shell 13.8%