How to Enable Debugging for Custom Plugin Development in CyberPanel?

I’m currently working on porting some custom plugins I’ve previously developed for Plesk and cPanel to CyberPanel, and I’m running into some issues I hope you can help me with.

When installing my custom plugins, the installation usually completes without problems. However, when accessing the plugin from the CyberPanel interface, I frequently encounter 500 Internal Server Errors or generic “Internal Error” messages in the browser. These errors make debugging difficult, as there is no visible traceback or specific error message.

As a developer, I’d like to know the following:

  1. How can I enable full debugging mode in CyberPanel (especially for Django-based plugins)?
  2. Where exactly are the error logs stored when developing a custom plugin?
  3. Is there a way to see full Django error tracebacks or logs in real time while testing a plugin?
  4. Are there any recommended best practices when developing and testing plugins (like environment variables, dev mode, or CLI commands)?
  5. Can I configure CyberPanel to show debug messages on the frontend (temporarily) during development?

Any documentation links or guidance from the CyberPanel team or experienced developers would be greatly appreciated. I believe having this setup would greatly help not only me, but other developers interested in contributing to the CyberPanel ecosystem with custom plugins.

Thanks in advance!

@usmannasir

Welcome to CyberPanel plugin development! Here’s a detailed guide to enable debugging and troubleshoot your plugins effectively.

  1. Enable Debug Mode

Create a debug flag file to enable detailed logging:
touch /usr/local/CyberCP/debug

This activates debug logging throughout CyberPanel, including detailed request/response logging.

  1. Django Debug Configuration

Edit /usr/local/CyberCP/CyberCP/settings.py:

Change DEBUG from False to True

DEBUG = True

Add your development domain to ALLOWED_HOSTS

ALLOWED_HOSTS = [‘*’] # For development only!

Important: Remember to set DEBUG = False in production!

  1. Error Log Locations

CyberPanel logs are stored in multiple locations:

Main CyberPanel log

/home/cyberpanel/error-logs.txt

Django/LSCPD logs

/usr/local/lscp/logs/error.log
/usr/local/lscp/logs/stderr.log

Custom plugin logs (if using CyberCPLogFileWriter)

/home/cyberpanel/error-logs.txt

  1. Real-time Log Monitoring

Monitor logs in real-time while testing:

Watch all relevant logs simultaneously

tail -f /home/cyberpanel/error-logs.txt /usr/local/lscp/logs/error.log

  1. Plugin Development Best Practices

A. Logging in Your Plugin

Use CyberPanel’s logging system:
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging

In your plugin code

logging.writeToFile(“Debug: Entering my_function”)
logging.writeToFile(f"Variable value: {my_variable}")

B. Exception Handling

Always wrap your code with proper exception handling:
try:
# Your plugin logic here
result = perform_operation()
logging.writeToFile(f"Operation successful: {result}“)
except Exception as e:
# Log the full traceback
import traceback
error_msg = str(traceback.format_exc())
logging.writeToFile(f"Plugin Error: {error_msg}”)

  # Return proper error response
  return HttpResponse(json.dumps({
      'status': 0,
      'error_message': str(e)
  }))

C. Debug-Specific Code

Add debug-only code blocks:
from plogical.processUtilities import ProcessUtilities
import os

if os.path.exists(ProcessUtilities.debugPath):
logging.writeToFile(“=== DEBUG MODE ACTIVE ===”)
logging.writeToFile(f"Request method: {request.method}“)
logging.writeToFile(f"Request body: {request.body}”)
logging.writeToFile(f"Request path: {request.path}")

  1. Common 500 Error Causes & Solutions

A. Import Errors

Always use absolute imports

from websiteFunctions.models import Websites # Good
from models import Websites # Bad - may cause import errors

B. Permission Issues

Ensure your plugin files have correct permissions:
chown -R cyberpanel:cyberpanel /usr/local/CyberCP/your_plugin/
chmod -R 755 /usr/local/CyberCP/your_plugin/

C. URL Pattern Issues

Register your URLs properly in your plugin’s urls.py:
from django.urls import path
from . import views

urlpatterns = [
path(‘your_endpoint/’, views.your_view, name=‘your_view_name’),
]

  1. Development Workflow

  2. Enable debugging:
    touch /usr/local/CyberCP/debug
    systemctl restart lscpd

  3. Make changes to your plugin

  4. Restart CyberPanel:
    systemctl restart lscpd

  5. Test and monitor logs:
    tail -f /home/cyberpanel/error-logs.txt

  6. Check browser console for JavaScript errors (F12)

  7. Advanced Debugging Techniques

A. Print SQL Queries

from django.db import connection
print(connection.queries) # Shows all SQL queries

B. Interactive Debugging

Use Django shell for testing:
cd /usr/local/CyberCP
python manage.py shell

Then test your models and functions:
from your_plugin.models import YourModel
YourModel.objects.all()

C. Custom Middleware Debugging

If your plugin uses middleware, ensure it doesn’t interfere with secMiddleware.py.

  1. Frontend Debugging

For AngularJS-based interfaces:
// Add to your controller
console.log(‘Debug: Controller loaded’);
console.log(‘Response:’, response.data);

// Use $scope for debugging
$scope.debugMode = true; // Show debug info in template

  1. Testing Checklist

Before deploying:

  • Remove all print() statements
  • Set DEBUG = False
  • Test with debug mode OFF
  • Check all error handling
  • Verify logging works correctly
  • Test on fresh CyberPanel installation

Quick Debug Commands Reference

Enable debug mode

touch /usr/local/CyberCP/debug

Disable debug mode

rm -f /usr/local/CyberCP/debug

Restart CyberPanel

systemctl restart lscpd

View recent errors

tail -n 100 /home/cyberpanel/error-logs.txt

Clear log file (for testing)

/home/cyberpanel/error-logs.txt

Pro Tips:

  1. Use ACL Manager for permission checks in your views
  2. Follow CyberPanel’s coding patterns - study existing plugins
  3. Test with different user roles (admin, reseller, user)
  4. Use CyberPanel’s built-in utilities (ProcessUtilities, ACLManager, etc.)
  5. Always validate and sanitize input - check secMiddleware.py for examples

Good luck with your plugin development! The CyberPanel community is here to help if you encounter specific issues.