# Setup Environment Script

This script allows you to set up your environment variables directly by creating a .env file from a template file. It will search for a template file in multiple locations:

1. `/storage/master_data/config_env.sample`
2. `/.env.example`
3. `/storage/app/config_env.sample`
4. `/storage/config_env.sample`

## Troubleshooting

If the script is not creating the .env file, please check the following:

1. Make sure you're running the script from the project root directory
2. Check that one of the template files exists (listed above)
3. Ensure you have write permissions to the directory
4. If there's an existing .env file, rename or remove it first

Two setup options are provided:

## Option 1: Direct PHP Script (Recommended)

The simplest approach is to use the direct PHP script:

```bash
php setup-environment.php --app_url=https://your-domain.com --db_database=your_db --db_username=your_username --db_password=your_password --app_debug=false --app_env=development
```

## Option 2: Helper Scripts

### Windows (PowerShell)

```powershell
.\setup-environment.ps1 -app_url "https://your-domain.com" -db_database "your_db" -db_username "your_username" -db_password (ConvertTo-SecureString "your_password" -AsPlainText -Force) -app_debug "false" -app_env "development"
```

### Linux/macOS (Bash)

```bash
./setup-environment.sh --app_url=https://your-domain.com --db_database=your_db --db_username=your_username --db_password=your_password --app_debug=false --app_env=development
```

### For Production Servers

For your production server, make sure to set the execution permissions:

```bash
chmod +x setup-environment.sh
./setup-environment.sh --app_url=https://your-domain.com --db_database=your_db --db_username=your_username --db_password=your_password --app_debug=false --app_env=production
```

### Available Parameters

- `--app_url`: The application URL (default: https://your-production-domain.com)
- `--db_database`: The database name (default: wecarecloud)
- `--db_username`: The database username (default: your_db_username)
- `--db_password`: The database password (default: your_db_password)
- `--app_debug`: The debug mode, set to true or false (default: false)
- `--app_env`: The application environment, like development, production, etc. (default: production)

### Example Commands

**Production Setup:**
```bash
php setup-environment.php --app_url=https://wecarecloud.com --db_database=wecarecloud_prod --db_username=prod_user --db_password="secure_password" --app_debug=false --app_env=production
```

**Development Setup:**
```bash
php setup-environment.php --app_url=http://localhost:8000 --db_database=wecarecloud_dev --db_username=dev_user --db_password="dev_password" --app_debug=true --app_env=development
```

## Notes

- This script will only create an `.env` file if one doesn't exist.
- All parameters are optional. If not provided, default values will be used.
- The script will display the values being used for each parameter.
