Deploying a Python Flask application on MilesWeb is a straightforward process. Follow these steps to get your application up and running smoothly.
1. Set Up Your MilesWeb Account
Before starting, ensure you have:
- An active hosting account with MilesWeb.
- Access to your cPanel dashboard.
2. Prepare Your Flask Application
Ensure your Flask application is deployment-ready. This includes creating a requirements.txt
file to list your application’s dependencies.
pip freeze > requirements.txt
3. Log in to cPanel
Access your MilesWeb cPanel account using your credentials.
4. Set Up the Python Application
Access the Python Application Setup
- In cPanel, locate the Setup Python App icon under the Software section.
Create a New Python Application
- Click on Create Application.
- Choose the desired Python version.
- Specify the application root directory (e.g.,
myapp
). - Set the application URL (e.g.,
mydomain.com/myapp
). - Define the application startup file (e.g.,
app.py
). - Provide the application entry point (e.g.,
app:app
if your Flask app object is namedapp
).
5. Upload Your Application Files
Option 1: Use File Manager
- Go to File Manager in cPanel.
- Navigate to your application root directory (e.g.,
myapp
). - Upload your Flask application files, including:
app.py
requirements.txt
- Other necessary files.
Option 2: Use FTP
- Use an FTP client to connect to your MilesWeb hosting account.
- Upload the files to the specified directory.
6. Install Dependencies
Access the Terminal
- In cPanel, find the Terminal or SSH Access icon under the Advanced section.
- Navigate to your application root directory.
Activate Your Virtual Environment
Activate the virtual environment created by MilesWeb:
source /home/your_cpanel_username/virtualenv/myapp/3.x/bin/activate
Install Required Packages
Install the dependencies listed in requirements.txt
:
pip install -r requirements.txt
7. Configure the WSGI File
Locate the WSGI File
In your application’s root directory, locate the WSGI file (commonly named passenger_wsgi.py
).
Edit the WSGI File
Modify the WSGI file to point to your Flask application. It should look like this:
import sys
import os
# Add the app's directory to the PYTHONPATH
sys.path.insert(0, os.path.dirname(__file__))
from app import app as application # Import your Flask app
8. Restart the Application
- Go back to Setup Python App in cPanel.
- Locate your application.
- Click on Restart.
9. Access Your Application
Open your web browser and navigate to your application URL (e.g., mydomain.com/myapp
). If everything is set up correctly, your Flask application should be live!
Troubleshooting
If you encounter any issues:
- Check error logs in cPanel under Errors or the logs specific to your Python application.
- Ensure your dependencies are correctly installed.
- Verify the WSGI configuration.
By following these steps, you can seamlessly deploy your Flask application on MilesWeb. If you face any challenges, feel free to reach out for support!