8000 GitHub - FMI-VT/php-codespaces-start: Repository used for PHP tutoring after 2025
[go: up one dir, main page]

Skip to content

FMI-VT/php-codespaces-start

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP & GitHub Codespaces Starter

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.

🚀 Quick Start (Codespaces)

  1. Click Use this template → Create a new repository in GitHub.
  2. Open your repo and click Code → Create codespace on main.
  3. When it boots, run:
    composer install
    composer test
    composer run serve
  4. Codespaces will auto-forward port 8000. Open it in the browser.

🎯 Try the Demo

  • Home page: / - Displays a greeting with PHP version info
  • Simple API: /?a=2&b=3 - Returns JSON { "sum": 5 }

📁 Project Structure

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

🧪 Features & Components

Core Components

  • 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

Example Code

  • src/functions.php: Contains evenOrOdd() utility function
  • src/Greeter.php: Example class demonstrating PSR-4 autoloading
  • public/index.php: Web entry point with demo API endpoints
  • tests/EvenOrOddTest.php: Unit tests demonstrating PHPUnit usage

🔧 Available Commands

# 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=always

🐛 Debugging (Xdebug)

Three debug configurations are available in VS Code:

  1. Listen for Xdebug - Standard web debugging (port 9003)
  2. Launch currently open script - Debug individual PHP files
  3. Launch Built-in web server - Debug with integrated server

Web Debugging

  • Set breakpoints in public/index.php
  • Start "Listen for Xdebug" configuration
  • Refresh your browser page

CLI Debugging

Use the xdebug-on helper script:

xdebug-on composer test    # Debug PHPUnit tests
xdebug-on php script.php   # Debug any PHP script

🏠 Local Development (Dev Containers)

If not using Codespaces:

  1. Install VS Code and Docker
  2. Install the Dev Containers extension
  3. Open the project folder in VS Code
  4. 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

🧩 Extending the Project

Adding New Classes

  1. Create files in src/ with the App\ namespace
  2. Follow PSR-4 autoloading conventions
  3. Add corresponding tests in tests/

Adding Dependencies

composer require vendor/package-name
composer require --dev vendor/dev-package-name

Environment Configuration

  • Modify .devcontainer/devcontainer.json for container settings
  • Update .devcontainer/Dockerfile for system dependencies
  • Adjust .vscode/launch.json for debugging configurations

📋 Requirements

  • GitHub Codespaces (recommended) or Docker + VS Code
  • No local PHP installation required when using containers

📄 License

MIT License - feel free to use this template for your projects!

About

Repository used for PHP tutoring after 2025

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dockerfile 50.6%
  • PHP 35.4%
  • Shell 14.0%
0