Apache2 can't run xvfb-run on ubuntu 14.04 server - django

I have a Django project.
I'am using xvfb on ubuntu 14.04 server with selenium and firefox to generate pdf from html.
Below is the code sample which is inside a python script.
cmd = 'xvfb-run -a python path/to/script.py'
subprocess.call(cmd, shell=True)
When I run it through django shell, it's working fine and pdfs are genearted on the server.
But when I run it via apache2, it's creating some never ending processes probably deadlocks and apache2 is giving time out repsonse.
Apache2 mayn't use 3rd party programs which is xvfb here.
Should I integrate xvfb with apache2 somehow?

Related

Failed to run dev_appserver.py using Datastore emulator from PyCharm

I have a simple Python 2.7 Google App Engine application.
I set my PyCharm Professional IDE to debug or run the app with Datastore emulator, and get the following error:
`Cannot use the Cloud Datastore Emulator because the packaged grpcio is incompatible to this system. Please install grpcio using pip`
I have tried to install this package (grpcio) using pip with no change
PyCharm runs this command to launch the app:
/usr/bin/python2.7 /home/netanel/Desktop/google-cloud-sdk/google-cloud-sdk/bin/dev_appserver.py --port 8080 --host localhost --clear_datastore=yes app.yaml --support_datastore_emulator=True
If I running this command from the terminal window it runs well
Do you have both python 3 and python 2.7 installed? Your pip install grpcio is likely installing for python 3 if so. Try
python2.7 -m pip install grpcio
to install grpcio for your python 2.7 environment that dev_appserver.py needs to use to run.

Django channels integrating with django

I'm following django channels tutorial in order to integrate it with django. But, at one point I confronted with error which I can't solve. In terminal Django says:
[Errno 111] Connect call failed ('127.0.0.1', 6379)
I think that problem is about with these lines in tutorial:
We will use a channel layer that uses Redis as its backing store. To start a Redis server on port 6379, run the following command:
$ docker run -p 6379:6379 -d redis:2.8
I'm working in Linux Ubuntu 17.04 and can't run command shown in above. When I run that command ubuntu terminal says:
docker: command not found
Result is still the same after installing 'docker' with 'sudo apt-get install docker'. How can I solve this problem? Is there other way to start redis server on specified port without installing docker?
From the first page of the tutorial:
This tutorial also uses Docker to install and run Redis. We use Redis as the backing store for the channel layer, which is an optional component of the Channels library that we use in the tutorial. Install Docker from its official website.
So, install docker on your ubuntu system, and the command docker will become available.

How to run the django web server even after closing the shell on Amazon Linux

I'm running a Django application on my Amazon Linux instance using the below command:
python manage.py runserver ec2-instance-ip.us-east-2.compute.amazonaws.com:8000
I want the application to be running even after I quit the shell. How do I run this web server even after quitting the shell on Amazon Linux?
I tried using the & as shown below, but it didn't work.
python manage.py runserver ec2-instance-ip.us-east-2.compute.amazonaws.com:8000 &
Running python manage.py ... is how you run in development, but it's not how you run on a web server. You need to deploy your application.
Take a look at Apache and mod_wsgi.
Install screen with below command
Screen is basically a tool which runs the process always, even we exit.
sudo apt-get update
sudo apt-get install screen
For details you can see: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-screen-on-an-ubuntu-cloud-server
Create a screen for you command, so your command can run as a daemon.
screen -S <processName> //Process name could be any random name for your process.
To enter inside screen.
screen -r <processName>
Now you are inside screen and can run your command here.
python manage.py runserver ec2-instance-ip.us-east-2.compute.amazonaws.com:8000
Now exit screen: ctrl+a and then d
You can create multiple screens as many you want and can any time list them by command:
screen -ls
!important: this is not recommended for Production server.
Look this to run Python app on production server: https://docs.djangoproject.com/en/2.0/howto/deployment/

Setting up SSL Certificate using mod_wsgi

I have developed a Django 1.8 application using Python 3.3. I am trying to deploy the application on a university dedicated server with Red Hat Enterprise Linux Server release 7.2 (Maipo). (Note: RHEL does not let me install newer versions of Django and Python)
I had difficulty with installing mod_wsgi using the RHEL Apache and I ended up installing:
pip install -U mod_wsgi-httpd
pip install mod_wsgi
Everything works perfectly when I use the following setup:
python manage.py runmodwsgi --setup-only --port=80 --user=iman --group=root --server-root=/etc/mod_wsgi-express-80
However, when I want to setup HTTPS, using the following setup does not return any error message, but the website does not show up neither with http:// nor with https:// prefixes.
python manage.py runmodwsgi --setup-only --port=80 --user=iman --group=root --server-root=/etc/mod_wsgi-express-80 --https-only --https-port=443 --ssl-certificate-file=/etc/sslcert/iman.crt --ssl-certificate-key-file=/etc/sslcert/private/iman.key --ssl-ca-certificate-file=/etc/sslcert/certs/ca-bundle.crt --server-name=iman123.university.edu
Here are helpful resources that I found about mod_wsgi:
mod_wsgi docs
GitHub repository
Running HTTPS and client authentication with mod_wsgi-express
pip install mod_wsgi-express left out mod_ssl.so
Thank you so much for your time and concern and apologies in advance if I am doing something wrong.

Running Django written with python3 in Gunicorn

I've written a django site in python 3.2 and I want to run it by Gunicorn in my VPS with Ubuntu 12.04 OS and I faced errors for that belongs to python 2.7 but since it's not a good idea to change my default python to 3.2 in Ubuntu 12.04 I want to ask is there anyway to tell Gunicorn to run my project by python 3.2 not python 2.7?
Sure, install the other python, but don't change your ubuntu settings. When you create your virtualenv for your django project, use the -p flag to specify which python to use.
virtualenv -p /usr/bin/python3.2 [path/to/new/virtualenv/]
Alternatively, move the whole project to Heroku. There you can specify things such as python version, plus you can start ignoring a whole bunch of dev-ops stuff like this and spend more time writing your app. It's free, and you can get set up in a couple of hours.