465 lines
8.7 KiB
Markdown
465 lines
8.7 KiB
Markdown
# JobifyGarden Deployment Guide
|
|
|
|
## Requirements
|
|
|
|
- **PHP**: 8.3.x (minimum)
|
|
- **MySQL**: 8.0+ or MariaDB 10.3+
|
|
- **Composer**: 2.x
|
|
- **Node.js**: 18.x or 20.x
|
|
- **Redis**: 6.x+ (for caching and queues)
|
|
- **Nginx** or **Apache**
|
|
- **Supervisor** (for queue workers)
|
|
|
|
## Server Setup
|
|
|
|
### 1. Install PHP 8.3 and Extensions
|
|
|
|
```bash
|
|
# Ubuntu/Debian
|
|
sudo apt update
|
|
sudo apt install -y php8.3 php8.3-fpm php8.3-cli php8.3-mysql php8.3-redis \
|
|
php8.3-xml php8.3-mbstring php8.3-curl php8.3-zip php8.3-gd \
|
|
php8.3-intl php8.3-bcmath php8.3-opcache
|
|
|
|
# Verify PHP version
|
|
php -v
|
|
# Should show: PHP 8.3.x
|
|
```
|
|
|
|
### 2. Install MySQL
|
|
|
|
```bash
|
|
sudo apt install -y mysql-server
|
|
sudo mysql_secure_installation
|
|
|
|
# Create database
|
|
sudo mysql -u root -p
|
|
CREATE DATABASE jobifygarden CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
CREATE USER 'jobifygarden'@'localhost' IDENTIFIED BY 'your_secure_password';
|
|
GRANT ALL PRIVILEGES ON jobifygarden.* TO 'jobifygarden'@'localhost';
|
|
FLUSH PRIVILEGES;
|
|
EXIT;
|
|
```
|
|
|
|
### 3. Install Redis
|
|
|
|
```bash
|
|
sudo apt install -y redis-server
|
|
sudo systemctl enable redis-server
|
|
sudo systemctl start redis-server
|
|
```
|
|
|
|
### 4. Install Composer
|
|
|
|
```bash
|
|
curl -sS https://getcomposer.org/installer | php
|
|
sudo mv composer.phar /usr/local/bin/composer
|
|
sudo chmod +x /usr/local/bin/composer
|
|
```
|
|
|
|
### 5. Install Node.js
|
|
|
|
```bash
|
|
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
|
sudo apt install -y nodejs
|
|
```
|
|
|
|
## Application Deployment
|
|
|
|
### 1. Clone the Repository
|
|
|
|
```bash
|
|
cd /var/www
|
|
sudo git clone <repository-url> jobifygarden
|
|
sudo chown -R www-data:www-data jobifygarden
|
|
cd jobifygarden
|
|
```
|
|
|
|
### 2. Install Dependencies
|
|
|
|
```bash
|
|
# Install PHP dependencies
|
|
composer install --no-dev --optimize-autoloader
|
|
|
|
# Install Node.js dependencies
|
|
npm ci
|
|
|
|
# Build frontend assets
|
|
npm run build
|
|
```
|
|
|
|
### 3. Configure Environment
|
|
|
|
```bash
|
|
# Copy environment file
|
|
cp .env.example .env
|
|
|
|
# Edit .env file
|
|
nano .env
|
|
```
|
|
|
|
Update the following in `.env`:
|
|
|
|
```env
|
|
APP_NAME=JobifyGarden
|
|
APP_ENV=production
|
|
APP_DEBUG=false
|
|
APP_URL=https://your-domain.com
|
|
|
|
DB_CONNECTION=mysql
|
|
DB_HOST=127.0.0.1
|
|
DB_PORT=3306
|
|
DB_DATABASE=jobifygarden
|
|
DB_USERNAME=jobifygarden
|
|
DB_PASSWORD=your_secure_password
|
|
|
|
CACHE_STORE=redis
|
|
SESSION_DRIVER=redis
|
|
QUEUE_CONNECTION=redis
|
|
|
|
REDIS_HOST=127.0.0.1
|
|
REDIS_PASSWORD=null
|
|
REDIS_PORT=6379
|
|
```
|
|
|
|
### 4. Generate Application Key
|
|
|
|
```bash
|
|
php artisan key:generate
|
|
```
|
|
|
|
### 5. Run Database Migrations
|
|
|
|
```bash
|
|
php artisan migrate --force
|
|
```
|
|
|
|
### 6. Optimize Application
|
|
|
|
```bash
|
|
php artisan config:cache
|
|
php artisan route:cache
|
|
php artisan view:cache
|
|
php artisan event:cache
|
|
```
|
|
|
|
### 7. Set Permissions
|
|
|
|
```bash
|
|
sudo chown -R www-data:www-data storage bootstrap/cache
|
|
sudo chmod -R 775 storage bootstrap/cache
|
|
```
|
|
|
|
## Web Server Configuration
|
|
|
|
### Nginx Configuration
|
|
|
|
Create `/etc/nginx/sites-available/jobifygarden`:
|
|
|
|
```nginx
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name your-domain.com;
|
|
root /var/www/jobifygarden/public;
|
|
|
|
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.3-fpm.sock;
|
|
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
|
include fastcgi_params;
|
|
fastcgi_hide_header X-Powered-By;
|
|
}
|
|
|
|
location ~ /\.(?!well-known).* {
|
|
deny all;
|
|
}
|
|
|
|
# Gzip compression
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_proxied any;
|
|
gzip_comp_level 6;
|
|
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
|
|
}
|
|
```
|
|
|
|
Enable the site:
|
|
|
|
```bash
|
|
sudo ln -s /etc/nginx/sites-available/jobifygarden /etc/nginx/sites-enabled/
|
|
sudo nginx -t
|
|
sudo systemctl reload nginx
|
|
```
|
|
|
|
### Apache Configuration (Alternative)
|
|
|
|
Create `/etc/apache2/sites-available/jobifygarden.conf`:
|
|
|
|
```apache
|
|
<VirtualHost *:80>
|
|
ServerName your-domain.com
|
|
DocumentRoot /var/www/jobifygarden/public
|
|
|
|
<Directory /var/www/jobifygarden/public>
|
|
AllowOverride All
|
|
Require all granted
|
|
</Directory>
|
|
|
|
ErrorLog ${APACHE_LOG_DIR}/jobifygarden_error.log
|
|
CustomLog ${APACHE_LOG_DIR}/jobifygarden_access.log combined
|
|
</VirtualHost>
|
|
```
|
|
|
|
Enable the site:
|
|
|
|
```bash
|
|
sudo a2enmod rewrite
|
|
sudo a2ensite jobifygarden
|
|
sudo systemctl reload apache2
|
|
```
|
|
|
|
## SSL Certificate (Let's Encrypt)
|
|
|
|
```bash
|
|
sudo apt install -y certbot python3-certbot-nginx
|
|
sudo certbot --nginx -d your-domain.com
|
|
```
|
|
|
|
## Queue Worker Setup (Supervisor)
|
|
|
|
Create `/etc/supervisor/conf.d/jobifygarden-worker.conf`:
|
|
|
|
```ini
|
|
[program:jobifygarden-worker]
|
|
process_name=%(program_name)s_%(process_num)02d
|
|
command=php /var/www/jobifygarden/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600
|
|
autostart=true
|
|
autorestart=true
|
|
stopasgroup=true
|
|
killasgroup=true
|
|
user=www-data
|
|
numprocs=4
|
|
redirect_stderr=true
|
|
stdout_logfile=/var/www/jobifygarden/storage/logs/worker.log
|
|
stopwaitsecs=3600
|
|
```
|
|
|
|
Start the workers:
|
|
|
|
```bash
|
|
sudo supervisorctl reread
|
|
sudo supervisorctl update
|
|
sudo supervisorctl start jobifygarden-worker:*
|
|
```
|
|
|
|
## Scheduled Tasks (Cron)
|
|
|
|
Add to crontab for `www-data` user:
|
|
|
|
```bash
|
|
sudo crontab -u www-data -e
|
|
```
|
|
|
|
Add this line:
|
|
|
|
```cron
|
|
* * * * * cd /var/www/jobifygarden && php artisan schedule:run >> /dev/null 2>&1
|
|
```
|
|
|
|
## Database Optimization
|
|
|
|
Run regularly to maintain database performance:
|
|
|
|
```bash
|
|
php artisan db:optimize
|
|
```
|
|
|
|
Consider adding to scheduler in `app/Console/Kernel.php`:
|
|
|
|
```php
|
|
$schedule->command('db:optimize')->weekly();
|
|
```
|
|
|
|
## Monitoring & Maintenance
|
|
|
|
### Clear Caches
|
|
|
|
```bash
|
|
php artisan cache:clear
|
|
php artisan config:clear
|
|
php artisan route:clear
|
|
php artisan view:clear
|
|
```
|
|
|
|
### View Logs
|
|
|
|
```bash
|
|
tail -f storage/logs/laravel.log
|
|
```
|
|
|
|
### Monitor Queue
|
|
|
|
```bash
|
|
php artisan queue:monitor
|
|
```
|
|
|
|
### Database Backup
|
|
|
|
```bash
|
|
# Create backup directory
|
|
mkdir -p /var/backups/jobifygarden
|
|
|
|
# Add to cron (daily at 2 AM)
|
|
0 2 * * * mysqldump -u jobifygarden -p'password' jobifygarden | gzip > /var/backups/jobifygarden/backup-$(date +\%Y\%m\%d).sql.gz
|
|
```
|
|
|
|
## Performance Tuning
|
|
|
|
### PHP-FPM Configuration
|
|
|
|
Edit `/etc/php/8.3/fpm/pool.d/www.conf`:
|
|
|
|
```ini
|
|
pm = dynamic
|
|
pm.max_children = 50
|
|
pm.start_servers = 10
|
|
pm.min_spare_servers = 5
|
|
pm.max_spare_servers = 35
|
|
pm.max_requests = 500
|
|
```
|
|
|
|
### OPcache Configuration
|
|
|
|
Edit `/etc/php/8.3/fpm/conf.d/10-opcache.ini`:
|
|
|
|
```ini
|
|
opcache.enable=1
|
|
opcache.memory_consumption=256
|
|
opcache.interned_strings_buffer=16
|
|
opcache.max_accelerated_files=10000
|
|
opcache.revalidate_freq=0
|
|
opcache.validate_timestamps=0
|
|
```
|
|
|
|
Restart PHP-FPM:
|
|
|
|
```bash
|
|
sudo systemctl restart php8.3-fpm
|
|
```
|
|
|
|
## Security Checklist
|
|
|
|
- [ ] Update `.env` with strong `APP_KEY`
|
|
- [ ] Set `APP_DEBUG=false` in production
|
|
- [ ] Configure firewall (UFW/iptables)
|
|
- [ ] Set up fail2ban for brute force protection
|
|
- [ ] Keep PHP and dependencies updated
|
|
- [ ] Regular security audits: `composer audit`
|
|
- [ ] Monitor error logs regularly
|
|
- [ ] Set up automated backups
|
|
- [ ] Use HTTPS only (redirect HTTP to HTTPS)
|
|
- [ ] Configure proper file permissions
|
|
|
|
## Updating the Application
|
|
|
|
```bash
|
|
cd /var/www/jobifygarden
|
|
|
|
# Enable maintenance mode
|
|
php artisan down
|
|
|
|
# Pull latest code
|
|
git pull origin main
|
|
|
|
# Update dependencies
|
|
composer install --no-dev --optimize-autoloader
|
|
npm ci
|
|
npm run build
|
|
|
|
# Run migrations
|
|
php artisan migrate --force
|
|
|
|
# Clear and rebuild caches
|
|
php artisan config:cache
|
|
php artisan route:cache
|
|
php artisan view:cache
|
|
|
|
# Disable maintenance mode
|
|
php artisan up
|
|
|
|
# Restart queue workers
|
|
sudo supervisorctl restart jobifygarden-worker:*
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Permission Issues
|
|
|
|
```bash
|
|
sudo chown -R www-data:www-data /var/www/jobifygarden
|
|
sudo chmod -R 775 storage bootstrap/cache
|
|
```
|
|
|
|
### Queue Not Processing
|
|
|
|
```bash
|
|
# Check supervisor status
|
|
sudo supervisorctl status
|
|
|
|
# Restart workers
|
|
sudo supervisorctl restart jobifygarden-worker:*
|
|
|
|
# Check worker logs
|
|
tail -f storage/logs/worker.log
|
|
```
|
|
|
|
### Database Connection Issues
|
|
|
|
```bash
|
|
# Test database connection
|
|
php artisan tinker
|
|
>>> DB::connection()->getPdo();
|
|
```
|
|
|
|
### Performance Issues
|
|
|
|
```bash
|
|
# Check slow query log
|
|
php artisan db:monitor
|
|
|
|
# Optimize database
|
|
php artisan db:optimize
|
|
|
|
# Clear all caches
|
|
php artisan optimize:clear
|
|
php artisan optimize
|
|
```
|
|
|
|
## Support
|
|
|
|
For issues and questions, check:
|
|
- Application logs: `storage/logs/laravel.log`
|
|
- Web server logs: `/var/log/nginx/error.log` or `/var/log/apache2/error.log`
|
|
- PHP-FPM logs: `/var/log/php8.3-fpm.log`
|
|
- Supervisor logs: `/var/log/supervisor/supervisord.log`
|
|
|
|
---
|
|
|
|
**Last Updated**: April 4, 2026
|