Skip to main content
This guide covers deploying VIP2CARS to a production environment with proper optimization, security, and maintenance procedures.

Pre-Deployment Checklist

Before deploying to production, ensure:

Initial Deployment

Step 1: Clone Repository

cd /var/www
git clone https://github.com/farceque99/AndersonFarcequeFlores.git vip2cars
cd vip2cars
Adjust the repository URL and destination path according to your setup.

Step 2: Install Dependencies

1

Install PHP dependencies

composer install --optimize-autoloader --no-dev
The flags optimize for production:
  • --optimize-autoloader: Generates optimized autoloader for better performance
  • --no-dev: Excludes development dependencies
2

Install Node.js dependencies

npm ci
Use npm ci instead of npm install for faster, more reliable builds in production.

Step 3: Environment Configuration

1

Create environment file

cp .env.example .env
2

Generate application key

php artisan key:generate
3

Edit production settings

nano .env
Ensure these production values:
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.com

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=vip2cars
DB_USERNAME=vip2cars_user
DB_PASSWORD=secure-password
Critical: Always set APP_DEBUG=false in production to prevent sensitive information exposure.

Step 4: Database Setup

1

Run migrations

php artisan migrate --force
The --force flag is required in production environments.
2

Seed data (optional)

php artisan db:seed
Only run seeders if you need test data. Production systems typically don’t use seeders.

Step 5: Compile Assets

npm run build
This compiles and minifies all frontend assets using Vite.
The build process creates optimized JavaScript and CSS files in the public/build directory.

Step 6: Optimize Application

1

Cache configuration

php artisan config:cache
Caches all configuration files into a single file for faster loading.
2

Cache routes

php artisan route:cache
Compiles all routes into a single cached file.
3

Cache views

php artisan view:cache
Pre-compiles all Blade templates.
4

Cache events

php artisan event:cache
Caches event to listener mappings.
After making changes to configuration, routes, or views, you must clear and recache these files.

Step 7: Set Permissions

sudo chown -R www-data:www-data /var/www/vip2cars
sudo chmod -R 755 /var/www/vip2cars
sudo chmod -R 775 /var/www/vip2cars/storage
sudo chmod -R 775 /var/www/vip2cars/bootstrap/cache
Proper permissions are critical for security. The web server needs write access to storage and bootstrap/cache directories only.

Web Server Configuration

Nginx Configuration

