PHP basic developer environment
Basic developer environment for Symfony apps.
For your convenience the developer environment has some helpers which take away some difficulties you could experience using docker containers.
If you want this easy helpers to be readily available for you you can use
environment before you start.
environment allows you to start your
environment with an updated
PATH and allows you to choose between
byobu. You can also define a default in the .env file.
explicit setting the window manager:
$ ./environment [tmux|screen|byobu]
using default window manager, defined in .env
When you are running in this environment all helpers are available in your path.
You are not required to use the environent, but then you have to call the helpers with their full path.
To make use of the helpers you should use the
run wrapper for
$ run up
There is a sample configuration
.env-sample which contains the defaults used
in this environment.
If you want to change some of these values, copy
C_UID=1000 C_GID=1000 PHPVERSION=7.1 NGINXVERSION=stable SYMFONYVERSION=4 BASEHOST=application.dev MYSQL_ROOT_PASSWORD=toor APPLICATION=../application DEVELOPMENT=1 WINDOW_MANAGER=tmux
C_UID / C_GID
Configure what UID and GID your PHP container must use. This usually should
match your Hosts UID and GID. To find your local UID you can run
id -u and to
find your local GID you can run
Choose your PHP version. To see which versions are available here.
Choose what version of Nginx you want. To see which versions are available see here
Choose the version of symfony you are going to use. The nginx configuration is slightly different between version 3 and version 4.
This setting defines what the hostname will be you can browse your Symfony app.
The example configuration will be give you
Choose whatever you want to use as default root password.
A relative or absolute path to your application code.
There is the
DEVELOPMENT environment variable wich will enable xdebug,
composer and enable timestamp checking in opcache.
DEVELOPMENT is enabled xdebug should work out of the box. When you have
issues - like while running docker for mac - you can set the extra environment
XDEBUG_CONFIG with your hosts ip in it so xdebug can properly
Set the default window manager when running the environment. Available options are: tmux, screen and byobu
The helpers are written in python, so you should have python2 or python3 installed on your system to be able to use them. Most Linux distributions and macOS have python already installed so there should be no issue there. There are no extra dependencies on python modules.
Run the composer command inside the php docker container. The working directory will be the current directory you are executing this command from. Your $HOME/.ssh and $HOME/.composer folders wil be mounted inside this container to enable you to make use of your ssh keys and composer cache.
$ composer require package_name
Create a new database inside the running mysql container with the name 'database' and 'DEFAULT CHARSET utf8mb4'.
$ create_db database
Execute a mysql command inside the running mysql container as the root user.
$ mysql "SELECT * FROM table_name;"
Execute the mysqldump command inside the running mysql container as the root user.
$ mysqldump db_name > export_file_name.sql
Import a given mysql file into a given database, inside the running mysql container as the root user.
$ mysqlimport db_name import_file_name.sql
Execute the node command inside a node container. The working directory will be the current directory you are executing this command from.
$ node js_file.js
Execute the npm command inside a node container. The working directory will be the current directory you are executing this command from. Your $HOME/.ssh and $HOME/.npm folders wil be mounted inside this container to enable you to make use of your ssh keys and npm cache.
$ npm install package_name
Execute the yarn command inside a node container. The working directory will be the current directory you are executing this command from. Your $HOME/.ssh and $HOME/.npm folders wil be mounted inside this container to enable you to make use of your ssh keys and npm cache.
$ yarn add package_name
Execute the php command inside the running php container, or inside a php-symfony container if none is running. The working directory will be the current directory you are executing this command from.
$ php -v
Execute the redis-cli command in the running redis container.
$ redis-cli flushall
Run docker-compose for the current project, setting the project name to the BASEHOST variable from the .env file
$ run up
For this environment to work properly you should install gnu coreutils
$ brew install coreutils
On macOS you could just install docker from the docker site and run like this. But our experience is that the native docker install is fairly slow to use. We would suggest you to install dinghy.
If you have dinghy installed this environment will try to use it.
Currently there is an annoying limitation when we are using dinghy and that is
that the hostnames used must end with
tmux on macOS
Tmux starts the shells as loginshells, that means that for example bash is
going to load the
profile files. This sort of behaviour triggers the
path_helper that will move our added PATH to the end. This is not the behaviour
To fix this you can change the if for the path helper in your
if [ -z $TMUX ] && [ -x /usr/libexec/path_helper ]; then eval `/usr/libexec/path_helper -s` fi
oh-my-zsh users should check if there is no fixed setting
$PATH in their
~/.zshrc. If that is the case you can safely comment it
out. If somewhere in your shell startup
$PATH is forced you lose the features
./environment script brings to you.
MIT License (MIT). See License File for more information.