Sign inSign up

teguh02/gophp

By teguh02

Updated about 1 year ago

A lightweight, high-performance Docker image that combines PHP 8.4 with a Go HTTP server

Image
Developer tools
0

597

teguh02/gophp repository overview

GoPHP - High-Performance PHP 8.4 + Go HTTP Server

Docker Pulls Docker Image Size GitHub

A lightweight, high-performance Docker image that combines PHP 8.4 (compiled from source) with a Go HTTP server. Perfect for modern PHP applications with intelligent framework routing and enhanced security.

🚀 Quick Start

# Run with default application
docker run -p 8080:80 teguh02/gophp:latest

# Mount your PHP project
docker run -p 8080:80 -v /path/to/your/project:/app teguh02/gophp:latest

Visit: http://localhost:8080

✨ Key Features

  • 🔥 High Performance: Go HTTP server with direct static file serving
  • 🛡️ Security Hardened: Blocks sensitive files (.env, .git/, composer files)
  • 🎯 Framework Smart: Auto-detection for WordPress, Laravel, CodeIgniter
  • 📦 Lightweight: Alpine Linux base (~80MB final image)
  • 🚀 Production Ready: Health checks, proper logging, non-root user
  • ⚡ Smart Caching: Optimized cache headers for static assets

🏗️ PHP Extensions Included

Core Extensions
  • PDO (pdo, pdo_mysql, pdo_sqlite) - Database connectivity
  • MySQLi - MySQL improved extension
  • cURL - HTTP client functionality
  • OpenSSL - Cryptographic functions
  • Zip - Archive handling
  • XML - XML processing
  • JSON - JSON data handling
  • mbstring - Multibyte string handling
Enhanced Extensions
  • GD - Image processing (WordPress themes/plugins)
  • Intl - Internationalization (Laravel, multi-language apps)
  • Tokenizer - Required by Composer and Laravel
  • OPcache - Performance optimization

🎯 Framework Support

WordPress
# Mount WordPress project
docker run -p 8080:80 -v /path/to/wordpress:/app teguh02/gophp:latest

# Features:
# - Pretty permalinks support
# - wp-admin, wp-content routing
# - Plugin/theme compatibility
Laravel
# Mount Laravel project (public folder auto-detected)
docker run -p 8080:80 -v /path/to/laravel:/app teguh02/gophp:latest

# Features:
# - Clean URLs without index.php
# - public/ directory support
# - Route caching compatibility
CodeIgniter
# Mount CodeIgniter project
docker run -p 8080:80 -v /path/to/codeigniter:/app teguh02/gophp:latest

# Features:
# - Controller/method routing
# - Clean URLs support
# - Assets serving optimization

🛡️ Security Features

Blocked Files (Returns 403 Forbidden)
  • .env - Environment configuration
  • .git/ - Git repository files
  • composer.json, composer.lock - Dependency files
  • package.json, package-lock.json - Node.js files
  • .htaccess - Apache configuration
  • wp-config.php - WordPress config (when accessed directly)
  • Backup files (*.bak, *.tmp, *.log)
  • System files (.DS_Store, Thumbs.db)
Additional Security
  • Non-root user execution (uid:1001)
  • PHP errors logged to stderr (Docker-friendly)
  • Minimal attack surface (essential packages only)

⚡ Performance Optimizations

Static File Caching
# Automatic cache headers
CSS/JS files:    Cache-Control: public, max-age=86400    (1 day)
Images:          Cache-Control: public, max-age=604800   (7 days)  
Fonts:           Cache-Control: public, max-age=2592000  (30 days)
Other static:    Cache-Control: public, max-age=3600     (1 hour)
PHP Optimizations
  • OPcache enabled - Bytecode caching
  • Realpath cache - File system optimization
  • Memory limit: 512MB (configurable)
  • Execution time: 30s (configurable)

🔧 Configuration

Environment Variables
# No environment variables required - auto-detection works out of the box
# Framework detection happens automatically based on project files
Custom PHP Configuration
# Mount custom php.ini
docker run -p 8080:80 \
  -v /path/to/project:/app \
  -v /path/to/custom.ini:/usr/local/php/etc/php.ini \
  teguh02/gophp:latest

🏥 Health Check

Built-in health endpoint for monitoring:

curl http://localhost:8080/health

Response:

{
  "status": "healthy",
  "service": "gophp", 
  "timestamp": 1694395200
}

📊 Usage Examples

Development Environment
# Quick development setup
docker run --rm -p 8080:80 -v $(pwd):/app teguh02/gophp:latest
Production Deployment
# docker-compose.yml
version: '3.8'
services:
  web:
    image: teguh02/gophp:latest
    ports:
      - "80:80"
    volumes:
      - ./app:/app
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost/health"]
      interval: 30s
      timeout: 10s
      retries: 3
With Database
# Full stack with MySQL
version: '3.8'
services:
  web:
    image: teguh02/gophp:latest
    ports:
      - "80:80"
    volumes:
      - ./app:/app
    depends_on:
      - mysql
    restart: unless-stopped

  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: yourpassword
      MYSQL_DATABASE: yourapp
    volumes:
      - mysql_data:/var/lib/mysql
    restart: unless-stopped

volumes:
  mysql_data:

🔍 Troubleshooting

Common Issues

Internal Server Error on PHP files:

# Check container logs
docker logs <container_name>

# Verify PHP-CGI is working
docker exec <container_name> php-cgi -v

File permissions:

# Ensure files are readable
chmod -R 755 /path/to/your/project

Framework not detected:

# Check for framework files
# WordPress: wp-config.php
# Laravel: artisan file
# CodeIgniter: system/ directory

📈 Performance Benchmarks

MetricValue
Image Size~80MB
Cold Start~2s
Memory Usage~50MB (base)
Static File ServingDirect (no PHP overhead)
Framework DetectionAutomatic

🛠️ Advanced Usage

Custom Nginx/Apache Alternative

This image replaces traditional web servers:

# Instead of nginx + php-fpm
docker run nginx:alpine  # ❌ Complex setup

# Use GoPHP directly  
docker run teguh02/gophp:latest  # ✅ Simple & fast
Multi-site Hosting
# Host multiple PHP apps
docker run -p 8080:80 -v /var/www/site1:/app teguh02/gophp:latest
docker run -p 8081:80 -v /var/www/site2:/app teguh02/gophp:latest

📝 Build Information

  • Base Image: Alpine Linux 3.19
  • PHP Version: 8.4.0 (compiled from source)
  • Go Version: 1.21+ (for HTTP server)
  • Architecture: Multi-platform (amd64, arm64)
  • Build Method: Multi-stage (optimized)

🤝 Contributing

Found a bug or want to contribute?

📄 License

This project is licensed under the MIT License.


⭐ If this image helps your project, please consider giving it a star!

Tag summary

Content type

Image

Digest

sha256:f3b19e2d0

Size

35.7 MB

Last updated

about 1 year ago

docker pull teguh02/gophp