A zero-to-PHP template for GitHub Codespaces with PHPUnit testing, Xdebug debugging, and a simple web server setup. Start coding PHP in minutes — no local setup required.
- Click Use this template → Create a new repository in GitHub.
- Open your repo and click Code → Create codespace on main.
- When it boots, run:
composer install composer test composer run serve - Codespaces will auto-forward port 8000. Open it in the browser.
- Home page:
/- Displays a greeting with PHP version info - Simple API:
/?a=2&b=3- Returns JSON{ "sum": 5 }
/.devcontainer/ # Dev Container configuration
├── devcontainer.json # Container settings & VS Code extensions
├── Dockerfile # PHP 8.4 container setup
├── xdebug.ini # Xdebug configuration
└── scripts/
└── xdebug-on.sh # Helper script for CLI debugging
/.vscode/ # VS Code settings & debug configurations
└── launch.json # Xdebug launch configurations
/public/ # Web root (served by PHP built-in server)
└── index.php # Main entry point with demo endpoints
/src/ # Application source code
├── functions.php # Global utility functions
└── Greeter.php # Example class with PSR-4 autoloading
/tests/ # PHPUnit test suite
└── EvenOrOddTest.php # Example unit tests
composer.json # Dependencies & scripts
phpunit.xml # PHPUnit configuration
README.md # This file
- PHP 8.4: Latest PHP version with modern features
- PSR-4 Autoloading: Organized code structure with
App\namespace - PHPUnit 11.3: Modern testing framework with color output
- Xdebug: Full debugging support with multiple launch configurations
src/functions.php: ContainsevenOrOdd()utility functionsrc/Greeter.php: Example class demonstrating PSR-4 autoloadingpublic/index.php: Web entry point with demo API endpointstests/EvenOrOddTest.php: Unit tests demonstrating PHPUnit usage
# Install dependencies
composer install
# Run tests with colored output
composer test
# Start development server on port 8000
composer run serve
# Run tests manually
vendor/bin/phpunit --colors=alwaysThree debug configurations are available in VS Code:
- Listen for Xdebug - Standard web debugging (port 9003)
- Launch currently open script - Debug individual PHP files
- Launch Built-in web server - Debug with integrated server
- Set breakpoints in
public/index.php - Start "Listen for Xdebug" configuration
- Refresh your browser page
Use the xdebug-on helper script:
xdebug-on composer test # Debug PHPUnit tests
xdebug-on php script.php # Debug any PHP scriptIf not using Codespaces:
- Install VS Code and Docker
- Install the Dev Containers extension
- Open the project folder in VS Code
- Click "Reopen in Container" when prompted
The container will automatically:
- Install PHP 8.4 with Xdebug
- Run
composer install - Configure VS Code with PHP extensions
- Set up debugging environment
- Create files in
src/with theApp\namespace - Follow PSR-4 autoloading conventions
- Add corresponding tests in
tests/
composer require vendor/package-name
composer require --dev vendor/dev-package-name- Modify
.devcontainer/devcontainer.jsonfor container settings - Update
.devcontainer/Dockerfilefor system dependencies - Adjust
.vscode/launch.jsonfor debugging configurations
- GitHub Codespaces (recommended) or Docker + VS Code
- No local PHP installation required when using containers
MIT License - feel free to use this template for your projects!