Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Automated documentation update #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/wp-mysql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

# WP & MySQL (wp-mysql)

Develop WP applications with MySQL.

## Options

| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| phpVersion | PHP version: | string | 7.4 |
| wpVersion | WP version: | string | 6.0 |
| contentPath | Content path: | string | themes |

This template references an image that was [pre-built](https://containers.dev/implementors/reference/#prebuilding) to automatically include needed devcontainer.json metadata

* **Image**: mcr.microsoft.com/devcontainers/php ([source](https://github.com/devcontainers/images/tree/main/src/php))
* **Applies devcontainer.json contents from image**: Yes ([source](https://github.com/devcontainers/images/blob/main/src/php/.devcontainer/devcontainer.json))

## Using this template

This template creates two containers, one for PHP and one for MySQL. You will be connected to the PHP container. The MySQL database has a default password of `wordpress` and you can update MySQL parameters by updating the `.devcontainer/docker-compose.yml` file.

The template uses the `wpdevenv/php` image which includes `git`. This template add a non-root `vscode` user with `sudo` access.

You can connect to MySQL from an external tool, it will be accessible from the Host machine at `localhost:9030`

### Adding another service

You can add other services to your `docker-compose.yml` file [as described in Docker's documentation](https://docs.docker.com/compose/compose-file/#service-configuration-reference). 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:

```yaml
# Runs the service on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db
```

### Using the forwardPorts property

By 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.

```json
"forwardPorts": [9000]
```

The `ports` property in `docker-compose.yml` [publishes](https://docs.docker.com/config/containers/container-networking/#published-ports) 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.

### Starting / stopping Apache

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:

```bash
apache2ctl start
```

Apache 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`:

```json
"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:

```bash
sudo chmod a+x "$(pwd)" && sudo rm -rf /var/www/html && sudo ln -s "$(pwd)" /var/www/html
```

---

_Note: This file was auto-generated from the [devcontainer-template.json](https://github.com/wpdevenv/dev_container_templates/blob/main/src/wp-mysql/devcontainer-template.json). Add additional notes to a `NOTES.md`._