## Table of Contents

- [What is Continuous Deployment?](#what-is-continuous-deployment)
- [Why Use DeployHQ with Grav?](#why-use-deployhq-with-grav)
- [Prerequisites](#prerequisites)
- [Setting Up DeployHQ](#setting-up-deployhq)
- [Configuring Your Project](#configuring-your-project)
- [Deployment Configuration](#deployment-configuration)
- [Advanced Features](#advanced-features)
- [Best Practices](#best-practices)

## What is Continuous Deployment?

Continuous Deployment (CD) is an automated software release process where code changes are automatically deployed to production after passing automated testing. DeployHQ facilitates this process by providing a robust platform for automated deployments.

## Why Use DeployHQ with Grav?

- **Simple Setup**: DeployHQ offers straightforward integration with various version control systems
- **Automated Deployments**: Automatically deploy changes when you push to your repository
- **Built-in Build Tools**: Compile assets and run commands during deployment
- **Multiple Server Support**: Deploy to multiple servers with different configurations
- **Rollback Capability**: Easily revert to previous deployments if issues arise

## Prerequisites

1. A [Grav](https://getgrav.org/) website
2. Git repository (GitHub, Bitbucket, or GitLab)
3. SSH access to your server
4. DeployHQ account

## Setting Up DeployHQ

### 1. Create an Account

```markdown
1. Visit deployhq.com
2. Sign up for a new account
3. Verify your email address
```

### 2. Connect Your Repository

```markdown
1. Go to "New Project" in DeployHQ
2. Select your repository provider (GitHub, Bitbucket, or GitLab)
3. Authorize DeployHQ to access your repositories
4. Select your Grav website repository
```

### 3. Configure Server Details

```markdown
1. Navigate to "Servers" in your project
2. Click "New Server"
3. Enter your server details:
   - Server name
   - Protocol (SFTP/SSH)
   - Hostname
   - Port
   - Username
   - Authentication method (Password or SSH Key)
4. Set deployment path
```

## Configuring Your Project

### 1. Branch Configuration

```yaml
# Example branch configuration
Production:
  branch: main
  auto_deploy: true

Staging:
  branch: develop
  auto_deploy: true
```

### 2. Build Commands

```bash
# Example build configuration for Grav
npm install
npm run build
composer install --no-dev
```

### 3. Deployment Config File

Create a `deploybuild.yml` in your repository:

```yaml
# deploybuild.yml
build_languages:
  - name: "node"
    version: "18"
  - name: "php"
    version: "8.0"

build_commands:
  - description: "Install NPM Dependencies"
    command: "npm install \n npm run build"
    halt_on_error: true
  - description: "Install Composer Dependencies"
    command: "composer install --no-dev"
    halt_on_error: true

build_cache_files:
  - path: node_modules/**
```

## Deployment Configuration

### 1. Setting Up Automatic Deployments

```markdown
1. Go to Project Settings > Automatic Deployments
2. Enable "Automatic Deployments"
3. Select branches to trigger deployments
```

### 2. Configure Deploy Hook

```bash
# Example Deploy Hook URL
https://[account].deployhq.com/deploy/[project]/[token]
```

### 3. Required Config Files

```markdown
1. Navigate to Project Settings > Config Files
2. Add a file that contains:
   - GRAV_ENV=production
   - API_KEY=your_api_key
```

## Advanced Features

### 1. Custom Deploy Scripts

```bash
#!/bin/bash
# deploy-script.sh
php bin/grav clear-cache
php bin/gpm update
```

### 2. Health Checks

```yaml
# Health check configuration
health_check:
  url: https://yoursite.com/health
  expected_status: 200
  timeout: 30
```

### 3. Notifications

```markdown
1. Configure Slack notifications
2. Set up email alerts
3. Enable webhook notifications
```

## Best Practices

### 1. Security

```markdown
- Use SSH keys instead of passwords
- Implement IP whitelisting
- Regular security audits
```

### 2. Deployment Strategy

```markdown
1. Use staging environments
2. Implement health checks
3. Configure automatic rollbacks
4. Set up notification alerts
```

### 3. Maintenance

```markdown
- Regular backup verification
- Log monitoring
- Performance tracking
```

This guide provides a foundation for setting up [Continuous Deployment](https://www.deployhq.com/blog/what-is-continuous-deployment) for your Grav website using DeployHQ. Adjust the configurations based on your specific needs and requirements.

----------

_Want to learn more about deployments or Wordpress? Check out our [documentation](https://www.deployhq.com/support) or [contact our support team](https://www.deployhq.com/contact) for assistance._