# MTEngine — Installation Guide

## Before You Begin

Make sure your server meets the requirements:

- PHP 8.1 or higher
- MySQL 5.7+ or MariaDB 10.4+
- Apache with `mod_rewrite` enabled
- PHP extensions: `PDO`, `PDO_MySQL`, `mbstring`, `json`, `curl`, `fileinfo`, `gd`

---

## Step 1 — Download & Upload Files

1. Download the MTEngine package from your purchase platform
2. Extract the ZIP file on your computer
3. Upload **all files** to your web server via FTP/SFTP or your hosting file manager
   - If installing to the root: upload to `public_html/` or `www/`
   - If installing to a subdirectory: upload to `public_html/myshop/`

> **Important:** Make sure hidden files are uploaded too, especially `.htaccess` and `.env.example`

---

## Step 2 — Create Database

1. Log in to your hosting control panel (cPanel, DirectAdmin, etc.)
2. Go to **MySQL Databases**
3. Create a new database (e.g. `mysite_db`)
4. Create a new database user with a strong password
5. Assign the user to the database with **ALL PRIVILEGES**
6. Note down: host, database name, username, password

---

## Step 3 — Set File Permissions

Via SSH or your file manager, set the following permissions:

```bash
# Directories that need write access
chmod 755 storage/
chmod 755 storage/cache/
chmod 755 storage/credentials/
chmod 755 storage/queue/
chmod 755 storage/settings/
chmod 755 uploads/
chmod 755 public/uploads/

# The .env file should not be world-readable
chmod 640 .env
```

---

## Step 4 — Run the Installer

1. Open your browser and go to: `https://yourdomain.com/install/`
2. Follow the step-by-step wizard:
   - **Step 1** — Choose language
   - **Step 2** — Requirements check
   - **Step 3** — Database connection — enter your DB credentials here. The installer writes `.env` automatically. You do **not** need to edit `.env` manually.
   - **Step 4** — SQL import
   - **Step 5** — Create admin account
   - **Step 6** — License activation (enter the key from your purchase email)
   - **Step 7** — Done

> **Shared hosting note:** If your hosting plan does not allow creating databases via script, create the database manually in cPanel first, then enter its name in Step 3 of the installer.

The installer will automatically:
- Write your `.env` configuration file
- Import the database schema
- Create required directories
- Write your license credentials
- Create the `storage/installed.lock` file (blocks future installer access)

---

## Step 5 — Log In to Admin Panel

1. Go to: `https://yourdomain.com/admin`
2. Log in using the admin credentials you created during the installation wizard.

---

## Step 6 — Basic Configuration

After logging in, complete these steps in the admin panel:

1. **Settings → Site Identity** — Upload your logo, set site name and description
2. **Settings → Basic Settings** — Set currency, contact info, WhatsApp number
3. **Settings → Shipping** — Configure your shipping provider(s)
4. **Products → Add Product** — Create your first product

---

## Step 8 — Secure Your Installation

1. **Change the default admin password** immediately via Profile → Change Password
2. Verify the `/install` directory is blocked (the lock file does this automatically)
3. Make sure `APP_DEBUG=false` in your `.env` file
4. Ensure `storage/` directory is not web-accessible (the `.htaccess` inside handles this)

---

## Troubleshooting

### Blank page or 500 error
- Temporarily set `APP_DEBUG=true` in `.env` to see error details
- Check your server's PHP error log
- Make sure `.htaccess` is uploaded and `mod_rewrite` is enabled

### Installer not loading
- Check that `storage/installed.lock` does not exist
- Make sure PHP can write to the `storage/` directory

### Database connection error
- Double-check your `.env` credentials
- Make sure the database user has ALL PRIVILEGES on the database
- Some hosts use `127.0.0.1` instead of `localhost` for `DB_HOST`

### Images not uploading
- Check that `uploads/` and `public/uploads/` are writable (chmod 755)
- Check your PHP `upload_max_filesize` and `post_max_size` settings

### .htaccess not working
- Make sure `AllowOverride All` is set in your Apache virtual host config
- On cPanel hosts, this is usually enabled by default

---

## After Installation

- See **[UPGRADE.md](UPGRADE.md)** for how to update to future versions
- See **[FAQ.md](FAQ.md)** for common questions
- See **[CHANGELOG.md](CHANGELOG.md)** for what changed in this version
