DALT.PHP
Guides

Deployment Guide

Deploy your DALT.PHP application to production

Learn how to deploy your DALT.PHP application to production with proper configuration, security, and performance optimization.

Important: DALT.PHP is designed for learning, not production. For production apps, use Laravel, Symfony, or similar frameworks. This guide is for deploying learning projects or prototypes.

Pre-Deployment Checklist

Before deploying, ensure:

  • All features tested locally
  • Database migrations ready
  • Environment variables configured
  • Debug mode disabled
  • Dependencies installed
  • Security best practices followed

Deployment Options

Option 1: Shared Hosting (Easiest)

Most shared hosting providers support PHP. Good for simple projects.

Providers:

  • Namecheap
  • Bluehost
  • HostGator
  • SiteGround

Upload Files

Upload your project via FTP/SFTP. Exclude these directories:

.git/
node_modules/
.dalt/node_modules/
storage/logs/

Configure Web Root

Point your domain to the public/ directory, not the project root.

In cPanel or hosting panel, set Document Root to: /home/username/public_html/public

Set Environment

Create .env file on server:

APP_ENV=production
APP_DEBUG=false
DB_DRIVER=pgsql
DB_HOST=localhost
DB_NAME=your_database
DB_USER=your_user
DB_PASS=your_password

Run Migrations

SSH into server and run:

cd /path/to/project
php artisan migrate

Set Permissions

chmod -R 755 storage
chmod -R 755 database

Option 2: VPS (More Control)

Use a VPS for full control. Good for production-like deployments.

Providers:

  • DigitalOcean
  • Linode
  • Vultr
  • AWS Lightsail

Setup Server

# Update system
sudo apt update && sudo apt upgrade -y

# Install PHP 8.2+
sudo apt install php8.2 php8.2-cli php8.2-fpm php8.2-sqlite3 php8.2-mbstring -y

# Install Nginx
sudo apt install nginx -y

# Install Composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Clone Project

cd /var/www
sudo git clone https://github.com/yourusername/your-project.git
cd your-project
sudo composer install --no-dev --optimize-autoloader

Configure Nginx

Create /etc/nginx/sites-available/your-project file:

