A simple PHP web application boilerplate that serves a static HTML page with optional database support.
- 🚀 Built-in PHP web server
- 🗄️ Optional MySQL and PostgreSQL database support
- 📁 Static file serving
- 🔍 Health check endpoint
- ⚙️ Environment variable configuration
- 🎯 Simple routing system
- PHP >= 7.4
- PDO extension (included by default)
- PDO MySQL driver (for MySQL support)
- PDO PostgreSQL driver (for PostgreSQL support)
# Using PHP directly
php -S localhost:8080 -t . index.php
# Or using Composer
composer startThe server will start on port 8080 by default. You can customize the port using the PORT environment variable:
PORT=3000 php index.phpRun the server in development mode:
make devThis starts the PHP built-in server at http://localhost:8080.
The application automatically connects to a database if the DATABASE_URL environment variable is set.
- MySQL:
mysql://user:password@host:port/database - PostgreSQL:
postgres://user:password@host:port/databaseorpostgresql://user:password@host:port/database
# MySQL
DATABASE_URL="mysql://root:password@localhost:3306/mydb" php index.php
# PostgreSQL
DATABASE_URL="postgres://user:pass@localhost:5432/mydb" php index.phpThe database connection is established on each request and can be checked via the /health endpoint.
Serves the main HTML page from web/index.html.
Returns a JSON health check response with database connection status.
Response Example:
{
"status": "ok",
"database": {
"type": "MySQL",
"status": "Connected",
"connected": true
}
}Serves static files from the web/ directory.
Example: /static/styles.css → web/styles.css
.
├── index.php # Main application file
├── web/
│ └── index.html # Static HTML page
├── composer.json # Composer configuration
├── Makefile # Build and run commands
└── README.md # This file
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 8080 |
DATABASE_URL |
Database connection string | (none) |
This application is designed to work seamlessly with DollarDeploy, which handles build, deployment, and monitoring automatically.
- Pre-start command: sudo apt install -y php-fpm php-pgsql php-mysql
Deploying on the command line:
ddc --apiKey $DOLLARDEPLOY_API_KEY --services postgres --url https://github.com/dollardeploy/example-php --app:preStartCmd "sudo apt install php-fpm php-pgsql" --hostId $HOST_ID --app:type php
- Static files are served only from the
web/directory - Path traversal attacks are prevented with
realpath()checks - Database credentials should be provided via
DATABASE_URLenvironment variable - PDO is used with prepared statements for safe database operations
MIT