Deploy Directus with DeployHQ Guide
Prerequisites
- A Directus project ready for deployment
- A Git repository (GitHub, GitLab, or Bitbucket) containing your Directus project
- A web hosting service or server to deploy to
- Node.js installed on your local machine and server
- Database (PostgreSQL, MySQL, SQLite, etc.)
Initial Setup
1. Create your Directus project
# Install Directus CLI
npm init directus-project@latest my-project
# Navigate to project
cd my-project
# Install dependencies
npm install
# Configure environment variables
cp .env.example .env
# If you want to start it locally
npx directus start
Edit your .env
file with appropriate values:
DB_CLIENT="pg"
DB_HOST="127.0.0.1"
DB_PORT="5432"
DB_DATABASE="directus"
DB_USER="directus"
DB_PASSWORD="directus"
ADMIN_EMAIL="admin@example.com"
ADMIN_PASSWORD="d1r3ctu5"
KEY="random-string"
SECRET="random-string"
2. Initialize Git repository
git init
git add .
git commit -m "Initial commit"
git remote add origin <your-repository-url>
git push -u origin main
DeployHQ Configuration
1. Create DeployHQ Account
- Visit DeployHQ
- Sign up for a new account
2. Create New Project
- Click "New Project" in DeployHQ dashboard
- Choose a name for your project
- Select your repository provider (GitHub/GitLab/Bitbucket)
- Grant repository access when prompted
3. Configure Server
- Click "Servers & Groups" in project settings
- Select "Add Server"
- Choose your server type (SFTP/SSH recommended)
- Enter server details:
- Server name
- Hostname
- Username
- Password/SSH key
- Remote path (where files will be deployed)
4. Configure Build Pipeline
- Go to "Build Pipeline" in project settings
- Click "Add New Pipeline Command"
- Add the following commands:
# Install Node.js dependencies
npm install
# Build Directus (if needed)
npm run build
# Add any custom build steps here
5. Configure Deployment
- Go to "Deployment Config"
- Configure included/excluded files:
# Include
dist/**/*
node_modules/**/*
extensions/**/*
migrations/**/*
# Exclude
.env
.git/**/*
.github/**/*
.vscode/**/*
6. Set Up Environment Variables
- Go to "Environment Config"
- Add all necessary environment variables from your
.env
file - Make sure to set production-appropriate values
7. Set Up Automatic Deployments
- Go to "Automatic Deployments"
- Enable automatic deployments for your branch (usually
main
) - Configure deployment triggers (e.g., on push)
First Deployment
1. Database Setup
- Ensure your production database is created and configured
- Run initial migrations:
npm run cli migrate:latest
You can leave this command as a SSH Command and it will run every time. If there are no migrations, the command will end without errors
2. Manual Deployment
- Go to "Deployments" in project dashboard
- Click "Deploy Now"
- Select branch to deploy
- Review changes and confirm
3. Verify Deployment
- Check deployment logs for any errors
- Visit your Directus admin panel
- Verify API endpoints are working
- Check database connections
Ongoing Usage
1. Regular Updates
# Make changes to your project
git add .
git commit -m "Update project"
git push origin main
2. Monitor Deployments
- Check DeployHQ dashboard for deployment status
- Review logs for any issues
- Configure notifications for deployment events
Troubleshooting
- Build Failures: Check Node.js and npm errors
- Database Issues: Verify database connection and migrations
- Permission Issues: Check file permissions and ownership
- API Issues: Verify environment variables and endpoints
- Memory Issues: Monitor Node.js memory usage
Best Practices
- Use environment variables for all sensitive information
- Implement staging environments for testing
- Regular database backups
- Monitor server resources
- Keep Directus and dependencies updated
- Use PM2 or similar for process management
- Implement proper caching strategies
- Set up proper logging
Production Considerations
1. Process Management
# Install PM2 globally
npm install -g pm2
# Start Directus with PM2
pm2 start npm --name "directus" -- start
2. Nginx Configuration Example
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:8055;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
3. SSL Configuration
- Install SSL certificate
- Configure HTTPS in Nginx
- Update Directus environment variables for HTTPS
This guide provides a comprehensive approach to deploying Directus using DeployHQ. Adjust configurations based on your specific needs and hosting environment. Remember to follow security best practices and keep your system updated.