A baseline PHP and MySQL dev containter. This represents my first attempt at creating a devcontainer, and ideally I want to use this a template for future PHP/MySQL projects.
For some reason a git push
from the command line results in an error, however, using the Source Control feature on the side bar does sync to a remote repo.
The following directions may need updating.
- Clone this repo into a local folder
- Remove the current remote repo
- Create a new remote repo for the project
- Link the remote repo to the local repo
- Update
docker-compose.yml
- change the container names for all services to reflect the project - Reopen the project in the container
- Update the readme to reflect the project
- Commit all changes
The basis for the PHP container comes from Microsoft's mcr.microsoft.com/devcontainers/php:0-8.2 image. I have not been able to find a feature list for the exact image, however, this dev readme file gives a good idea of all the tools installed. The version numbers for each install might vary from the linked file to the image.
- PHP v8.2.5
- Composer v2.5.5
- Xdebug v3.2.1
- Git v2.40.1
- MySQL v(latest)
- VS Code Devcontainer Extensions
- Apache Conf (from image)
- ESLint (form image)
- GitLens (from
devcontainer.json
) - PHP Debug (from image)
- PHP Intelephense (from image)
You can change the image in the docker-compose.yml
file to mcr.microsoft.com/devcontainers/php
to use the latest image available.
The repo contains a basic composer.json
file that sets up the PSR-4 autoload to tie the App
namespace to the src
folder. Once you get this running for you application you will want to run composer dump-autoload
in the container's terminal. This will create the /vendor
folder used by Composer.
Git is intalled from base image and has a basic configuration applied. By default, the image copies your host's git config, which you can confirm by running git config --list --global
and seeing that your user name and email are present. See the article, Sharing Git credentials with your container for ways to have git working from inside the container.
By default the devcontainer mounts a few folders and files. You can mount additional folders and files by updating the docker-compose.yml
file. After you run composer dump-autoload
(see above) you will want to update the volumes to map the /vendor
folder, i.e., ./vendor:/var/www/vendor
and then Rebuild and Reopen the devcontainer.
.:/workspace
- The root folder of the host workspace is mounted to the container's/workspace
folder../docker/xdebug/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
- The xdebug config file maps to the container's config file../public_html:/var/www/html
- Thepublic_html
folder maps to Apache's/var/www/html
folder../src:/var/www/src
- Thesrc
folder maps to the/var/www/src/
folder.
Xdebug is setup and configured to listen on port 9005 and VS Code's launch.json
is setup for the same port. You can use whatever browser extension you find convenient, I use Xdebug Helper (or from their repo).
You can configure Xdebug by updating the ./docker/xdebug/xdebug.ini
file and then rebuilding the container.
The default setup uses the latest version of MySQL and creates a named volume devdata
(aka phpdev_devdata
).