>
> To successfully host a Django website on cPanel and troubleshoot the 500
> error occurring when DEBUG is set to False, here’s a comprehensive guide:
> Step 1: Prepare Django Project for Deployment
>
> 1.
>
> *Settings Adjustment*:
> - In your settings.py file, set DEBUG = False for production.
> - Add your domain to the ALLOWED_HOSTS list, like this:
>
> python
> Copy code
> ALLOWED_HOSTS = ['yourdomain.com', 'www.yourdomain.com']
>
> 2.
>
> *Static Files Configuration*:
> - Set up the STATIC_ROOT for static files. For example:
>
> python
> Copy code
> STATIC_ROOT = os.path.join(BASE_DIR, 'static')
>
> - Run python manage.py collectstatic to gather all static files
> into the STATIC_ROOT directory.
>
> Step 2: Compress and Upload Your Project
>
> 1. *Compress the Project Folder*:
> - Zip your Django project files to simplify the upload.
> 2. *Upload the Zip File*:
> - Go to *File Manager* in cPanel, navigate to the root of your
> domain, and upload the zipped project.
> - Extract the zip file.
>
> Step 3: Create a Python App in cPanel
>
> 1. Go to *Setup Python App* in cPanel.
> 2. *Set the Python Version* (typically Python 3.7 or later).
> 3. *Select the Project Directory* where you uploaded your files.
> 4. *Configure the Virtual Environment*:
> - Set up the virtual environment by pointing to the folder where
> manage.py is located.
> 5. *Install Dependencies*:
> - Click *Enter to the virtual environment*.
> - Run pip install -r requirements.txt to install your project
> dependencies.
>
> Step 4: Configure Environment Variables
>
> 1. Go to the *Environment Variables* section in your Python App
> settings.
> 2. Set environment variables for DJANGO_SETTINGS_MODULE:
>
> plaintext
> Copy code
> DJANGO_SETTINGS_MODULE=yourproject.settings
>
> 3. If you’re using a secret key, add it as well:
>
> plaintext
> Copy code
> SECRET_KEY=your_secret_key
>
>
> Step 5: Set Up Database Settings
>
> 1. Configure the database in settings.py to use the production
> database (if not using SQLite).
> 2. Ensure that the database credentials are correct and accessible in
> the cPanel environment.
>
> Step 6: Check Permissions
>
> Ensure that all files and folders have the correct permissions:
>
> - Files: 644
> - Folders: 755
>
> Step 7: Adjust Allowed Hosts and Error Handling
>
> 1. *Test ALLOWED_HOSTS*:
> - Make sure your domain is added to ALLOWED_HOSTS.
> 2. *Configure Logging* in settings.py to catch errors:
>
> python
> Copy code
> LOGGING = {
> 'version': 1,
> 'disable_existing_loggers': False,
> 'handlers': {
> 'file': {
> 'level': 'ERROR',
> 'class': 'logging.FileHandler',
> 'filename': os.path.join(BASE_DIR, 'error.log'),
> },
> },
> 'loggers': {
> 'django': {
> 'handlers': ['file'],
> 'level': 'ERROR',
> 'propagate': True,
> },
> },
> }
>
> 3. *Check the Error Log*:
> - In cPanel, go to *Errors* under Metrics to see server logs.
> - Look in error.log in your project directory to identify specific
> errors.
>
> Step 8: Test and Debug
>
> 1. Restart the Python app in cPanel.
> 2. Access the site with DEBUG = False and check if it runs smoothly.
> 3. If the 500 error persists, inspect logs and address any
> misconfigurations.
>
> This should help troubleshoot and resolve the issue on cPanel with DEBUG
> set to False
>
if the error persists let me know , happy to help
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-users/CA%2B7S-XsZRrTYSO5a6PaYjB47KTySw2aaRq2TvqoMOqer-ww-Eg%40mail.gmail.com.