- 1 year ago
"No web processes running" Error on Heroku , Deploying Fastapi
The "No web processes running" error on Heroku typically occurs when the Heroku platform cannot detect a running web process to serve your application. To resolve this issue when deploying a FastAPI application on Heroku, you can follow these steps:
Ensure Procfile is Present:
- Verify that you have a
Procfile
in the root directory of your project. TheProcfile
is a text file that specifies the commands to start your application. - Open the
Procfile
and make sure it contains the following line:bashweb: uvicorn main:app --host=0.0.0.0 --port=${PORT:-5000}
- Verify that you have a
Confirm Dependencies:
- Make sure you have the necessary dependencies specified in your
requirements.txt
orPipfile
for Heroku to install.
- Make sure you have the necessary dependencies specified in your
Add a Port Configuration:
- In your FastAPI application's main file (e.g.,
main.py
orapp.py
), ensure you have the following code at the end:pythonimport os
...
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
uvicorn.run(app, host="0.0.0.0", port=port)
- In your FastAPI application's main file (e.g.,
Verify Git Repository:
- Ensure that your project is initialized as a Git repository and the necessary files are committed.
- Run
git init
in the root directory of your project if it hasn't been initialized yet, and make sure to commit your changes.
Deploy to Heroku:
- Run the following commands in your project's root directory to deploy to Heroku:shell
heroku login # Log in to your Heroku account
heroku create <app-name> # Create a new Heroku app (optional if you already have an app)
git push heroku main # Push your code to the Heroku remote repository
- Run the following commands in your project's root directory to deploy to Heroku:
Scale Dynos:
- To ensure at least one web process is running, run the following command to scale the dynos:shell
heroku ps:scale web=1
- To ensure at least one web process is running, run the following command to scale the dynos:
After completing these steps, Heroku should detect the web process and start serving your FastAPI application. You can verify the status of your application using the heroku logs --tail
command to see if there are any errors or issues.
If you continue to experience the "No web processes running" error, it's recommended to check the Heroku logs and consult Heroku's documentation or support for further assistance.