Step‑by‑Step Guide to Deploying a Django Project on a Linux Server with the BT Panel
This tutorial walks beginners through deploying a Django application on a fresh Linux server using the BT (BaoTa) panel, covering security‑group port opening, software installation, Python environment setup, uWSGI and Nginx configuration, static file handling, and common troubleshooting steps.
This tutorial is aimed at absolute beginners who want to deploy a Django project quickly on a new Linux server, using the BT (BaoTa) control panel to avoid unnecessary pitfalls.
Scenario: You have just purchased a new Linux (CentOS) server.
1. Open required ports in the cloud provider's security group. Common ports include 80, 443, 21, 22, 3306, and 8888 (the latter for BT panel access).
2. Download and install Xshell. Xshell is used to log into the Linux server.
3. Create a /www directory in the root filesystem. This directory will hold the BT panel and website data.
mkdir /www
4. Install the BT panel. Run the following command in the terminal:
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
After installation, note the displayed login URL, username and password.
5. Install common web service components. In the BT panel select Nginx (required) and, if using MySQL, select MySQL (ensure version compatibility with Django 3.0+).
6. Install the "Python Project Management" plugin from the BT software store.
7. Install the required Python version. Use the plugin to add the desired Python version (e.g., 3.7.2) from a domestic mirror.
8. Add a site for the project. Provide your domain name or server IP address.
9. Upload the Django source code. Before packaging, run pip freeze > requirements.txt locally and include the file in the project directory.
pip freeze > requirements.txt
Upload and extract the source archive on the server, ensuring the code resides under /www/wwwroot/ and that requirements.txt is present.
10. Create a uwsgi.ini file. Example content:
# uwsgi configuration [uwsgi] socket=127.0.0.1:8997 chdir=/www/wwwroot/www.django.cn/ wsgi-file=myblog/wsgi.py processes=4 threads=2 master=True pidfile=uwsgi.pid daemonize=uwsgi.log
11. Modify the Nginx site configuration. Add the following location blocks (replace ports and paths with those from uwsgi.ini ):
location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8997; uwsgi_param UWSGI_SCRIPT myblog.wsgi; uwsgi_param UWSGI_CHDIR /www/wwwroot/www.django.cn/; } location /static/ { alias /www/wwwroot/www.django.cn/static/; }
12. Add the project in the Python Project Management plugin. Fill in the options, ensuring the port matches the one defined in uwsgi.ini .
13. Activate the virtual environment created by the plugin. Run:
source /www/wwwroot/myblog/myblog_venv/bin/activate
After activation, install dependencies from requirements.txt (the plugin does this automatically) or install additional packages manually.
14. Solve missing admin‑site styles. Add a static‑files collection path in settings.py :
# Collect static files to a dedicated directory STATIC_ROOT = os.path.join(BASE_DIR, 'static')
Then, inside the virtual environment, run:
python manage.py collectstatic
Refresh the admin page; the styles should reappear.
After completing all steps, access the domain in a browser to see the deployed Django site.
If an "Internal Server Error" occurs, log into the virtual environment and run python manage.py runserver to debug, then restart the project via the BT panel.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.