Develop PHP applications with MariaDB (MySQL Compatible).
| Options Id | Description | Type | Default Value |
|---|---|---|---|
| imageVariant | PHP version (use -trixie, -bookworm, -bullseye variants on local arm64/Apple Silicon): | string | 8.4-trixie |
This template references an image that was pre-built to automatically include needed devcontainer.json metadata.
- Image: mcr.microsoft.com/devcontainers/php (source)
- Applies devcontainer.json contents from image: Yes (source)
This template creates two containers, one for PHP and one for MariaDB. You will be connected to the PHP container, and from within that container the MariabDB container will be available on localhost port 3305. The MariaDB database has a default password of mariadb and you can update MariaDB parameters by updating the .devcontainer/docker-compose.yml file.
While the template itself works unmodified, it uses the mcr.microsoft.com/devcontainers/php image which includes git, a non-root vscode user with sudo access, and a set of common dependencies and Python tools for development.
You can connect to MariaDB from an external tool when connected to the Dev Container from a local tool by updating .devcontainer/devcontainer.json as follows:
"forwardPorts": [ "3306" ]Once the MariaDB container has port forwarding enabled, it will be accessible from the Host machine at localhost:3306. The MariaDB Documentation has:
- An Installation Guide for MySQL, a CLI tool to work with a MariaDB database.
- Tips on populating data in the database.
You can add other services to your docker-compose.yml file as described in Docker's documentation. However, if you want anything running in this service to be available in the container on localhost, or want to forward the service locally, be sure to add this line to the service config:
# Runs the service on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:dbBy default, web frameworks and tools often only listen to localhost inside the container. As a result, we recommend using the forwardPorts property to make these ports available locally.
"forwardPorts": [9000]The ports property in docker-compose.yml publishes rather than forwards the port. This will not work in a cloud environment like Codespaces and applications need to listen to * or 0.0.0.0 for the application to be accessible externally. Fortunately the forwardPorts property does not have this limitation.
This dev container includes Apache in addition to the PHP CLI. While you can use PHP's built in CLI (e.g. php -S 0.0.0.0:8080), you can start Apache by running:
apache2ctl startApache will be available on port 8080.
If you want to wire in something directly from your source code into the www folder, you can add a symlink as follows to postCreateCommand:
"postCreateCommand": "sudo chmod a+x \"$(pwd)\" && sudo rm -rf /var/www/html && sudo ln -s \"$(pwd)\" /var/www/html"...or execute this from a terminal window once the container is up:
sudo chmod a+x "$(pwd)" && sudo rm -rf /var/www/html && sudo ln -s "$(pwd)" /var/www/htmlNote: This file was auto-generated from the devcontainer-template.json. Add additional notes to a NOTES.md.