vanilla
Overview
Vanilla PHP is a plain PHP project without any framework. It provides a clean starting point for simple projects, giving you full control over your code structure with HTML, CSS, JavaScript, and PHP.
Quick Start
Create Repository from Template
On your dashboard, go to the Tools & Deployment tab. Click the "New Repository" button, select the Vanilla PHP template from the dropdown, enter a repository name and subdomain, then click "Create Repository".
Clone Your Repository
git clone https://<git-server>/<username>/<repo-name>.git
cd <repo-name>
Configure Database (Optional)
If using MySQL, get your database credentials from phpMyAdmin (link on dashboard) and update your PHP files:
$host = 'your-host';
$dbname = 'your-database';
$username = 'your-username';
$password = 'your-password';
Start Developing
Edit HTML, CSS, JavaScript, and PHP files directly. No build step required!
Push Your Changes
git add .
git commit -m "Initial setup"
git push origin main
Local Development with Docker
If you don't have PHP installed locally, you can use Docker to run a local PHP server. The project includes a Dockerfile with PHP 8.2 and Apache.
Prerequisites
Install Docker Desktop for your operating system (Windows, Mac, or Linux).
Running with Docker
# Build and run the container
docker build -t my-php-app .
docker run -p 8080:80 -v $(pwd):/var/www/html my-php-app
# Or use a quick one-liner for development
docker run --rm -p 8080:80 -v $(pwd):/var/www/html php:8.2-apache
Open http://localhost:8080 in your browser.
Project Structure
Understanding where files are located:
├── index.php # Main entry point
├── css/
│ └── style.css # Stylesheets
├── js/
│ └── script.js # JavaScript files
├── includes/
│ ├── config.php # Database configuration
│ ├── header.php # Reusable header
│ └── footer.php # Reusable footer
├── images/ # Image assets
├── Dockerfile # Docker build configuration
└── README.md # Project documentation
Common Tasks
Database Connection with PDO
Create a reusable database connection:
<?php
$host = 'localhost';
$dbname = 'database_name';
$username = 'username';
$password = 'password';
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
die("Connection failed: " . $e->getMessage());
}
?>
Querying the Database
Use prepared statements for secure queries:
<?php
// SELECT query
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$userId]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
// INSERT query
$stmt = $pdo->prepare("INSERT INTO users (name, email) VALUES (?, ?)");
$stmt->execute([$name, $email]);
?>
Including Files
Reuse code across pages:
<?php
include 'includes/header.php';
// Your page content here
include 'includes/footer.php';
?>
Handling Form Data
Process POST requests safely:
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = htmlspecialchars($_POST['name'] ?? '');
$email = filter_var($_POST['email'] ?? '', FILTER_SANITIZE_EMAIL);
// Process the data...
}
?>
Key Technologies
PHP 8.2
Server-side scripting with modern PHP features and MySQL/PDO support.
HTML5
Structure your web pages with semantic HTML elements.
CSS3
Style your pages with modern CSS features like Flexbox and Grid.
JavaScript
Add interactivity with vanilla JavaScript - no libraries required.
Troubleshooting
Database connection failed
Cause: Incorrect database credentials or database not accessible.
Solution: Check your credentials in phpMyAdmin (link on dashboard). Ensure host, database name, username, and password are correct.
PHP errors not showing
Cause: Error reporting is disabled.
Solution: Add at the top of your PHP file: ini_set('display_errors', 1); error_reporting(E_ALL);
Blank white page
Cause: PHP fatal error with error reporting disabled.
Solution: Enable error reporting (see above) or check server logs. Common causes: syntax errors, missing files, or undefined functions.
CSS/JS not loading
Cause: Incorrect file paths.
Solution: Use relative paths from your HTML file: href="css/style.css" or absolute paths: href="/css/style.css"
Form data not received
Cause: Form method or action incorrect.
Solution: Ensure your form has method="POST" and the correct action attribute pointing to your PHP file.
Deployment Workflow
Every time you push code to Git, your application is automatically deployed:
Your deployed application URL follows this format:
https://<your-subdomain>-<repo-name>.<session-domain>
Example: https://student01-module-a.demo.nstrim.app