Apache AWS lightsail python configuration ModuleNotFound error - python

I want to configure my python project to make use of apache,
All the configuration settings I have done to have my project to run apache as its server did not work but it was producing
ModuleNotFound error, but when I checked using pip list I saw that the package was installed. However when I run python manage.py runserver ipaddress:8000
it worked perfectly without any error. This show that there is configuration which was not working.
However all tutorials I have studied used apache2 directory as the location where their configuration takes place.
But when I checked apache2 directory I discovered that it was pointing to apache directory and if I tried to enter
into apache2 directory it would redirect me to apache directory so all my work is taking place in apache directory and not apache2 directory.
How can I get my project to make use of apache server and probably access apache2 as it is done in all the tutorials.

Related

Heroku not working for Node.js file with python scripts

I made a website in node.js and I have used child process to run python scripts and use their results in my website. But when I host my application on heroku, heroku is unable to run the python scripts.
I have noticed that heroku was able to run python scripts which only had inbuilt python packages like sys, json but it was failing for scripts which were using external packages like requests, beautifulsoup.
Attempt-1
I made a requirements.txt file inside the project folder and pushed my code to heroku again. But it was still not working. I noticed that heroku uses the requirements.txt file only for python based web applications but not for node.js applications.
Attempt-2
I made a python virtual env inside the project folder and imported the required python packages into the venv. I then removed gitignore from the venv and pushed the whole venv folder to heroku. It still didn't work.
Please let me know if anyone came across a way to handle this.
You can use a Procfile to specify a command to install the python dependencies then start the server.
Procfile:
web: pip install -r requirements.txt && npm start
Place Procfile in your project's root directory and deploy to heroku.
Solution:
Have a requirements.txt file in your project folder.
After you create a heroku app using "heroku create", heroku will identify your app as python based and will not download any of the node dependencies.
Now, go to your heroku profile and go to your app's settings. There is an option named "Add Buildpack" in there. Click on that and add node.js as one of the buildpacks.
Go back to your project and push it to heroku. This time heroku will identify your app as both python and node.js based and will download all the required files.

Azure deployment not installing Python packages listed in requirements.txt

This is my first experience deploying a Flask web app to Azure.
I followed this tutorial.
The default demo app they have works fine for me.
Afterwards, I pushed my Flask app via git. The log shows deployment was successful. However, when I browse the hosted app via link provided in "Application Properties", I get a 500 error as follows:
The page cannot be displayed because an internal server error has
occurred.
Most likely causes: IIS received the request; however, an internal
error occurred during the processing of the request. The root cause of
this error depends on which module handles the request and what was
happening in the worker process when this error occurred. IIS was not
able to access the web.config file for the Web site or application.
This can occur if the NTFS permissions are set incorrectly. IIS was
not able to process configuration for the Web site or application. The
authenticated user does not have permission to use this DLL. The
request is mapped to a managed handler but the .NET Extensibility
Feature is not installed.
The only off-base thing I can see by browsing the wwwroot via KUDU is that none of the packages I have installed in my local virtual environment are installed on Azure despite the existence of the "requirements.txt" file in wwwroot.
My understanding is that Azure would pip install any non existent package that it finds in the requirements.txt upon GIT successful push. But it doesn't seem to be happening for me.
Am I doing something wrong and the missing packages is just a symptom or could it be the cause the issue?
Notes:
My Flask app works fine locally (linux) and on a 3rd party VPS
I redeployed several times starting from scratch to no avail (I use local GIT method)
I cloned the Azure Flask demo app locally, changed just the app folder and pushed back to Azure, yet no success.
Azure is set to Python 2.7 same as my virtual env locally
As suggested in the tutorial linked above, I deleted the "env" folder and redeployed to trick Azure to reinstall the virtual env. It did but with its own default packages not the one in my requirements.txt.
My requirements.txt has the following:
bcrypt==3.1.0 cffi==1.7.0 click==6.6 Flask==0.11.1 Flask-Bcrypt==0.7.1
Flask-Login==0.3.2 Flask-SQLAlchemy==2.1 Flask-WTF==0.12
itsdangerous==0.24 Jinja2==2.8 MarkupSafe==0.23 pycparser==2.14
PyMySQL==0.7.7 python-http-client==1.2.3 six==1.10.0 smtpapi==0.3.1
SQLAlchemy==1.0.14 Werkzeug==0.11.10 WTForms==2.1
As Azure Web Apps will run a deploy.cmd script as the deployment task to control which commands or tasks will be run during the deployment.
You can use the command of Azure-CLI azure site deploymentscript --python to get the python applications' deployment task script.
And you can find the following script in this deploy.cmd sciprt:
IF NOT EXIST "%DEPLOYMENT_TARGET%\requirements.txt" goto postPython
IF EXIST "%DEPLOYMENT_TARGET%\.skipPythonDeployment" goto postPython
echo Detected requirements.txt. You can skip Python specific steps with a .skipPythonDeployment file.
So the .skipPythonDeployment will skip all the following steps in deployment task, including creating virtual environment.
You can try to remove .skipPythonDeployment from your application, and try again.
Additionally, please refer to https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script for more info.

