laravel
Overview
Laravel is a PHP web application framework with expressive, elegant syntax. This guide will walk you through deploying a Laravel application on the NStrim platform from start to finish.
Quick Start
Create Repository from Template
On your dashboard, go to the Tools & Deployment tab. Click the "New Repository" button, select the Laravel 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>
Install Dependencies
composer install
Configure Environment
Copy the example environment file and configure your database (see detailed instructions below):
cp .env.example .env
php artisan key:generate
Run Migrations & Push
php artisan migrate
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 Laravel commands. The project includes a Dockerfile that sets up everything you need.
Prerequisites
Install Docker Desktop for your operating system (Windows, Mac, or Linux).
Running Commands with Docker
Instead of running php artisan migrate directly, you run it inside a Docker container:
# Build the Docker image (only needed once)
docker build -t laravel-app .
# Run any artisan command
docker run --rm laravel-app php artisan migrate
# Run composer install
docker run --rm -v $(pwd):/var/www/html laravel-app composer install
# Interactive shell inside container
docker run --rm -it -v $(pwd):/var/www/html laravel-app bash
Database Configuration
The NStrim platform provides you with a MySQL/MariaDB database. You need to configure your .env file with the correct database credentials to connect.
Why Configure the Database?
Laravel uses a .env file to store environment-specific configuration. By default, the template uses SQLite (a file-based database), but NStrim provides MySQL for better performance and compatibility with real-world scenarios.
Step-by-Step Configuration
Open Your .env File
Open the .env file in your project root with your code editor.
Find the Database Section
Look for these lines (usually around line 23):
DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=
Update with Your Credentials
Replace with the credentials from your dashboard:
DB_CONNECTION=mysql
DB_HOST=db.<session-domain>
DB_PORT=3306
DB_DATABASE=<your-username>
DB_USERNAME=<your-username>
DB_PASSWORD=<your-password>
student01). Check your dashboard credentials section for exact values.Example Configuration
If your username is student01 and session domain is demo.nstrim.app:
DB_CONNECTION=mysql
DB_HOST=db.demo.nstrim.app
DB_PORT=3306
DB_DATABASE=student01
DB_USERNAME=student01
DB_PASSWORD=your-password-from-dashboard
Running Migrations
Migrations are Laravel's way of creating database tables. After configuring your database, run migrations to set up the required tables:
php artisan migrate
If you need to reset and re-run all migrations (this will delete all data):
php artisan migrate:fresh
To run migrations with seed data (if your project has seeders):
php artisan migrate:fresh --seed
Project Structure
Understanding where files are located:
├── app/ # Application code
│ ├── Http/
│ │ └── Controllers/ # Your controllers go here
│ └── Models/ # Eloquent Models
├── config/ # Configuration files
├── database/
│ ├── migrations/ # Database migrations
│ └── seeders/ # Database seeders
├── public/ # Public assets (CSS, JS, images)
├── resources/
│ └── views/ # Blade templates
├── routes/
│ └── web.php # Web routes (URL → Controller)
├── .env # Environment configuration (DB, etc.)
└── composer.json # PHP dependencies
Common Tasks
Creating a New Controller
php artisan make:controller ProductController
Creating a New Model with Migration
php artisan make:model Product -m
Adding a Route
Edit routes/web.php:
Route::get('/products', [ProductController::class, 'index']);
Clearing Cache
php artisan cache:clear
php artisan config:clear
php artisan view:clear
Useful Commands
php artisan serve
Start local development server
php artisan migrate
Run database migrations
php artisan migrate:status
Check migration status
php artisan make:controller
Create a new controller
php artisan make:model -m
Create model with migration
php artisan route:list
List all registered routes
php artisan tinker
Interactive PHP shell for testing
Troubleshooting
SQLSTATE[HY000] [2002] Connection refused
Cause: Database host is incorrect or database server is not accessible.
Solution: Check that DB_HOST in your .env file matches the database host from your dashboard (usually db.<session-domain>).
SQLSTATE[HY000] [1045] Access denied for user
Cause: Wrong username or password.
Solution: Double-check DB_USERNAME and DB_PASSWORD match exactly what's shown in your dashboard. Passwords are case-sensitive!
SQLSTATE[HY000] [1049] Unknown database
Cause: Database name doesn't exist.
Solution: Verify DB_DATABASE is set to your username (e.g., student01). Your database is pre-created with the same name as your username.
No application encryption key has been specified
Cause: The APP_KEY is missing in .env.
Solution: Run php artisan key:generate to generate a new key.
Class 'App\Http\Controllers\...' not found
Cause: Autoloader doesn't know about your new class.
Solution: Run composer dump-autoload to regenerate the autoloader.
Page shows old content after changes
Cause: Laravel is caching views or configuration.
Solution: Clear all caches:
php artisan cache:clear
php artisan config:clear
php artisan view:clear
500 Server Error after deployment
Cause: Usually a configuration issue or missing dependencies.
Solution: Check that:
.envfile exists and has correct values- APP_KEY is set (run
php artisan key:generate) - All dependencies are installed (
composer install) - Database credentials are correct
Checking Your Database
You can access phpMyAdmin to visually manage your database. Click the MySQL button on your dashboard to open phpMyAdmin. Log in with the same credentials shown on your dashboard.
From phpMyAdmin you can:
- View all tables created by migrations
- Browse and edit data directly
- Run custom SQL queries
- Export/import database data
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