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
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
Install Node.js dependencies
Use npm ci instead of npm install for faster, more reliable builds in production.
Step 3: Environment Configuration
Edit production settings
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
Run migrations
php artisan migrate --force
The --force flag is required in production environments.
Seed data (optional)
Only run seeders if you need test data. Production systems typically don’t use seeders.
Step 5: Compile Assets
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
Cache configuration
Caches all configuration files into a single file for faster loading.
Cache routes
Compiles all routes into a single cached file.
Cache views
Pre-compiles all Blade templates.
Cache events
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 ;
}
}
Enable the site
sudo ln -s /etc/nginx/sites-available/vip2cars /etc/nginx/sites-enabled/
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 >
Enable the site
sudo a2ensite vip2cars.conf
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
Read configuration
sudo supervisorctl reread
Update Supervisor
sudo supervisorctl update
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.
Open crontab
sudo crontab -e -u www-data
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:
Security Best Practices
1. Environment File Security
Ensure .env is never committed to version control.
2. Disable Directory Listing
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.
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
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
Optimize Composer autoloader
composer dump-autoload --optimize --classmap-authoritative
Use Redis for cache and sessions
Update .env: CACHE_STORE = redis
SESSION_DRIVER = redis
QUEUE_CONNECTION = redis
Troubleshooting
500 Internal Server Error
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
Queue Jobs Not Processing
Check worker status: sudo supervisorctl status vip2cars-worker: *
Restart workers: sudo supervisorctl restart vip2cars-worker: *
Recompile assets: Check Vite manifest: ls -la public/build/manifest.json
Database Connection Failed
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.