How to Rename a Frappe or ERPNext Site using Bench CLI
Change Site NameLearn the step-by-step process to safely change your Frappe or ERPNext site name (e.g., from site1.local) using essential Bench CLI commands like \`bench setup nginx\`.
When managing a Frappe or ERPNext instance, a common administrative task is renaming a site. This is often necessary when moving from a development environment with a default name like `site1.local` to a production environment with a custom domain. The process involves more than just renaming a folder; it requires updating web server configurations and internal Frappe settings to ensure the site remains accessible and functional.
This guide provides a comprehensive set of shell commands to perform this operation safely using the Bench Command Line Interface (CLI). Following these steps carefully will prevent common issues like '502 Bad Gateway' errors or scheduler failures.
1 # Step 1: Rename the site's folder manually 2 # Replace 'oldname.local' and 'newname.com' with your actual site names. 3 mv /home/ubuntu/frappe-bench/sites/oldname.local /home/ubuntu/frappe-bench/sites/newname.com 4
5 # Step 2: Navigate back to the main bench directory 6 cd /home/ubuntu/frappe-bench/ 7
8 # Step 3: Regenerate Nginx configuration for the new site name 9 bench setup nginx 10
11 # Step 4: Reload Nginx to apply the new configuration 12 sudo service nginx reload 13 # On systems using systemd, you might use: 14 # sudo systemctl restart nginx 15
16 # Step 5: Update the 'currentsite.txt' to point to the new site 17 # Open the file /home/ubuntu/frappe-bench/sites/currentsite.txt 18 # And change the content from 'oldname.local' to 'newname.com' 19
20 # Step 6: Re-enable the scheduler for the new site 21 bench --site newname.com enable-scheduler
Understanding This Code
What It Does
This series of commands renames a Frappe site's directory, regenerates the necessary Nginx web server configuration, updates the current site pointer, and restarts the scheduler to reflect the new site name.
When To Use
Use this procedure when you need to change the domain name of an existing Frappe or ERPNext site, for example, when moving from a default development name like \`site1.local\` to a custom production domain.
Prerequisites
- •Shell access (SSH) to the server hosting the Frappe instance.
- •Sudo or root privileges for restarting services like Nginx.
- •The Frappe Bench CLI must be installed and accessible in your server's PATH.
Key Concepts
Important ideas to understand in this code
Bench CLI
The Bench Command Line Interface is the primary tool for creating, managing, and updating Frappe and ERPNext sites. Commands like `bench setup nginx` and `bench --site` are essential for system administration.
Learn moreSite Naming & Resolution
Frappe Framework uses a multi-tenant architecture where each site is represented by a folder inside the `/sites` directory. The folder name must match the domain name you intend to use for that site.
Learn morecurrentsite.txt
This file, located in the `/sites` directory, tells Bench which site to use by default if the `--site` flag is not specified in a command. It must be updated manually after renaming a site.
Learn moreStep-by-Step Tutorial
Follow along to understand how this code works
Rename the Site Directory
The first step is to rename the actual directory containing your site's data. Use the standard Linux `mv` command. Make sure you are in the parent directory of `frappe-bench` or provide the full paths.
mv /home/ubuntu/frappe-bench/sites/site1.local /home/ubuntu/frappe-bench/sites/demo.finbyz.inRegenerate Nginx Configuration
Navigate to your `frappe-bench` directory. The `bench setup nginx` command will detect the change in the `/sites` directory and generate a new Nginx server block configuration for your new domain name.
cd /home/ubuntu/frappe-bench/
bench setup nginxApply the New Web Server Configuration
For Nginx to recognize the new configuration, you must reload its service. This command applies the changes without dropping existing connections.
sudo service nginx reloadUpdate the Default Site Pointer
Edit the `sites/currentsite.txt` file and replace the old site name with the new one. This ensures that bench commands run without the `--site` flag target the correct, renamed site.
# Open sites/currentsite.txt with a text editor (like nano or vim)
# Change 'site1.local' to 'demo.finbyz.in' and save the file.Re-enable the Scheduler
The scheduler (which handles background jobs, emails, etc.) is tied to the site name. You must enable it for the new site name to ensure background processes continue to run correctly.
bench --site demo.finbyz.in enable-schedulerCommon Issues & Solutions
Troubleshoot problems you might encounter