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_passwordSet Permissions
chmod -R 755 storage
chmod -R 755 databaseOption 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/composerClone Project
cd /var/www
sudo git clone https://github.com/yourusername/your-project.git
cd your-project
sudo composer install --no-dev --optimize-autoloaderConfigure 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 nginxSetup Environment
cp .env.example .env
nano .envSet production values:
APP_ENV=production
APP_DEBUG=falseRun Migrations
php artisan migrateSet 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/databaseOption 3: Platform as a Service
Use PaaS for zero-config deployments.
Providers:
- Heroku
- Railway
- Render
- Platform.sh
Example with Railway:
- Connect GitHub repository
- Railway auto-detects PHP
- Add environment variables
- 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=trueCreate 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 -fDeploy 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:latestThen 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=falseUse Production Database
Switch from SQLite to PostgreSQL:
DB_DRIVER=pgsql
DB_HOST=localhost
DB_NAME=production_db
DB_USER=db_user
DB_PASS=secure_passwordOptimize Composer
composer install --no-dev --optimize-autoloaderEnable OPcache
In php.ini file:
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60Security 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.comSet 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.logServer 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.sqlFile 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-fpmDeployment 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.shTroubleshooting
500 Internal Server Error
Check error logs:
tail -f /var/log/nginx/error.log
tail -f storage/logs/app.logCommon 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
- Working with Database - Optimize queries
- Adding Authentication - Secure your app
- Framework Internals - Understand the system