{"id":26167409,"url":"https://github.com/derafu/docker-php-caddy-server","last_synced_at":"2025-03-11T17:35:55.214Z","repository":{"id":281593715,"uuid":"945667159","full_name":"derafu/docker-php-caddy-server","owner":"derafu","description":"Docker with PHP and Caddy for Deployer","archived":false,"fork":false,"pushed_at":"2025-03-10T04:47:19.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-10T05:30:16.684Z","etag":null,"topics":["caddy","deployer","docker","php"],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/derafu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-09T23:35:37.000Z","updated_at":"2025-03-10T04:47:23.000Z","dependencies_parsed_at":"2025-03-10T05:30:29.927Z","dependency_job_id":"fa948897-6ab1-4ded-89ff-2fb71410916f","html_url":"https://github.com/derafu/docker-php-caddy-server","commit_stats":null,"previous_names":["derafu/docker-php-caddy-server"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derafu%2Fdocker-php-caddy-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derafu%2Fdocker-php-caddy-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derafu%2Fdocker-php-caddy-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derafu%2Fdocker-php-caddy-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/derafu","download_url":"https://codeload.github.com/derafu/docker-php-caddy-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243079705,"owners_count":20233042,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["caddy","deployer","docker","php"],"created_at":"2025-03-11T17:35:54.613Z","updated_at":"2025-03-11T17:35:55.208Z","avatar_url":"https://github.com/derafu.png","language":"Dockerfile","readme":"# Derafu Sites Server - Docker with PHP and Caddy for Deployer\n\n![GitHub last commit](https://img.shields.io/github/last-commit/derafu/docker-php-caddy-server/main)\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/derafu/docker-php-caddy-server)\n![GitHub Issues](https://img.shields.io/github/issues-raw/derafu/docker-php-caddy-server)\n\nA modern Docker setup for hosting PHP websites with Caddy web server and SSH access for Deployer deployments.\n\n## Features\n\n- **PHP 8.3**: Supported PHP version with common extensions.\n- **Caddy**: Modern web server with automatic HTTPS.\n- **SSH Access**: For automated deployments with Deployer.\n- **Automatic Site Discovery**: Just add your site folder and it works.\n- **Development Domains**: Test with .local domains that map to production folders.\n- **Automatic WWW Redirection**: For second-level domains (e.g., example.com → www.example.com).\n- **Auto-HTTPS**: Certificates are automatically generated on-demand.\n- **Environment Separation**: Development and production environments managed through Docker Compose override.\n\n## Quick Start\n\n### Prerequisites\n\n- Docker and Docker Compose installed on your system.\n- SSH key for deployment access.\n\n### Setup\n\n1. Clone this repository:\n   ```bash\n   git clone https://github.com/derafu/docker-php-caddy-server.git\n   cd docker-php-caddy-server\n   ```\n\n2. Add your SSH public key to `config/ssh/authorized_keys` for admin, and default deployment, access:\n   ```bash\n   cat ~/.ssh/id_rsa.pub \u003e config/ssh/authorized_keys\n   ```\n\n3. Build and start the container:\n   ```bash\n   docker-compose up -d\n   ```\n   The `-d` parameter runs it in detached mode (background).\n\n### Verification\n\nCheck that the container is running:\n\n```bash\ndocker-compose ps\n```\n\nView container logs:\n\n```bash\ndocker-compose logs -f\n```\n\nThe `-f` parameter allows you to follow logs in real-time.\n\n### Testing Your First Site\n\n1. Create a test site directory structure:\n   ```bash\n   mkdir -p sites/www.example.com/public\n   echo \"\u003c?php phpinfo();\" \u003e sites/www.example.com/public/index.php\n   ```\n\n2. Access the site at:\n   - Production mode: https://www.example.com (requires DNS configuration).\n   - Development mode: https://www.example.com.local:8443 (requires local hosts entry).\n\nFor local development, add to your `/etc/hosts` file:\n```\n127.0.0.1 www.example.com.local\n```\n\n## Directory Structure\n\n```\ndocker-php-caddy-server/\n├── config/                     # Configuration files.\n│   ├── caddy/                  # Caddy configuration.\n│   ├── php/                    # PHP configuration.\n│   ├── ssh/                    # SSH configuration and authorized keys.\n│   └── supervisor/             # Supervisor configuration.\n├── sites/                      # Web sites directory for local development.\n│   └── www.example.com/        # Example site.\n│       └── public/             # Public web files.\n├── .env                        # Docker Compose environment configuration.\n├── Dockerfile                  # Container definition.\n├── docker-compose.yml          # Docker services configuration (production).\n└── docker-compose.override.yml # Development-specific configuration.\n```\n\n## Development vs Production Environment\n\nThis project uses Docker Compose's override functionality to separate development and production configurations:\n\n### Production Environment\n\nThe base `docker-compose.yml` contains the minimal configuration needed for production deployment. It:\n\n- Sets up required environment variables.\n- Defines essential ports (HTTP, HTTPS, SSH).\n- Doesn't mount external volumes.\n\n### Development Environment\n\nThe `docker-compose.override.yml` file adds development-specific settings:\n\n- Adds additional development ports (e.g., management interface).\n- Mounts local volumes for easy site development.\n\n### Usage:\n\n- **Development**: Docker Compose automatically merges both files:\n  ```bash\n  docker-compose up -d\n  ```\n\n- **Production**: Use only the base configuration:\n  ```bash\n  docker-compose -f docker-compose.yml up -d\n  ```\n\n## Access and Management\n\n### SSH Access\n\nConnect to the container via SSH:\n\n```bash\nssh admin@localhost -p 2222\n```\n\n### Direct Container Access\n\nAccess the container shell:\n\n```bash\ndocker exec -it derafu-sites-server-php-caddy bash\n```\n\n### Restarting Services\n\nRestart Caddy web server:\n\n```bash\ndocker exec -it derafu-sites-server-php-caddy supervisorctl restart caddy\n```\n\n### Stopping the Container\n\n```bash\ndocker-compose down\n```\n\n### Rebuilding After Configuration Changes\n\nRebuild for development:\n\n```bash\ndocker-compose build --no-cache\ndocker-compose up -d\n```\n\nRebuild for production:\n\n```bash\ndocker-compose -f docker-compose.yml build --no-cache\ndocker-compose -f docker-compose.yml up -d\n```\n\n## Adding New Sites\n\n1. Create the site directory structure:\n   ```bash\n   mkdir -p sites/www.newsite.com/public\n   touch sites/www.newsite.com/public/index.php\n   ```\n\n2. No server restart required! Caddy automatically detects new sites.\n\n3. For local development, add to your hosts file:\n   ```\n   127.0.0.1 www.newsite.com.local\n   ```\n\n## Environment Variables\n\nCustomize behavior through environment variables:\n\n| Variable              | Description                    | Default             |\n|-----------------------|--------------------------------|---------------------|\n| `SERVER_NAME`         | Name for the docker container  | derafu-sites-server |\n| `CADDY_DEBUG`         | Enable debug mode with `debug` | (empty)             |\n| `CADDY_EMAIL`         | Email for Let's Encrypt        | admin@example.com   |\n| `CADDY_HTTPS_ISSUER`  | TLS issuer (internal, acme)    | internal            |\n| `CADDY_LOG_SIZE`      | Log file max size              | 100mb               |\n| `CADDY_LOG_KEEP`      | Number of log files to keep    | 5                   |\n| `CADDY_LOG_KEEP_DAYS` | Days to keep logs              | 14                  |\n| `WWW_ROOT_PATH`       | Web root path                  | /var/www/sites      |\n| `HTTP_PORT`           | HTTP port in host              | 8080                |\n| `HTTPS_PORT`          | HTTPS port in host             | 8443                |\n| `SSH_PORT`            | SSH port in host               | 2222                |\n| `ADMIN_USER`          | SSH user in the container      | admin               |\n| `ADMIN_GROUP`         | SSH group in the container     | admin               |\n\n## Domain Logic\n\nThe server handles domains in the following way:\n\n1. **Development domains**: Any domain ending with `.local` (e.g., `www.example.com.local`)\n   - Maps to the same directory as its production counterpart.\n   - Uses internal self-signed certificates.\n\n2. **Production domains**:\n   - Redirects from non-www to www for second-level domains.\n   - Automatically obtains and manages Let's Encrypt certificates (issuer `acme`).\n\n## Troubleshooting\n\n### SSL Certificate Issues\n\nIf you're having issues with SSL certificates in development:\n\n- Ensure your browser trusts self-signed certificates.\n- Try using HTTP instead of HTTPS for local development.\n\n### Permissions Issues\n\nIf you encounter permission issues:\n\n```bash\ndocker exec -it derafu-sites-server-php-caddy chown -R admin:admin /var/www/sites\n```\n\n### Logs Location\n\nLogs are available in the container and can be accessed with:\n\n```bash\ndocker exec -it derafu-sites-server-php-caddy cat /var/log/caddy/access.log\n```\n\n## Advanced Usage\n\n### Custom Caddy Configuration\n\nFor advanced configurations, modify the Caddyfile at `config/caddy/Caddyfile`.\n\n### Using with Deployer\n\nThis container is designed to work with [Deployer](https://deployer.org/) for PHP deployments:\n\n1. Set up your `deploy.php` configuration to connect to the SSH server on port 2222.\n2. Use the `admin` user for authentication.\n3. Set your deployment path to `/var/www/sites/www.yoursite.com`\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\nThis package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderafu%2Fdocker-php-caddy-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderafu%2Fdocker-php-caddy-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderafu%2Fdocker-php-caddy-server/lists"}