server {
    listen 80;
    server_name yourdomain.com;
    root /var/www/your-project/public;
    
    index index.php;
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    
    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Enable site:

sudo ln -s /etc/nginx/sites-available/your-project /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Setup Environment

cp .env.example .env
nano .env

Set production values:

APP_ENV=production
APP_DEBUG=false

Run Migrations

php artisan migrate

Set Permissions

sudo chown -R www-data:www-data /var/www/your-project
sudo chmod -R 755 /var/www/your-project
sudo chmod -R 775 /var/www/your-project/storage
sudo chmod -R 775 /var/www/your-project/database

Option 3: Platform as a Service

Use PaaS for zero-config deployments.

Providers:

  • Heroku
  • Railway
  • Render
  • Platform.sh

Example with Railway:

  1. Connect GitHub repository
  2. Railway auto-detects PHP
  3. Add environment variables
  4. Deploy automatically on push

Option 4: Docker Container

Use Docker for consistent deployments across any environment.

Create Dockerfile

Create a Dockerfile in your project root:

FROM php:8.2-fpm-alpine

# Install system dependencies
RUN apk add --no-cache \
    nginx \
    supervisor \
    sqlite

# Install PHP extensions
RUN docker-php-ext-install pdo pdo_pgsql

# Set working directory
WORKDIR /var/www/html

# Copy project files
COPY . .

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN composer install --no-dev --optimize-autoloader

# Set permissions
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/database

# Copy Nginx config
COPY docker/nginx.conf /etc/nginx/http.d/default.conf

# Copy supervisor config
COPY docker/supervisord.conf /etc/supervisord.conf

EXPOSE 80

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

Create Nginx Config

Create docker/nginx.conf:

server {
    listen 80;
    server_name _;
    root /var/www/html/public;
    
    index index.php;
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Create Supervisor Config

Create docker/supervisord.conf:

[supervisord]
nodaemon=true
user=root

[program:php-fpm]
command=php-fpm8.2 -F
autostart=true
autorestart=true

[program:nginx]
command=nginx -g 'daemon off;'
autostart=true
autorestart=true

Create docker-compose.yml

For local development and testing:

version: '3.8'

services:
  app:
    build: .
    ports:
      - "8000:80"
    volumes:
      - .:/var/www/html
    environment:
      - APP_ENV=production
      - APP_DEBUG=false
      - DB_DRIVER=pgsql
      - DB_HOST=db
      - DB_NAME=dalt
      - DB_USER=dalt
      - DB_PASS=secret
    depends_on:
      - db

  db:
    image: postgres:16-alpine
    environment:
      - POSTGRES_DB=dalt
      - POSTGRES_USER=dalt
      - POSTGRES_PASSWORD=secret
    volumes:
      - db_data:/var/lib/postgresql/data

volumes:
  db_data:

Build and Run

# Build the image
docker build -t dalt-php .

# Run with docker-compose
docker-compose up -d

# Run migrations
docker-compose exec app php artisan migrate

# View logs
docker-compose logs -f

Deploy to Production

Push to Docker Hub:

# Tag the image
docker tag dalt-php yourusername/dalt-php:latest

# Push to Docker Hub
docker push yourusername/dalt-php:latest

Then deploy on any Docker-compatible platform (AWS ECS, Google Cloud Run, DigitalOcean App Platform, etc.)

Production Configuration

Disable Debug Mode

In .env file:

APP_ENV=production
APP_DEBUG=false

Use Production Database

Switch from SQLite to PostgreSQL:

DB_DRIVER=pgsql
DB_HOST=localhost
DB_NAME=production_db
DB_USER=db_user
DB_PASS=secure_password

Optimize Composer

composer install --no-dev --optimize-autoloader

Enable OPcache

In php.ini file:

opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60

Security Hardening

Hide Sensitive Files

Ensure .env is not web-accessible:

location ~ /\.env {
    deny all;
}

Use HTTPS

Install SSL certificate:

# Using Let's Encrypt
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com

Set Secure Headers

In Nginx config:

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
add_header X-XSS-Protection "1; mode=block";

Disable Directory Listing

autoindex off;

Limit Request Size

client_max_body_size 10M;

Performance Optimization

Enable Gzip Compression

gzip on;
gzip_types text/plain text/css application/json application/javascript;
gzip_min_length 1000;

Browser Caching

location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
    expires 1y;
    add_header Cache-Control "public, immutable";
}

Database Connection Pooling

Use persistent connections in config/database.php:

'options' => [
    PDO::ATTR_PERSISTENT => true,
]

Monitoring

Error Logging

Ensure errors are logged:

// In bootstrap.php
ini_set('log_errors', 1);
ini_set('error_log', base_path('storage/logs/php_errors.log'));

Application Logs

Check logs regularly:

tail -f storage/logs/app.log

Server Monitoring

Use tools like:

  • Uptime monitoring: UptimeRobot, Pingdom
  • Error tracking: Sentry, Rollbar
  • Performance: New Relic, Datadog

Backup Strategy

Database Backups

# PostgreSQL backup
pg_dump -U user database > backup.sql

# Automate with cron (daily at 2 AM)
0 2 * * * pg_dump -U user database > /backups/db_backup.sql

File Backups

# Backup uploads and database
tar -czf backup.tar.gz database/ storage/

Automated Backups

Use hosting provider's backup service or:

  • AWS S3
  • Backblaze B2
  • rsync to remote server

Continuous Deployment

Git-Based Deployment

# On server
cd /var/www/your-project
git pull origin main
composer install --no-dev
php artisan migrate
sudo systemctl restart php8.2-fpm

Deployment Script

Create deploy.sh script:

#!/bin/bash
cd /var/www/your-project
git pull origin main
composer install --no-dev --optimize-autoloader
php artisan migrate --force
sudo chown -R www-data:www-data storage
sudo systemctl restart php8.2-fpm
echo "Deployment complete!"

GitHub Actions

Create .github/workflows/deploy.yml file:

name: Deploy
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Deploy to server
        uses: appleboy/ssh-action@master
        with:
          host: secrets.HOST
          username: secrets.USERNAME
          key: secrets.SSH_KEY
          script: |
            cd /var/www/your-project
            ./deploy.sh

Troubleshooting

500 Internal Server Error

Check error logs:

tail -f /var/log/nginx/error.log
tail -f storage/logs/app.log

Common causes:

  • Wrong file permissions
  • Missing .env file
  • PHP errors (check with APP_DEBUG=true temporarily)

Database Connection Failed

Verify:

  • Database credentials in .env file
  • Database server is running
  • User has proper permissions

Routes Not Working

Ensure:

  • Nginx config has try_files directive
  • public/ is the document root
  • .htaccess rules (if using Apache)

Post-Deployment

Test Everything

  • Homepage loads
  • All routes work
  • Database queries execute
  • Forms submit correctly
  • Authentication works
  • File uploads work (if applicable)

Monitor Performance

  • Check page load times
  • Monitor database query performance
  • Watch server resource usage

Setup Alerts

Configure alerts for:

  • Server downtime
  • High error rates
  • Disk space low
  • High CPU/memory usage

Congratulations! Your DALT.PHP application is now deployed and running in production!

Next Steps

On this page