Skip to content

Instantly share code, notes, and snippets.

@joby-lol
Last active September 7, 2023 13:22
Show Gist options
  • Save joby-lol/6ed037ccbd8c56119270b12dfebb35eb to your computer and use it in GitHub Desktop.
Save joby-lol/6ed037ccbd8c56119270b12dfebb35eb to your computer and use it in GitHub Desktop.
PHP 8.2 Dev Container and VS Code launch options starting point
// .devcontainer/devcontainer.json
{
// build from dockerfile
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
// specify run arguments
"runArgs": [
"--dns=8.8.8.8" // for some reason DNS doesn't work right unless we explicitly name a DNS server
],
// mount entire sites_v2 directory, so we can access global config and shared DB
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace/${localWorkspaceFolderBasename},type=bind,consistency=cached",
"workspaceFolder": "/workspace/${localWorkspaceFolderBasename}",
// specify extensions that we want
"customizations": {
"vscode": {
"extensions": [
"DEVSENSE.intelli-php-vscode",
"DEVSENSE.phptools-vscode",
"DEVSENSE.profiler-php-vscode",
"DEVSENSE.composer-php-vscode",
"SanderRonde.phpstan-vscode",
"sibiraj-s.vscode-scss-formatter",
"mrmlnc.vscode-scss",
"Gruntfuggly.todo-tree",
"redhat.vscode-yaml",
"oliversturm.fix-json",
"ecmel.vscode-html-css",
"yzhang.markdown-all-in-one",
"DavidAnson.vscode-markdownlint",
"helixquar.randomeverything",
"neilbrayfield.php-docblocker",
"ms-vscode.test-adapter-converter"
]
}
}
}
# .devcontainer/Dockerfile
FROM ubuntu:22.04
# prepare to install php 8.2
RUN apt update && apt install -y software-properties-common
RUN add-apt-repository ppa:ondrej/php
RUN apt update
# install php 8.2 and other fundamental packages
RUN export DEBIAN_FRONTEND=noninteractive; apt install -y --no-install-recommends php8.2 php-curl git openssl unzip
# install composer and its CA certificates
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
COPY --from=composer:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
# install the PHP extensions that basically all PHP projects should need
RUN export DEBIAN_FRONTEND=noninteractive; apt install -y php8.2-opcache php-xdebug php-mbstring php-zip php-gd php-xml
# install extensions that are more project-specific
RUN export DEBIAN_FRONTEND=noninteractive; apt install -y php-sqlite3
// .vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0",
// your entry script goes here
"${workspaceRoot}/web/index.php
],
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment