I'm never done development in a career as a software programmer
I'm given this domain name on NameCheap with the server disk. Now I design Django app and trying to deploy on the server but I had problems (stated below)
[ E 2019-03-19 06:23:19.7356 598863/T2n age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /home/username/IOT: The application process exited prematurely.
App 644163 output: File "/home/username/IOT/passenger_wsgi.py", line 1, in <module>
App 644163 output: File "/home/username/virtualenv/IOT/3.7/lib64/python3.7/imp.py", line 171, in load_source
edited: Read more about the software supporting the WSGI is using Phusion Passenger, you could read more here; www.phusionpassenger.com
this is my passenger_wsgi.py:
from myproject.wsgi import application
I had tried several tutorials:
https://www.youtube.com/watch?v=ffqMZ5IcmSY&ab_channel=iFastNetLtd.InternetServices
https://smartlazycoding.com/django-tutorial/deploy-a-django-website-to-a2-hosting
https://hostpresto.com/community/tutorials/how-to-setup-a-python-django-website-on-hostpresto/
https://www.helloworldhost.com/knowledgebase/9/Deploy-Django-App-on-cPanel-HelloWorldHost.html
https://www.helloworldhost.com/knowledgebase/9/Deploy-Django-App-on-cPanel-HelloWorldHost.html
how to install django on cpanel
Very much applicate if you could help
When you setup a python app in cpanel, you specify the folder where you have setup the app. That will be the folder that will contain your passenger_wsgi.py file. You have to upload your django project to that same folder. To make sure they you have uploaded to the right directory, just have this simple check_ your manage.py and passenger_wsgi.py should be in the same folder. Now edit your passenger_wsgi.py and replace everything with the following code:
from myapp.wsgi import application
After this, do not forget to restart the python app. I have written a step by step guide for deploying django app on shared hosting using cpanel. Check it here.
The answer very simple, my server is using a programme name passenger, the official website for more information: https://www.phusionpassenger.com/
Now error very simply; passenger can't find my application, All I did was move my project and app folder on the same layer passenger_wsgi.py and it works like charm.
Related
I am trying to deploy my dash app which uses dash_extensions, Dash_proxy and has multiple pages in the pages folder on GCP cloud run using gunicorn but the app cannot find the pages folder. It works perfectly fine when I use the development server but breaks in the production server because it cannot find the folder path.
The app (following code is inside the app.py file):
app = DashProxy(use_pages=True, pages_folder=pages_folder, external_stylesheets=[dbc.themes.SIMPLEX])
The app.py file and the pages folder are in the same directory
I have tried tried to following methods to get the folder path:
pages_folder="pages"
pages_folder=os.path.join(os.path.dirname(__file__), "pages")
for p in Path('.').rglob('*'):
if str(p).endswith('pages'):
pages_folder = str(p)
break
None of the above three work in when deploying on gcp using gunicorn through docker:
Dockerfile command:
CMD ["gunicorn" , "-b", "0.0.0.0:8000", "app:server"]
But if I use dev server through docker like following code it works:
CMD python app.py
Does anyone have any ideas of how to make it work with gunicorn?
Thanks for the help!
-Rexon
Yes I did. Just had to specify the root folder. This is what I did and it seems to work for me.
pages_folder=os.path.join(os.path.dirname(__name__), "pages")
app = DashProxy(__name__,use_pages=True, pages_folder=pages_folder, external_stylesheets=[dbc.themes.SIMPLEX])
server=app.server
I'm trying to deploy a django web app to the Microsoft Azure and this is correctly deployed by the pipeline on DevOps Azure, but I get the error message (ModuleNotFoundError: No module named 'django) on portal Azure and cannot reach my app via the URL.
The app also works properly locally
Here is the whole error message: '''https://pastebin.com/mGHSS8kQ'''
How can I solve this error?
I understand you have tried the steps suggested in the SO thread Eyap shared, and few things here are already covers that. Kindly review these settings.
You can use this command instead - source /antenv3.6/bin/activate.
As a side note- The antenv will be available only after a deployment is initiated. Kindly check the “/” path from SSH and you should see a folder with name starting from antenv.
Browse to .python_packages/lib/python3.6/site-packages/ or .python_packages/lib/site-packages/. Kindly review the file path exists.
Review the Application logs as well (/home/LogFiles folder) from Kudu- https://<yourwebpp-name>.scm.azurewebsites.net/api/logs/docker
The App Service deployment engine automatically activates a virtual environment and runs
pip install -r requirements.txt
The requirements.txt file must be in the project root for dependencies to be installed.
For Django apps, App Service looks for a file named wsgi.py within your app code, and then runs Gunicorn using the following command:
is the name of the folder that contains wsgi.py
gunicorn --bind=0.0.0.0 --timeout 600 .wsgi
If you want more specific control over the startup command, use a custom startup command, replace with the name of folder that contains wsgi.py, and add a --chdir argument if that module is not in the project root.
For additional details, please checkout this document
Configure a Linux Python app for Azure App Service
Quickstart: Create a Python app in Azure App Service on Linux
I am trying to host a Python\Django app on Heroku. I followed the guide on heroku website but when I execute the line "heroku ps:scale web:1" it comes back the following message:
No process types on ⬢ salty-brushlands-45215.
▸ Upload a Procfile to add process types.
▸ https://devcenter.heroku.com/articles/procfile
I already tryed to commit a Procfile into my project (searching for a solution) but I don't know if requires any configuration inside it. Help please!
Your Procfile should contain this,
web: gunicorn your_project.wsgi
web defines the type of your application
gunicorn is a wsgi server
1.Create .txt file.
2.add this raw to your file:
worker: python main.py
3.save file and delete file extension (.txt)
4.add Procfile to master folder
5.deploy
I'm trying to deploy a web app built with Django/Redux/React/Webpack on a Digital Ocean droplet. I'm using Phusion Passenger and Nginx on the deployment server.
I used create-react-app to build a Django app which has a frontend that uses React/Redux, and a backend api that uses django-rest-framework. I built the frontend using npm run build.
The Django app is configured to look in the frontend/build folder for its files and everything works as expected, including authentication. It's based on this tutorial: http://v1k45.com/blog/modern-django-part-1-setting-up-django-and-react/
In settings.py:
ALLOWED_HOSTS = ['*']
TEMPLATES = [
...
'DIRS': [
os.path.join(BASE_DIR, 'frontend/build'),
],
...
]
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'frontend/build/static'),
]
On my development machine, I activate a Python 3.6 virtual environment and run ./manage.py runserver, and the app is displayed at localhost:3000.
On the deployment server, I've cloned the files into a folder in var/www/ and built the frontend.
I've set up Passenger according to the docs with a file passenger_wsgi.py:
import myapp.wsgi
application = myapp.wsgi.application
And the wsgi.py file is in the djangoapp folder below:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapp.settings')
application = get_wsgi_application()
The Passenger docs only cover a single-part app:
https://www.phusionpassenger.com/library/walkthroughs/start/python.html
https://www.phusionpassenger.com/library/walkthroughs/deploy/python/digital_ocean/nginx/oss/xenial/deploy_app.html
https://www.phusionpassenger.com/library/deploy/wsgi_spec.html
I've tried cloning the tutorial part 1 code directly onto my server and following the instructions to run it. I got this to work on the server by adding "proxy": "http://localhost:8000" to frontend/package.json. If I run the Django server with ./manage.py runserver --settings=ponynote.production_settings xxx.x.x.x:8000
then the app is correctly served up at myserver:8000. However Passenger is still not serving up the right files.
I have changed wsgi.py to say this:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.production_settings")
application = get_wsgi_application()
The page served by Passenger at URL root now appears to have the right links to the js files such as "text/javascript" src="/static/bundles/js/main.a416835a.js, but the links don't work: the expected js is not present. Passenger is failing to serve the js files from static/bundles/js, even though the Django server can find them.
Very grateful for any help or ideas.
Create-react-app has a fairly opinionated setup for local and production environments.
Locally, running npm start will run a webpack-dev-server, which you would typically access on port 3000. It runs a local nodejs web server to serve the files. You can route requests to your local Django server via the proxy setting.
It's worth noting that at this point there is little or no connection between your React app and Django. If you use the proxy setting, the only thing connecting the two apps is the routing of any requests not handled by your React app to your Django app via the port.
By default in create-react-app (and as noted in the tutorial you mentioned you are following) in production you would run npm run build which will process your create-react-app files into static JS and CSS files, which are then accessed in Django like static files any other Django app.
One thing Django is missing in order to access the static files is a way to know what files are generated when running npm run build. Running a build will typically result in files output like this:
- css
|- main.e0c3cfcb.css
|- main.e0c3cfcb.css.map
- js
|- 0.eb5a2873.chunk.js
|- 0.eb5a2873.chunk.js.map
|- 1.951bae33.chunk.js
|- 1.951bae33.chunk.js.map
A random hash is added to filenames to ensure cache busting. This is where webpack-bundle-tracker and django-webpack-loader come in. When build files are generated, an accompanying file is also created called manifest.json, listing the files created for the build. This is generated in Webpack and picked up by django-webpack-loader so that Django can know which files to import.
It is possible to run a nodejs server in production, or to use server-side rendering, but if you're following the tutorial you mentioned and using create-react-app default settings, then running npm run build and deploying the static files is the simplest, safest option.
Nothing in any of the Passenger deployment links you mention cover anything beyond deploying a Python/Django app - you would need to manage two apps and deployments to have both Django and React running as servers in production.
Note that the tutorial you mention covers how to get your build files into Django in production, but you will need to ensure that you have webpack-bundle-tracker, django-webpack-loader and your Django staticfiles configuration all configured to work together.
The key missing setting was the 'location' setting in the Passenger config file.
Although the Django server serves up the static files, including the build files for your React app, Nginx doesn't see any static files except those in a 'public' directory.
So to deploy a Django app built with Webpack to production, you need to tell Nginx about those files. If you're using Passenger, these settings are probably in a separate Passenger config file. 'alias' is the command to use in this case where the folder has a different name from 'static' (which is where the web page links point).
If you use a virtual environment for your app, you need to specify where Passenger can find the right Python executable.
/etc/nginx/sites-enabled/myapp.conf
server {
listen 80;
server_name xx.xx.xx.xx;
# Tell Passenger where the Python executable is
passenger_python /var/www/myapp/venv36/bin/python3.6;
# Tell Nginx and Passenger where your app's 'public' directory is
# And where to find wsgi.py file
root /var/www/myapp/myapp/myapp;
# Tell Nginx where Webpack puts the bundle folder
location /static/ {
autoindex on;
alias /var/www/myapp/myapp/assets/;
}
# Turn on Passenger
passenger_enabled on;
}
Passenger uses the wsgi.py file as an entry point to your app. You need a passenger_wsgi.py file one level above the wsgi.py file. This tells Passenger where to find the wsgi.py file.
/var/www/myapp/myapp/passenger_wsgi.py
import myapp.wsgi
application = myapp.wsgi.application
/var/www/myapp/myapp/myapp/wsgi.py
If you are using a separate production_settings.py file, make sure this is specified here.
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.production_settings")
application = get_wsgi_application()
I've built a Django project that works, even after I freeze it using Cx_Freeze and Py2exe.
Now I'm trying to set up the project for distribution, which requires a real webserver. I'm going for Gunicorn (will add Nginx once it works). I managed to run the Gunicorn server properly through the command line using :
gunicorn wsgi:application
However, I need to be able to run the server from my Python script, as the server is ment to be localhost. Gunicorn used to be shipped with a command 'run_gunicorn' designed for Django, but this command is now deprecated.
I tried understanding the following method :
How to use Flask-Script and Gunicorn
But I can't figure out how to make it work with Django.
The following doesn't work:
from django.core.wsgi import get_wsgi_application
from gunicorn.app.base import Application
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = get_wsgi_application()
Application().run(application)
Could someone tell me how to start the gunicorn server from my Python script ?