Hey, any of you ever hosted a website on cpanel? If so what process did you use? I tried uploading the django website code, creating the python app and installing dependencies but the site seems not to run unless Debug is True. I get a server error 500 when Debug is False. I followed this tutorial https://geekydocs.com/blog/deploying-your-django-application-in-cpanel and still get the error. Kindly 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 django-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/CAE1sx0K%3D3EGGEBN4FyZkb2N8z4eRsd478%3D%2BWSmDs%2Bvg%2BAm90dg%40mail.gmail.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/CAOp5q4D1cj3B8Fnu%3DZqtbAkQr4oxzFsADo2iRPKccoCWidUPuQ%40mail.gmail.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/CAOp5q4D1cj3B8Fnu%3DZqtbAkQr4oxzFsADo2iRPKccoCWidUPuQ%40mail.gmail.com.
Check this out. It should guide you better.
https://pythonfusion.com/deploy-django-on-shared-hosting/
To successfully host a Django website on cPanel and troubleshoot the 500 error occurring when
DEBUGis set toFalse, here’s a comprehensive guide:Step 1: Prepare Django Project for Deployment
Settings Adjustment:
- In your
settings.pyfile, setDEBUG = Falsefor production.- Add your domain to the
ALLOWED_HOSTSlist, like this:Static Files Configuration:
- Set up the
STATIC_ROOTfor static files. For example:pythonSTATIC_ROOT = os.path.join(BASE_DIR, 'static')- Run
python manage.py collectstaticto gather all static files into theSTATIC_ROOTdirectory.Step 2: Compress and Upload Your Project
- Compress the Project Folder:
- Zip your Django project files to simplify the upload.
- 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
- Go to Setup Python App in cPanel.
- Set the Python Version (typically Python 3.7 or later).
- Select the Project Directory where you uploaded your files.
- Configure the Virtual Environment:
- Set up the virtual environment by pointing to the folder where
manage.pyis located.- Install Dependencies:
- Click Enter to the virtual environment.
- Run
pip install -r requirements.txtto install your project dependencies.Step 4: Configure Environment Variables
- Go to the Environment Variables section in your Python App settings.
- Set environment variables for
DJANGO_SETTINGS_MODULE:plaintextDJANGO_SETTINGS_MODULE=yourproject.settings- If you’re using a secret key, add it as well:
plaintextSECRET_KEY=your_secret_keyStep 5: Set Up Database Settings
- Configure the database in
settings.pyto use the production database (if not using SQLite).- 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:
755Step 7: Adjust Allowed Hosts and Error Handling
- Test
ALLOWED_HOSTS:
- Make sure your domain is added to
ALLOWED_HOSTS.- Configure Logging in
settings.pyto catch errors:pythonLOGGING = { '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, }, }, }- Check the Error Log:
- In cPanel, go to Errors under Metrics to see server logs.
- Look in
error.login your project directory to identify specific errors.Step 8: Test and Debug
- Restart the Python app in cPanel.
- Access the site with
DEBUG = Falseand check if it runs smoothly.- If the 500 error persists, inspect logs and address any misconfigurations.
This should help troubleshoot and resolve the issue on cPanel with
DEBUGset toFalse
--
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 django-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/CA%2B7S-XsZRrTYSO5a6PaYjB47KTySw2aaRq2TvqoMOqer-ww-Eg%40mail.gmail.com.