Changing documentroot in openshift

We're developing an android app with an api backend that we want to deploy via openshift.
The problem is we have the android app and the webservice in the same github project in two different folders. So I need to change the document_root so that openshift can find the python wsgi.py file.
I've already tried this:
rhc env-set OPENSHIFT_PYTHON_WSGI_APPLICATION="\${OPENSHIFT_REPO_DIR}/server/wsgi.py" --app api
But then it wouldn't find the requirements.txt because it still uses the wrong document_root.
I tried putting the requirements.txt in the root dir, that way it parses the file but installs the lib's in the wrong place.
I've also tried
rhc env-set OPENSHIFT_DOCUMENT_ROOT="\${OPENSHIFT_REPO_DIR}/server" --app api
But that didn't work either
Help please!!!!
As of the March release of OpenShift online, you can now specify the path to your WSGI with the 'OPENSHIFT_PYTHON_WSGI_APPLICATION' environment variable. You can read more about it here: https://www.openshift.com/blogs/openshift-online-march-2014-release-blog
Are you looking for OPENSHIFT_PYTHON_REQUIREMENTS_PATH
https://developers.openshift.com/en/python-overview.html

django gunicorn and nginx proxy giving 504 error

I went through all the related questions and could not find the answer, i went through the docs as well and tried all that i could, its my first time, hence having a hard time.
I have a simple django polls app with proper settings and static files, working locally.
As mentioned in the title i am trying to use django on a newly bought VPS, with nginx and gunicorn, i am using virtualenv as well.
Here is my folder structure on the server:
logs pid projhome scripts
inside the projhome i have the following directories:
bin djangopolls include lib local
as already mentioned parallel to the projhome folder i have scripts folder, with the following content:
source /home/django/projhq/bin/activate
kill `cat /home/username/pid/gunicorn.pid`
gunicorn_django -c /home/username/projhome/djangopolls/gunicorn_cfg.py
Now to start the server i need to go to the scripts folder and run the start script, i do that without any error, but when i check the IP i get 504 error.
Where am i wrong???
you might first want to cd into the directory where settings.py file is placed and then run gunicorn, so you can update your script.sh to first cd into the django project directory.

How configure mod_wsgi with wamp server in windows7

I am new to Django framework and Python. I installed Python Wamp server and downloaded mod_wsgi. I follow these steps.
I am in confused whether I configured it correctly since when I stop the wamp server then also the http://127.0.0.1:8000/ works correctly.
Have you considering reading any of the official mod_wsgi documentation at:
http://www.modwsgi.org
including its quick configuration guide.
http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
We would then need to now what configuration you set in Apache for mapping your application and a better explaination of the problem you are seeing including any error messages in browser or Apache error logs.
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi is the answer it has a windows vc10 binary.
If you can be bothered getting the latest wampserver (or at lest one compiled with vc10):
Add you your env ;C:\Python27;C:\Python27\Scripts
wget http://peak.telecommunity.com/dist/ez_setup.py (or just down loaded it to you user folder)
python ez_setup.py
easy_install pip
pip install django
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi (put the appropriate with your apache moduales (currently has Apache 22 and 24)
In your http.config:
LoadModule wsgi_module modules/mod_wsgi.so
To test start a project:
django-admin.py startproject mysite
python manage.py runserver 83 # (or some other test port that's not 80)
All that I did I got from this youtube
Edit: So when you want to stop testing on port 83 and use Apache on port 80
you need to set WSGIPythonPath as mentioned here (I didn't bother with that page to much) and WSGIScriptAlias. The main guide to do that is here although #Jisson's wamp guide has that too and shows windows paths etc which I at first found useful too :)

Categories

Resources