vanilla

Complete deployment guide for vanilla on NStrim

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.

Before You Start
Make sure you have your dashboard open - you'll need the Git credentials displayed there. This template includes PHP with MySQL/PDO support via Apache.

Quick Start

1

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

2

Clone Your Repository

git clone https://<git-server>/<username>/<repo-name>.git
cd <repo-name>
3

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';
4

Start Developing

Edit HTML, CSS, JavaScript, and PHP files directly. No build step required!

5

Push Your Changes

git add .
git commit -m "Initial setup"
git push origin main
Every push to Git automatically deploys your application. Check your Module Work URL on the dashboard to see your live site.

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.

What is Docker?
Docker creates isolated "containers" with all the software you need (PHP, Apache, MySQL extensions) without installing them on your computer. Think of it like a lightweight virtual machine.

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.

Note
Docker is optional for local development. The NStrim platform handles deployment automatically - you only need Docker if you want to run PHP locally without installing it.

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:

Code Change git push Deploy to Apache Live!

Your deployed application URL follows this format:

https://<your-subdomain>-<repo-name>.<session-domain>

Example: https://student01-module-a.demo.nstrim.app

For more information, visit PHP Documentation and MDN Web Docs.