# Cozy Corner Shkodër — Setup Guide

## Requirements

- PHP 8.1+ with extensions: `pdo_mysql`, `curl`, `gd` (or `imagick`), `mbstring`, `intl`
- MySQL 8.0+ (or MariaDB 10.6+)
- Apache 2.4+ or Nginx (or PHP built-in server for local dev)

---

## 1. Database

```bash
# Create database and import schema + seed data
mysql -u root -p -e "CREATE DATABASE cozy_corner CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql -u root -p cozy_corner < database/schema.sql
mysql -u root -p cozy_corner < database/seed.sql
```

Create a dedicated MySQL user (recommended for production):

```sql
CREATE USER 'cozy_corner'@'localhost' IDENTIFIED BY 'strong-password-here';
GRANT ALL PRIVILEGES ON cozy_corner.* TO 'cozy_corner'@'localhost';
FLUSH PRIVILEGES;
```

---

## 2. Environment Configuration

```bash
cp .env.example .env
```

Edit `.env` and fill in every value:

| Key | Example | Notes |
|-----|---------|-------|
| `APP_URL` | `https://cozycornershkoder.com` | No trailing slash |
| `APP_KEY` | 32-char random string | `openssl rand -hex 16` |
| `DB_HOST` | `127.0.0.1` | |
| `DB_NAME` | `cozy_corner` | |
| `DB_USER` | `cozy_corner` | |
| `DB_PASS` | `…` | |
| `SMTP_HOST` | `smtp.gmail.com` | |
| `SMTP_PORT` | `587` | |
| `SMTP_USER` | `your@gmail.com` | |
| `SMTP_PASS` | `app-password` | Use Gmail App Password |
| `MAIL_FROM` | `noreply@cozycornershkoder.com` | |

---

## 3. Web Server

### Option A — Apache

Enable `mod_rewrite` and point `DocumentRoot` to the `public/` directory.

```apache
<VirtualHost *:80>
    ServerName cozycornershkoder.com
    DocumentRoot /var/www/cozy-corner/public

    <Directory /var/www/cozy-corner/public>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
```

The `public/.htaccess` is already included and handles the front-controller rewrite.

### Option B — PHP Built-in Server (local dev only)

```bash
php -S localhost:8000 server.php
```

Then open `http://localhost:8000`.

### Option C — Nginx

```nginx
server {
    listen 80;
    server_name cozycornershkoder.com;
    root /var/www/cozy-corner/public;
    index index.php;

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

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

---

## 4. File Permissions

```bash
chmod -R 755 public/uploads
chown -R www-data:www-data public/uploads
```

---

## 5. First Login

1. Navigate to `http://your-domain/admin`
2. Log in with:
   - **Email:** `admin@cozycornershkoder.com`
   - **Password:** `CozyAdmin2026!`
3. **Immediately** go to Settings → My Account and change your password.

---

## 6. iCal Two-Way Sync

### Get your export URL

In the Admin → Settings → Calendar Sync tab, copy your iCal export URL. It looks like:

```
https://your-domain/ical/YOUR_SECRET_TOKEN
```

### Airbnb

1. Go to Airbnb → Hosting → Calendar → Availability settings → Export calendar
2. Copy the `.ics` URL Airbnb gives you
3. Paste it in Admin → Settings → Calendar Sync → **Airbnb iCal export URL**
4. Give Airbnb your export URL: in Airbnb calendar → Import calendar → paste your URL

### Booking.com

1. Go to Booking.com Extranet → Rates & Availability → Export calendar
2. Copy the iCal export link
3. Paste it in Admin → Settings → Calendar Sync → **Booking.com iCal export URL**
4. In Booking.com → Import calendar → paste your export URL

### Automated sync (cron)

Add this to your server's crontab (`crontab -e`):

```cron
*/15 * * * * php /var/www/cozy-corner/scripts/sync-ical.php >> /var/log/cozy-corner-ical.log 2>&1
```

This syncs every 15 minutes. Logs go to `/var/log/cozy-corner-ical.log`.

---

## 7. PayPal

### Sandbox (testing)

1. Create a PayPal Developer account at developer.paypal.com
2. Create a sandbox app → copy **Client ID** and **Secret**
3. Admin → Settings → Payments → PayPal → set Mode to **Sandbox**, paste credentials
4. Test payments using PayPal sandbox buyer accounts

### Going Live

1. In the same PayPal Developer dashboard, switch to **Live** tab → create a live app
2. Admin → Settings → Payments → PayPal → set Mode to **Live**, paste live credentials
3. Ensure `APP_URL` in `.env` is your real HTTPS domain

---

## 8. Production Checklist

- [ ] Set `APP_ENV=production` and `APP_DEBUG=false` in `.env`
- [ ] Enable HTTPS — get a free certificate via Let's Encrypt (`certbot --apache`)
- [ ] Add HSTS header in Apache/Nginx config
- [ ] Build compiled Tailwind CSS (removes Play CDN from views first):
  ```bash
  npm install
  npm run build
  ```
  Then update `app/Views/partials/head.php` to load `tailwind.css` instead of the Play CDN script.
- [ ] Set up the iCal cron job (see step 6)
- [ ] Configure SMTP for real email delivery
- [ ] Upload your own gallery photos via Admin → Media
- [ ] Fill in all Settings tabs: pricing, contact, social links, bank details
- [ ] Change admin password
- [ ] Run `OPTIMIZE TABLE` on your MySQL tables after initial seeding

---

## 9. Backup

```bash
# Daily database backup (add to cron)
mysqldump -u cozy_corner -p cozy_corner | gzip > /backups/cozy-corner-$(date +%F).sql.gz

# Uploaded media
rsync -az /var/www/cozy-corner/public/uploads/ /backups/uploads/
```

---

## Directory Structure

```
cozy corner shkoder/
├── app/
│   ├── bootstrap.php          # Autoloader, env, session start
│   ├── config/config.php
│   ├── Controllers/           # HomeController, PaymentController, BlogController…
│   ├── Core/                  # Router, Database, Auth, Session, Csrf
│   ├── Models/                # Booking, Review, Post, Setting…
│   ├── Services/              # ICalService, PricingService, PayPalService…
│   ├── Views/                 # PHP templates
│   └── routes.php
├── database/
│   ├── schema.sql
│   └── seed.sql
├── public/                    # Web root (DocumentRoot points here)
│   ├── index.php              # Front controller
│   ├── .htaccess
│   ├── assets/
│   │   ├── css/custom.css
│   │   ├── js/booking.js
│   │   └── img/
│   └── uploads/               # User-uploaded media (writable)
├── scripts/
│   └── sync-ical.php          # Cron iCal sync
├── server.php                 # PHP built-in server router
├── tailwind.config.js
├── package.json
├── .env.example
└── SETUP.md
```
