Last active
February 4, 2025 06:06
-
-
Save Zxce3/7ddea6e9b5644939813f35fd78439dbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"name": "PHP 8.3 with MariaDB (Ondřej Surý PHP)", | |
"build": { | |
"dockerfile": "Dockerfile" | |
}, | |
"customizations": { | |
"vscode": { | |
"extensions": [ | |
"ikappas.composer", | |
"php.php-debug", | |
"ms-azuretools.vscode-docker", | |
"bmewburn.vscode-intelephense-client", | |
"editorconfig.editorconfig", | |
"mikestead.dotenv", | |
"streetsidesoftware.code-spell-checker", | |
"xdebug.php-debug" | |
], | |
"settings": { | |
"php.validate.enable": true, | |
"php.suggest.basic": false, | |
"editor.formatOnSave": true, | |
"files.trimTrailingWhitespace": true | |
} | |
} | |
}, | |
"features": { | |
"ghcr.io/devcontainers/features/github-cli:1": {}, | |
"ghcr.io/devcontainers/features/git:1": {} | |
}, | |
"forwardPorts": [ | |
8080, // Web server | |
3306, // MariaDB | |
9003 // Xdebug | |
], | |
"postCreateCommand": "composer install", | |
"remoteUser": "vscode", | |
"mounts": [ | |
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
php: | |
build: . | |
container_name: php-container | |
volumes: | |
- .:/workspace | |
ports: | |
- "8080:8080" | |
environment: | |
- PHP_VERSION=8.3 | |
depends_on: | |
- mariadb | |
mariadb: | |
image: mariadb:latest | |
container_name: mariadb-container | |
environment: | |
MYSQL_ROOT_PASSWORD: root | |
MYSQL_DATABASE: my_database | |
MYSQL_USER: user | |
MYSQL_PASSWORD: password | |
ports: | |
- "3306:3306" | |
volumes: | |
- mariadb-data:/var/lib/mysql | |
volumes: | |
mariadb-data: | |
driver: local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use the official Ubuntu base image | |
FROM ubuntu:20.04 | |
# Prevent interactive prompts during installation | |
ENV DEBIAN_FRONTEND=noninteractive | |
ENV TZ=UTC | |
# Install base dependencies first | |
RUN apt-get update && apt-get install -y --no-install-recommends \ | |
ca-certificates \ | |
curl \ | |
gnupg2 \ | |
lsb-release \ | |
tzdata \ | |
apt-transport-https \ | |
sudo \ | |
&& apt-get clean \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Create non-root user (moved after sudo installation) | |
RUN useradd -ms /bin/bash vscode && \ | |
adduser vscode sudo && \ | |
echo "vscode ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/vscode && \ | |
chmod 0440 /etc/sudoers.d/vscode | |
# Install development tools (removed sudo from here) | |
RUN apt-get update && apt-get install -y --no-install-recommends \ | |
git \ | |
unzip \ | |
zip \ | |
&& apt-get clean \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Install library dependencies | |
RUN apt-get update && apt-get install -y --no-install-recommends \ | |
libpng-dev \ | |
libjpeg-dev \ | |
libfreetype6-dev \ | |
libxml2-dev \ | |
libicu-dev \ | |
libssl-dev \ | |
mariadb-client \ | |
&& apt-get clean \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Add PHP repository and install PHP packages | |
RUN apt-get update && apt-get install -y software-properties-common && \ | |
add-apt-repository -y ppa:ondrej/php && \ | |
apt-get update && \ | |
apt-get install -y --no-install-recommends \ | |
php8.3 \ | |
php8.3-cli \ | |
php8.3-fpm \ | |
php8.3-mysql \ | |
php8.3-xml \ | |
php8.3-curl \ | |
php8.3-zip \ | |
php8.3-intl \ | |
php8.3-sockets \ | |
php8.3-mbstring \ | |
php8.3-bcmath \ | |
php8.3-gd \ | |
php8.3-opcache \ | |
php8.3-soap \ | |
php8.3-imagick \ | |
&& apt-get clean \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Install Composer | |
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | |
# PHP Configuration | |
RUN mkdir -p /etc/php/8.3/cli/conf.d && \ | |
echo "memory_limit=512M" > /etc/php/8.3/cli/conf.d/memory-limit.ini && \ | |
echo "max_execution_time=300" >> /etc/php/8.3/cli/conf.d/memory-limit.ini && \ | |
echo "upload_max_filesize=64M" >> /etc/php/8.3/cli/conf.d/memory-limit.ini && \ | |
echo "post_max_size=64M" >> /etc/php/8.3/cli/conf.d/memory-limit.ini | |
# Create required directories and set permissions | |
RUN mkdir -p /workspace && \ | |
chown -R vscode:vscode /workspace | |
# Set up working directory | |
WORKDIR /workspace | |
# Switch to non-root user | |
USER vscode | |
# Expose ports | |
EXPOSE 8080 | |
EXPOSE 3306 | |
# Healthcheck | |
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | |
CMD curl -f http://localhost:8080/ || exit 1 | |
# Start PHP development server | |
CMD ["php", "-S", "0.0.0.0:8080", "-t", "/workspace"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment