This guide walks you through setting up a complete Bench development environment for building and testing Frappe applications.
Prerequisites
Before setting up Bench for development, ensure you have:
- Python 3.10 or higher
- Node.js 18 or higher
- MariaDB/MySQL database server
- Redis server
- Git
- A Unix-like operating system (Linux or macOS)
Bench is designed for development on Linux and macOS systems. For Windows, consider using WSL2 (Windows Subsystem for Linux).
Installing Bench
Install the Bench CLI tool using pip:
pip3 install frappe-bench
Verify the installation:
Initializing a New Bench
Create a new bench directory
Initialize a new bench instance. This creates a directory with the Frappe framework and all necessary configuration:
Create a new directory called frappe-bench
Set up a Python virtual environment in env/
Clone the Frappe framework into apps/frappe
Install Python and Node dependencies
Create configuration files for Redis, Procfile, and common site config
Use --frappe-branch to specify a particular Frappe version:bench init frappe-bench --frappe-branch version-15
Navigate to the bench directory
Create your first site where your applications will run:
bench new-site mysite.localhost
You’ll be prompted to set a MariaDB root password and an Administrator password for the site.
If your database is on a custom host or port, use:bench new-site mysite.localhost --db-host 192.168.1.100 --db-port 3307
Set the default site (optional)
To avoid using --site flag with every command:
bench use mysite.localhost
Getting and Installing Apps
Get apps from Git repositories:
bench get-app erpnext https://github.com/frappe/erpnext
bench get-app erpnext https://github.com/frappe/erpnext --branch version-15
For local development, you can create a soft link instead of cloning:bench get-app myapp --soft-link /path/to/local/myapp
Install the app on your site
bench --site mysite.localhost install-app erpnext
Starting the Development Server
Start all development processes using:
This launches multiple processes defined in the Procfile:
- web: Gunicorn web server (port 8000)
- socketio: Real-time communication server (port 9000)
- watch: Asset builder that watches for changes
- schedule: Background scheduler
- worker_short: Background worker for short jobs
- worker_long: Background worker for long jobs
- worker_default: Default background worker
Access your site at http://localhost:8000 or http://mysite.localhost:8000Default credentials:
- Username:
Administrator
- Password: The one you set during
new-site
Running specific processes
To start only the web server:
To run in a different port:
Developing Custom Apps
Generate a new Frappe application scaffold:
App title
App description
Publisher name
Email
Icon
Color
bench --site mysite.localhost install-app myapp
Start development with live reload
The bench start command automatically watches for changes in your Python and JavaScript files and reloads as needed.
Development Best Practices
Use Developer Mode
Enable developer mode in your site for better debugging:
bench --site mysite.localhost set-config developer_mode 1
bench --site mysite.localhost clear-cache
Developer mode provides:
- Detailed error messages
- Automatic reloading of Python code
- Live Sass compilation
- Access to developer console
Managing Dependencies
Update all Python dependencies:
bench setup requirements --python
Update all Node dependencies:
bench setup requirements --node
Install development dependencies:
bench setup requirements --dev
Database Migrations
After making changes to DocTypes, run:
bench --site mysite.localhost migrate
Building Assets
Manually build assets:
Build for production:
Running Tests
Run tests for a specific app:
bench --site mysite.localhost run-tests --app myapp
Run specific test:
bench --site mysite.localhost run-tests --app myapp --module myapp.tests.test_module
Using the Bench Console
Access a Python console with Frappe context:
bench --site mysite.localhost console
Managing Multiple Sites
List all sites:
bench --site all list-apps
Backup a site:
bench --site mysite.localhost backup
Troubleshooting Development Setup
Port Already in Use
If port 8000 is already in use:
# Find and kill the process
lsof -ti:8000 | xargs kill -9
Or configure a different port in sites/common_site_config.json:
{
"webserver_port": 8080
}
Permission Errors
Ensure proper ownership:
sudo chown -R $USER:$USER ~/frappe-bench
Redis Connection Issues
Restart Redis services:
Clear Cache and Rebuild
For mysterious issues:
bench --site mysite.localhost clear-cache
bench build --force
Development Workflow Summary
Start the development server:
Make changes to your app code
Changes are automatically detected and reloaded
Test your changes in the browser
Run migrations if needed:
bench --site mysite.localhost migrate
Commit your changes:
cd apps/myapp
git add .
git commit -m "Add new feature"
Next Steps