Set up Python app in cPanel
Setting up a Python application in cPanel using the CloudLinux “Setup Python App” option involves several steps. Here’s a step-by-step guide to help you through the process:
- Log into cPanel:
- Access your cPanel by navigating to your client area and then clicking on Login to Control Panel button or by entering your username and password in the cPanel URL.
- Navigate to Setup Python App:
- In the cPanel dashboard, locate the “Software” section and click on “Setup Python App
- Create a New Application:
- Click the “Create Application” button.
- Select the Python version you wish to use from the dropdown menu.
- Enter the application root (the directory where your app will be stored, e.g.,
myapp). - Specify the application URL (the domain or subdomain that will be used to access your app).
- Choose the application startup file (the WSGI entry point, typically something like
app.pyorwsgi.py).
- Click the “Create Application” button.
- Configure the Virtual Environment:
- After creating the application, cPanel will set up a virtual environment for your app.
- You will see a command to enter the virtual environment. It looks like this:
source /home/username/virtualenv/application/version/bin/activate && cd /home/username/application - SSH into your server or use Terminal in cPanel and run the command to activate the virtual environment.
- Install Required Packages:
- While in the virtual environment, install the required Python packages for your application using pip. For example:
pip install flask - If you have a
requirements.txtfile, you can install all dependencies at once:pip install -r requirements.txt
- While in the virtual environment, install the required Python packages for your application using pip. For example:
- Configure WSGI File:
- Ensure your WSGI file (specified during application creation) is properly configured. A basic
wsgi.pyfor a Flask app might look like this:from myapp import app if __name__ == "__main__": app.run()
- Ensure your WSGI file (specified during application creation) is properly configured. A basic
- Restart the Application:
- Back in the cPanel “Setup Python App” interface, you can restart the application to apply changes. Click on the “Restart” button next to your application.
- Access Your Application:
- Visit the URL you specified during setup to access your application. It should now be running and accessible
- .htaccess redirect rules
- For API or other URLs under the application, you may need to add the code below to your .htaccess file in the application folder. The file will already contain certain lines added by cloudlinux. Please keep those line as is and the following can be appended below that at the end. This will help overcome 404 errors in the python application for API or other URLs under the application.
RewriteEngine On
RewriteRule . - [L]


Troubleshooting Tips
- Check Logs: If your application isn’t working as expected, check the logs for errors. Logs can be found in the
logsdirectory within your application root. - Permissions: Ensure that all files and directories have the correct permissions. Typically, 755 for directories and 644 for files.
By following these steps, you should be able to set up and run a Python application in cPanel using the CloudLinux “Setup Python App” option.