Python (Django/Flask)
- Python (Django/Flask) Server Configuration
This article details configuring a MediaWiki server to effectively run Python web applications, specifically those built with the Django and Flask frameworks. This setup allows for dynamic content generation and integration with other Python-based services. It assumes you have a base MediaWiki installation functioning correctly.
Prerequisites
Before beginning, ensure the following are installed on your server:
- Python 3.7 or higher: The core programming language.
- pip: The Python package installer.
- Virtualenv: A tool to create isolated Python environments.
- A web server (e.g., Apache, Nginx) configured to proxy requests to your Python application.
- Basic understanding of the command line interface.
- MediaWiki 1.40 or higher is installed.
Setting up a Virtual Environment
Using a virtual environment is crucial for managing dependencies and avoiding conflicts.
1. Navigate to your desired project directory (e.g., `/var/www/python_apps`). 2. Create a virtual environment:
```bash virtualenv venv ```
3. Activate the virtual environment:
```bash source venv/bin/activate ```
(Your prompt should now be prefixed with `(venv)`).
Django Configuration
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design.
1. Install Django:
```bash pip install django ```
2. Create a Django project:
```bash django-admin startproject myproject ```
3. Navigate into the project directory:
```bash cd myproject ```
4. Run migrations:
```bash python manage.py migrate ```
5. Configure your `settings.py` file. Pay attention to `ALLOWED_HOSTS` and `DATABASES` settings.
6. Run the development server (for testing – *not* for production):
```bash python manage.py runserver 0.0.0.0:8000 ```
This starts a server listening on all interfaces (0.0.0.0) on port 8000.
Django System Requirements
The following table outlines recommended system requirements for a Django based MediaWiki extension:
CPU | RAM | Storage | Python Version |
---|---|---|---|
2+ Cores | 4GB+ | 20GB+ SSD | 3.8+ |
Flask Configuration
Flask is a micro web framework written in Python. It is lightweight and flexible, suitable for smaller applications or APIs.
1. Install Flask:
```bash pip install flask ```
2. Create a simple Flask application (e.g., `app.py`):
```python from flask import Flask app = Flask(__name__)
@app.route("/") def hello(): return "Hello from Flask!"
if __name__ == "__main__": app.run(debug=True, host='0.0.0.0') ```
3. Run the Flask application:
```bash python app.py ```
This starts a development server listening on port 5000.
Flask System Requirements
The following table outlines recommended system requirements for a Flask based MediaWiki extension:
CPU | RAM | Storage | Python Version |
---|---|---|---|
1+ Core | 2GB+ | 10GB+ SSD | 3.7+ |
Web Server Integration (Nginx Example)
To serve your Python application through a web server like Nginx, you need to configure a reverse proxy.
1. Create a new Nginx configuration file (e.g., `/etc/nginx/sites-available/myproject`):
```nginx server { listen 80; server_name yourdomain.com;
location / { proxy_pass http://127.0.0.1:8000; # For Django #proxy_pass http://127.0.0.1:5000; # For Flask proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } ```
2. Create a symbolic link to enable the configuration:
```bash sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled/ ```
3. Test the Nginx configuration:
```bash sudo nginx -t ```
4. Restart Nginx:
```bash sudo systemctl restart nginx ```
Important Considerations
- **Security:** Never run a production Django/Flask application with `debug=True`. Use a production-ready WSGI server like Gunicorn or uWSGI. Ensure proper security measures, including HTTPS, are in place.
- **Database:** Django and Flask often require a database. PostgreSQL and MySQL are common choices. Configure your application to connect to the database.
- **Static Files:** Properly serve static files (CSS, JavaScript, images) using your web server.
- **Logging:** Implement comprehensive logging to monitor your application's health and troubleshoot issues. Logging best practices should be followed.
- **MediaWiki Integration:** Develop extensions to integrate your Python application with MediaWiki. Consider using APIs or other communication methods.
- **Monitoring:** Implement system monitoring to keep track of performance and resource usage.
Python Package Versions
The following table lists example package versions used in this configuration:
Package | Version | ||||||||
---|---|---|---|---|---|---|---|---|---|
Django | 4.2.7 | Flask | 2.3.2 | Gunicorn | 20.1.0 | uWSGI | 2.0.20 | Virtualenv | 20.24.2 |
Further Resources
- Django Documentation
- Flask Documentation
- Gunicorn Documentation
- uWSGI Documentation
- Nginx Documentation
- MediaWiki Extension Development
- Virtualenv Documentation
Intel-Based Server Configurations
Configuration | Specifications | Benchmark |
---|---|---|
Core i7-6700K/7700 Server | 64 GB DDR4, NVMe SSD 2 x 512 GB | CPU Benchmark: 8046 |
Core i7-8700 Server | 64 GB DDR4, NVMe SSD 2x1 TB | CPU Benchmark: 13124 |
Core i9-9900K Server | 128 GB DDR4, NVMe SSD 2 x 1 TB | CPU Benchmark: 49969 |
Core i9-13900 Server (64GB) | 64 GB RAM, 2x2 TB NVMe SSD | |
Core i9-13900 Server (128GB) | 128 GB RAM, 2x2 TB NVMe SSD | |
Core i5-13500 Server (64GB) | 64 GB RAM, 2x500 GB NVMe SSD | |
Core i5-13500 Server (128GB) | 128 GB RAM, 2x500 GB NVMe SSD | |
Core i5-13500 Workstation | 64 GB DDR5 RAM, 2 NVMe SSD, NVIDIA RTX 4000 |
AMD-Based Server Configurations
Configuration | Specifications | Benchmark |
---|---|---|
Ryzen 5 3600 Server | 64 GB RAM, 2x480 GB NVMe | CPU Benchmark: 17849 |
Ryzen 7 7700 Server | 64 GB DDR5 RAM, 2x1 TB NVMe | CPU Benchmark: 35224 |
Ryzen 9 5950X Server | 128 GB RAM, 2x4 TB NVMe | CPU Benchmark: 46045 |
Ryzen 9 7950X Server | 128 GB DDR5 ECC, 2x2 TB NVMe | CPU Benchmark: 63561 |
EPYC 7502P Server (128GB/1TB) | 128 GB RAM, 1 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (128GB/2TB) | 128 GB RAM, 2 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (128GB/4TB) | 128 GB RAM, 2x2 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (256GB/1TB) | 256 GB RAM, 1 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (256GB/4TB) | 256 GB RAM, 2x2 TB NVMe | CPU Benchmark: 48021 |
EPYC 9454P Server | 256 GB RAM, 2x2 TB NVMe |
Order Your Dedicated Server
Configure and order your ideal server configuration
Need Assistance?
- Telegram: @powervps Servers at a discounted price
⚠️ *Note: All benchmark scores are approximate and may vary based on configuration. Server availability subject to stock.* ⚠️