Codespaces with php and mysql #202521
Replies: 4 comments
|
You probably don't need XAMPP in Codespaces. I would just run PHP directly and set up MySQL separately. The main thing is to make sure the database is persistent, otherwise you might lose your data when the Codespace is recreated. A Docker setup with a volume could work well for this. I haven't used this exact setup a lot, but that's probably the direction I'd try. |
|
You don't need to recreate a traditional XAMPP stack in GitHub Codespaces. Codespaces is designed around Dev Containers, so the recommended approach is to containerize your development environment instead of installing everything into a single image. A typical setup would look like this:
Example project structure: With this approach you get:
If you're starting from scratch, I'd recommend using the official PHP Dev Container as your base and adding a MySQL service through Docker Compose. It's much closer to modern PHP development practices than trying to install XAMPP inside a Codespace. |
|
Both directions above are right — Dev Containers + Docker Compose, not XAMPP. Here's a concrete starting point: // .devcontainer/devcontainer.json
{
"name": "php-mysql",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace"
}# .devcontainer/docker-compose.yml
services:
app:
image: mcr.microsoft.com/devcontainers/php:8.3
volumes:
- ..:/workspace:cached
command: sleep infinity
db:
image: mysql:8.0
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: app
volumes:
- db-data:/var/lib/mysql
volumes:
db-data:One thing neither answer above mentions: the persistence caveat only covers part of the lifecycle. A named volume ( |
|
Building on the excellent Here is the fully optimized and production-ready setup for your 1. Updated
|
Uh oh!
There was an error while loading. Please reload this page.
🏷️ Discussion Type
Question
Body
Hi
How do I set up codespaces with a xampp type environment where I can code and test php mysql?
Ideally I'd like the data in the db to be persistent as well.
I looked in the templates when creating a new codespaces, but there is no php mysql option.
Appreciate any help!
All reactions