Local Execution Setup Guide
This guide will help you set up Flowguard to execute flows on your own server instead of using the cloud-based execution service.
Why Use Local Execution?
Running Flowguard locally on your server provides several benefits:
- Privacy: All test data stays on your server
- Performance: Lower latency for flow executions
- Control: Full control over the execution environment
- Cost: No dependency on external services
Prerequisites
Before you begin, ensure your server meets these requirements:
- Node.js version 18.0.0 or higher
- npm version 8.0.0 or higher
- Sufficient disk space for Playwright browsers (~500MB)
- Server access to install packages and run Node.js processes
Step-by-Step Setup
1. Install Node.js
If Node.js is not already installed on your server:
Ubuntu/Debian
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejsCentOS/RHEL
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
sudo yum install -y nodejsmacOS (using Homebrew)
brew install nodeVerify the installation:
node --version
npm --version2. Copy the API Directory
Copy the Flowguard API directory to a location on your server:
# Example: Copy from plugin directory to a custom location
cp -r /path/to/wordpress/wp-content/plugins/flowguard/api /var/www/flowguard-apiNote: You can place the API directory anywhere on your server. Make sure the directory is readable and executable by your web server user.
3. Install Dependencies
Navigate to the API directory and install the required npm packages:
cd /var/www/flowguard-api
npm installThis will install:
- express - Web server framework
- playwright - Browser automation library
- axios - HTTP client
- dotenv - Environment variable management
4. Install Playwright Browsers
Playwright requires browser binaries to be installed:
npx playwright installThis downloads and installs Chromium, Firefox, and WebKit browsers.
For headless servers, you may need to install additional system dependencies:
# Ubuntu/Debian
npx playwright install-deps
# Or manually
sudo apt-get install -y \
libnss3 \
libnspr4 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libdbus-1-3 \
libxkbcommon0 \
libatspi2.0-0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libpango-1.0-0 \
libcairo2 \
libasound25. Configure Environment (Optional)
Create a .env file in the API directory to customize settings:
cd /var/www/flowguard-api
nano .envAdd the following configuration:
# Server Configuration
PORT=3000
HOST=localhost
NODE_ENV=production
# Flow Configuration
FLOW_TIMEOUT=300000Configuration Options:
| Variable | Description | Default |
|---|---|---|
PORT | Port number for the API server | 3000 |
HOST | Hostname to bind to | localhost |
NODE_ENV | Environment mode | development |
FLOW_TIMEOUT | Maximum time for flow execution (ms) | 300000 (5 min) |
6. Start the Server
You have several options for starting the server:
Local API vs Full API
The plugin bundles a minimal Local API that only includes flow execution capabilities. It uses server-local.js as the entry point with fewer dependencies. This is different from the full API which includes monitoring, database, and other features.
Option A: Manual Start (for testing)
cd /var/www/flowguard-api
npm startPress Ctrl+C to stop the server.
Option B: Background Process with PM2 (Recommended)
PM2 is a production process manager for Node.js applications.
Install PM2 globally:
sudo npm install -g pm2Start the server with PM2:
cd /var/www/flowguard-api
pm2 start npm --name flowguard-api -- startUseful PM2 commands:
pm2 status # Check server status
pm2 logs flowguard-api # View logs
pm2 restart flowguard-api # Restart server
pm2 stop flowguard-api # Stop server
pm2 delete flowguard-api # Remove from PM2Make PM2 start on system boot:
pm2 startup
pm2 saveOption C: systemd Service (Linux)
Create a systemd service file:
sudo nano /etc/systemd/system/flowguard-api.serviceAdd the following configuration:
[Unit]
Description=Flowguard API Server
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/flowguard-api
ExecStart=/usr/bin/npm start
Restart=on-failure
RestartSec=10
Environment=NODE_ENV=production
Environment=PORT=3000
[Install]
WantedBy=multi-user.targetEnable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable flowguard-api
sudo systemctl start flowguard-apiCheck status:
sudo systemctl status flowguard-apiView logs:
sudo journalctl -u flowguard-api -f7. Verify Server is Running
Test the health endpoint:
curl http://localhost:3000/healthYou should see a response like:
{"status":"ok","timestamp":"2024-12-09T10:30:45.123Z"}8. Configure WordPress Plugin
- Log in to your WordPress admin panel
- Navigate to Flowguard > Settings
- Click on the Execution tab
- Select Local API as the execution mode
- Enter the API directory path:
/var/www/flowguard-api - Enter the port number:
3000(or your custom port) - Enter the host:
localhost - Click Check Requirements
The system will verify:
- Node.js is installed
- npm is installed
- API directory exists
- package.json is valid
- All npm packages are installed
- Playwright browsers are installed
- Local server is running
If all requirements are met, you'll see a success message and can start running flows locally!
Troubleshooting
Server Won't Start
Error: Port 3000 is already in use
Solution: Either stop the other process using port 3000, or change the port in your .env file and WordPress settings.
# Check what's using port 3000
sudo lsof -i :3000
# Use a different port
echo "PORT=3001" >> .envBrowser Launch Fails
Error: browserType.launch: Executable doesn't exist
Solution: Reinstall Playwright browsers:
cd /var/www/flowguard-api
npx playwright install --force
npx playwright install-depsPermission Errors
Error: EACCES: permission denied
Solution: Ensure the API directory has correct permissions:
sudo chown -R www-data:www-data /var/www/flowguard-api
sudo chmod -R 755 /var/www/flowguard-apiWordPress Can't Connect to Server
Error: Failed to connect to local API server
Solutions:
Verify the server is running:
bashcurl http://localhost:3000/healthCheck firewall settings (server should be accessible from localhost)
Review server logs:
bash# If using PM2 pm2 logs flowguard-api # If using systemd sudo journalctl -u flowguard-api -n 50
Server Crashes During Flow Execution
Cause: Insufficient memory or resources
Solution: Increase memory limits and optimize:
# Increase Node.js memory limit
node --max-old-space-size=4096 src/server.js
# Or in PM2
pm2 start src/server.js --name flowguard-api --max-memory-restart 1GSecurity Considerations
Local Network Only
By default, the API server only binds to localhost, meaning it's only accessible from the same machine. This is the recommended configuration.
DANGER
Never expose the API server to the public internet without proper authentication!
Firewall Configuration
If you need to access the API from a different server, use SSH tunneling instead of opening ports:
ssh -L 3000:localhost:3000 user@your-server.comProcess Isolation
Consider running the API server under a dedicated user account with limited permissions:
sudo useradd -r -s /bin/false flowguard
sudo chown -R flowguard:flowguard /var/www/flowguard-apiUpdate your systemd service or PM2 configuration to use this user.
Performance Optimization
Browser Reuse
The API server reuses browser instances when possible to improve performance. Browser contexts are created fresh for each flow execution.
Concurrent Flows
The server can handle multiple flow executions concurrently. The default limit is based on available system resources.
Resource Cleanup
Failed or cancelled flows automatically clean up their browser resources. The server monitors resource usage and restarts browsers if needed.
Maintenance
Updating the API
When updating Flowguard, you may need to update the API dependencies:
cd /var/www/flowguard-api
npm install
npx playwright installThen restart the server:
# If using PM2
pm2 restart flowguard-api
# If using systemd
sudo systemctl restart flowguard-apiLog Rotation
Configure log rotation to prevent logs from consuming too much disk space:
# For PM2
pm2 install pm2-logrotate
pm2 set pm2-logrotate:max_size 10M
pm2 set pm2-logrotate:retain 7Monitoring
Monitor server health and resource usage:
# Check server status
curl http://localhost:3000/health
# Monitor with PM2
pm2 monit
# Check system resources
htopRelated Documentation
- Settings - Configure execution mode and other settings
- Running Flows - Understanding flow execution
- REST API - API reference for developers