# 🚀 SAFMS Deployment Guide for Hostinger

## 📋 Prerequisites

- Hostinger hosting account with PHP 8.2+ support
- MySQL database access
- Domain name (or subdomain)
- FTP access or File Manager access

## 🛠️ Step-by-Step Deployment

### Step 1: Prepare Your Local Project

1. **Build frontend assets**:
```bash
npm install
npm run build
```

2. **Create deployment package**:
   - Exclude `node_modules/`, `vendor/`, `.git/`
   - Include all other files and folders

### Step 2: Hostinger Setup

1. **Login to Hostinger Control Panel**
2. **Create MySQL Database**:
   - Go to "Databases" → "MySQL Databases"
   - Create a new database
   - Note down: Database name, Username, Password

3. **Upload Files**:
   - Use File Manager or FTP
   - Upload to `public_html/` directory
   - **Important**: Set document root to `public_html/public/`

### Step 3: Environment Configuration

1. **Create `.env` file** in root directory:
```bash
# Copy from env-template.txt and update with your values
APP_NAME=SAFMS
APP_ENV=production
APP_KEY=base64:YOUR_GENERATED_KEY_HERE
APP_DEBUG=false
APP_URL=https://yourdomain.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_hostinger_db_name
DB_USERNAME=your_hostinger_db_user
DB_PASSWORD=your_hostinger_db_password

VITE_BACKEND_URL=https://yourdomain.com
VITE_APP_URL=https://yourdomain.com
```

### Step 4: Server Commands

Run these commands via Hostinger's Terminal or SSH:

```bash
# Install dependencies
composer install --optimize-autoloader --no-dev

# Set permissions
chmod -R 755 storage/
chmod -R 755 bootstrap/cache/

# Generate application key
php artisan key:generate

# Run migrations
php artisan migrate --force

# Create storage link
php artisan storage:link

# Cache for production
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

### Step 5: File Structure

Ensure your file structure looks like this:
```
public_html/
├── app/
├── bootstrap/
├── config/
├── database/
├── public/          # Document root
├── resources/
├── routes/
├── storage/
├── vendor/
├── .env
├── artisan
└── composer.json
```

## 🔧 Common Issues & Solutions

### Issue 1: 500 Internal Server Error
**Solution**: Check file permissions and `.env` configuration

### Issue 2: Database Connection Error
**Solution**: Verify database credentials in `.env`

### Issue 3: Assets Not Loading
**Solution**: Ensure `npm run build` was executed and assets are in `public/build/`

### Issue 4: Storage Links Not Working
**Solution**: Run `php artisan storage:link` and check permissions

## 📞 Hostinger Support

If you encounter issues:
1. Check Hostinger's PHP version (must be 8.2+)
2. Verify MySQL database access
3. Contact Hostinger support for server-specific issues

## 🎯 Post-Deployment Checklist

- [ ] Website loads without errors
- [ ] Database migrations completed
- [ ] User registration works
- [ ] File uploads work
- [ ] Email functionality works
- [ ] Admin panel accessible
- [ ] API endpoints responding

## 🔒 Security Recommendations

1. **Set `APP_DEBUG=false`** in production
2. **Use HTTPS** for all URLs
3. **Regular backups** of database and files
4. **Keep Laravel updated** for security patches

## 📊 Performance Tips

1. **Enable OPcache** if available
2. **Use CDN** for static assets
3. **Optimize images** before upload
4. **Monitor server resources**

---

**Need Help?** Check the Laravel documentation or Hostinger's support resources. 