Deploy Statamic with DeployHQ

Prerequisites

  • PHP 8.1 or higher
  • Composer installed globally
  • Statamic CLI installed globally
  • A Git repository (GitHub, GitLab, or Bitbucket)
  • A web server with Nginx

Initial Setup

1. Install Statamic CLI

# Install Statamic CLI globally
composer global require statamic/cli

2. Create New Statamic Site

# Navigate to web directory
cd /var/www

# Create new Statamic site
statamic new example.com

# If you encounter TTY errors, use:
script -q -c "statamic new --no-interaction example.com"

3. Set Permissions

sudo chmod -R 755 /var/www/example.com
sudo chown -R www-data:www-data /var/www/example.com
sudo chown -R www-data:www-data /var/www/example.com/storage
sudo chown -R www-data:www-data /var/www/example.com/content
sudo chown -R www-data:www-data /var/www/example.com/bootstrap/cache

4. Initialize Git Repository

cd /var/www/example.com
git init
git add .
git commit -m "Initial commit"
git remote add origin <your-repository-url>
git push -u origin main

Server Setup

1. Install and Configure Nginx

sudo apt install nginx -y

2. Create Nginx Configuration

Create /etc/nginx/sites-available/example.com:

server {
    listen 80;
    server_name example.com;
    root /var/www/example.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    set $try_location @static;

    if ($request_method != GET) {
        set $try_location @not_static;
    }

    if ($args ~* "live-preview=(.*)") {
        set $try_location @not_static;
    }

    location / {
        try_files $uri $try_location;
    }

    location @static {
        try_files /static${uri}_$args.html $uri $uri/ /index.php?$args;
    }

    location @not_static {
        try_files $uri /index.php?$args;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

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

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

DeployHQ Configuration

1. Create DeployHQ Account

  • Visit DeployHQ website
  • Sign up for a new account

2. Create New Project

  • Click "New Project"
  • Connect your Git repository
  • Configure repository access

3. Configure Server

  • Add new server in DeployHQ
  • Configure SFTP/SSH access
  • Set deployment path to /var/www/example.com

4. Configure Build Pipeline

# Install dependencies
composer install --no-dev --optimize-autoloader

# Clear and cache
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Build assets (if using)
npm install
npm run build

5. Configure Shared Directories

Set up shared paths:

storage/app/public
storage/framework/cache
storage/framework/sessions
storage/framework/views
storage/logs
.env

6. Deployment Rules

# Include
public/**/*
app/**/*
config/**/*
resources/**/*
content/**/*
storage/framework/views/**/*

# Exclude
node_modules/**/*
.env
.git/**/*
tests/**/*

First Deployment

1. Environment Setup

  • Create .env file on server
  • Configure environment variables
  • Set up database credentials

2. Initial Deployment

  • Run first deployment from DeployHQ
  • Monitor deployment logs
  • Verify file permissions

3. Post-Deployment Tasks

php artisan storage:link
php artisan config:cache
php artisan route:cache
php artisan view:cache

Ongoing Maintenance

1. Regular Updates

git add .
git commit -m "Update content"
git push origin main

2. Maintenance Tasks

  • Monitor logs
  • Update dependencies
  • Backup content and database
  • Clear caches when needed

Troubleshooting

  • Permission Issues: Verify www-data ownership
  • Nginx Configuration: Check nginx -t
  • PHP-FPM Socket: Verify PHP version in Nginx config
  • Cache Issues: Clear various caches
  • Static Asset Delivery: Check public directory permissions

Security Best Practices

  • Use HTTPS
  • Implement proper file permissions
  • Regular security updates
  • Secure control panel access
  • Configure environment variables
  • Regular backups
  • Rate limiting
  • Firewall configuration

Note: Adjust settings based on your specific needs and server environment.


Want to learn more about deployment or Wordpress? Check out our documentation or contact our support team for assistance.