Create /etc/nginx/sites-available/vip2cars:
server {
    listen 80;
    listen [::]:80;
    server_name yourdomain.com www.yourdomain.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name yourdomain.com www.yourdomain.com;
    root /var/www/vip2cars/public;

    # SSL Configuration
    ssl_certificate /etc/ssl/certs/yourdomain.crt;
    ssl_certificate_key /etc/ssl/private/yourdomain.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    # Logging
    access_log /var/log/nginx/vip2cars-access.log;
    error_log /var/log/nginx/vip2cars-error.log;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
1

Enable the site

sudo ln -s /etc/nginx/sites-available/vip2cars /etc/nginx/sites-enabled/
2

Test configuration

sudo nginx -t
3

Reload Nginx

sudo systemctl reload nginx

Apache Configuration

Create /etc/apache2/sites-available/vip2cars.conf:
<VirtualHost *:80>
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    Redirect permanent / https://yourdomain.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    DocumentRoot /var/www/vip2cars/public

    # SSL Configuration
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/yourdomain.crt
    SSLCertificateKeyFile /etc/ssl/private/yourdomain.key

    # Logging
    ErrorLog ${APACHE_LOG_DIR}/vip2cars-error.log
    CustomLog ${APACHE_LOG_DIR}/vip2cars-access.log combined

    <Directory /var/www/vip2cars/public>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
1

Enable required modules

sudo a2enmod rewrite ssl
2

Enable the site

sudo a2ensite vip2cars.conf
3

Restart Apache

sudo systemctl restart apache2

Queue Workers

VIP2CARS uses database queues for background tasks.

Setup Supervisor

Create /etc/supervisor/conf.d/vip2cars-worker.conf:
[program:vip2cars-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/vip2cars/artisan queue:work --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=2
redirect_stderr=true
stdout_logfile=/var/www/vip2cars/storage/logs/worker.log
stopwaitsecs=3600
1

Read configuration

sudo supervisorctl reread
2

Update Supervisor

sudo supervisorctl update
3

Start workers

sudo supervisorctl start vip2cars-worker:*

Check Worker Status

sudo supervisorctl status vip2cars-worker:*

Task Scheduling

Laravel’s task scheduler requires a single cron entry.
1

Open crontab

sudo crontab -e -u www-data
2

Add scheduler entry

* * * * * cd /var/www/vip2cars && php artisan schedule:run >> /dev/null 2>&1
The scheduler runs every minute and executes any scheduled tasks defined in your application.

Deployment Script

Create a deployment script for updates:
#!/bin/bash

set -e

echo "Starting deployment..."

# Enable maintenance mode
php artisan down --refresh=15

# Pull latest changes
git pull origin main

# Install dependencies
composer install --optimize-autoloader --no-dev
npm ci

# Compile assets
npm run build

# Run migrations
php artisan migrate --force

# Clear and cache
php artisan config:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache

# Restart queue workers
sudo supervisorctl restart vip2cars-worker:*

# Disable maintenance mode
php artisan up

echo "Deployment complete!"
Save as deploy.sh and make executable:
chmod +x deploy.sh

Security Best Practices

sudo chmod 600 .env
Ensure .env is never committed to version control.
Ensure your web server configuration prevents directory browsing.
composer update
npm update
Regularly update dependencies to patch security vulnerabilities.
Force HTTPS by redirecting all HTTP traffic to HTTPS in your web server configuration.
sudo ufw allow 22/tcp    # SSH
sudo ufw allow 80/tcp    # HTTP
sudo ufw allow 443/tcp   # HTTPS
sudo ufw enable
Automate database and file backups:
# Database backup
mysqldump -u username -p vip2cars > backup_$(date +%Y%m%d).sql

# Files backup
tar -czf vip2cars_$(date +%Y%m%d).tar.gz /var/www/vip2cars

Monitoring and Maintenance

Log Monitoring

# Application logs
tail -f storage/logs/laravel.log

# Nginx logs
tail -f /var/log/nginx/vip2cars-error.log

# Queue worker logs
tail -f storage/logs/worker.log

Clear Caches

If you encounter issues after deployment:
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear

Storage Cleanup

Clean old log files:
find storage/logs -name "*.log" -mtime +30 -delete

Performance Optimization

1

Enable OPcache

Edit /etc/php/8.2/fpm/php.ini:
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.revalidate_freq=2
2

Optimize Composer autoloader

composer dump-autoload --optimize --classmap-authoritative
3

Use Redis for cache and sessions

Update .env:
CACHE_STORE=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis

Troubleshooting

Check permissions:
sudo chmod -R 775 storage bootstrap/cache
sudo chown -R www-data:www-data storage bootstrap/cache
Check logs:
tail -n 50 storage/logs/laravel.log
Check worker status:
sudo supervisorctl status vip2cars-worker:*
Restart workers:
sudo supervisorctl restart vip2cars-worker:*
Recompile assets:
npm run build
Check Vite manifest:
ls -la public/build/manifest.json
Test connection:
php artisan tinker
>>> DB::connection()->getPdo();
Verify credentials in .env and MySQL user permissions.

Zero-Downtime Deployment

For high-traffic applications, consider using Laravel Envoyer or Deployer for zero-downtime deployments with rollback capabilities.
Laravel Envoyer (https://envoyer.io) provides automated zero-downtime deployments with health checks and rollback support.

Rollback Procedure

If deployment fails:
# Revert to previous commit
git reset --hard HEAD~1

# Reinstall dependencies
composer install --optimize-autoloader --no-dev
npm ci && npm run build

# Clear caches
php artisan config:clear
php artisan route:clear
php artisan view:clear

# Rollback migrations (if needed)
php artisan migrate:rollback

# Disable maintenance mode
php artisan up

Conclusion

Your VIP2CARS application is now deployed to production. Monitor logs regularly and keep dependencies updated for optimal security and performance. For additional support, refer to the Laravel documentation or check the application logs for specific error messages.

Build docs developers (and LLMs) love