I want to develop my project with web2py. Before that I make it with python cherrypy. and now going to switch to web2py.
But I would like use Apache server instead of WSGI and web2py server!
Could you guide me how do this?
Into scripts folder(web2py/scripts) are some one-step setup scripts to deploy a web2py environment using apache for:
Fedora Linux: setup-web2py-fedora.sh
Ubuntu Linux: setup-web2py-ubuntu.sh
If you have another OS you can check it in order to get a detailed step to step installation guide.
As Calvin said, the deployment recipes are at: http://web2py.com/books/default/chapter/29/13
A very detailed explanation is provided here - http://web2py.com/book/default/chapter/13#Apache-setup - including the apache2/mod_wsgi configuration files.
Perhaps you can try this out first and ask questions when you run into trouble?
There is problem with setup-web2py-ubuntu.sh in version 2.9.5 and prior if trying to run it on Ubuntu 14.04. The main culprit is the fact that Ubuntu 14.04 is using Apache 2.4, which is doing a few things differently from version 2.2.
I've modified the install script so that it will work on Ubuntu 14.04. There are now only three commands to run to get web2py working on a new server.
wget https://raw.githubusercontent.com/ivandigiusto/web2py-install/master/setup-web2py-ubuntu-14.04.sh
chmod +x setup-web2py-ubuntu-14.04.sh
sudo ./setup-web2py-ubuntu-14.04.sh
Please note that if you run this script on a server that already has an Apache and web sites configured, it will:
wipe your current default.conf in /etc/apache2/sites-available/
delete all links in /etc/apache2/sites-enabled/
To get around that, you may want to manually modify the setup script before running it, or just spin up a new server and try this out on it.
Related
On my dev machine I installed and configured celery within a django app and it works without issues using python3.5 and the django dev webserver.
When I deploy that app to my production server I get an error "no module named celery". On the production server runs python3.6 with apache2 and mod_wsgi.
On both machines I use django-1.11 and celery-4.1.0 within a virtualenv. I suspect that it's either an issue with python3.6 or with mod_wsgi.
I haven't found any real solution to my issue so I'm trying my luck here :)
Cheers
Michael
As a sanity check, make sure the celery is actually installed in the virtual environment you use.
If you are using virtual environment with mod_wsgi, you may need to setup python-home=<path_to_your_virtual_env> in the WSGIDaemonProcess directive.
Example:
WSGIDaemonProcess django python-path=/opt/portal/src/ python-home=/opt/venv/django home=/opt/portal/
You can use the comma-separated list if more than one directory is required in python-path
So, I figured it out. Apparently my virtualenv was pointing to another directory and not to the one apache was using. No idea how this happend. Anyway, after removing and recreating the virtualenv it worked.
Thanks for your help!
I'm a newbie in django and lately I've been trying to use apache as my django web server to test mod_xsendfile for a project. My environment: ubuntu 14.04, python 3.4, apache2, django 1.8, having mod_wsgi installed using pip. I also have downloaded and compiled mod_xsendfile on apache2
I have several problems though:.
Problem1: In the documentation provided at here it states to set mod_xsendfile on and provide a path for it in the virtual host configuration; I searched and noticed the virtual host config takes place in a file named httpd.conf and in ubuntu 14.04 having apache2 installed it seems that the whole structures has changed so I found no such file.
Problem2: I am using mod_wsgi-express for running my server and it performs all the configurations automatically. I have read the documentations in here and here but I couldn't find in any of them being stated where the general configurations (apache configurations to be specific) are pulled from.
Long story short: my question being: how can I enable mod_xsendfile considering my environment and the fact that I am using mod_wsgi-express which generates the configs automatically.
Note:: I run the server using the following command: $python manage.py runmodwsgi
Thanks to Graham Dumpleton here's the solution that worked for me:
I put the following directive into a file named extra.conf:
LoadModule xsendfile_module 'usr/lib/apache2/modules/mod_xsendfile.so'
XSendFile On
XSendFilePath /tmp/PrivateFiles
Then I passed the extra.conf path as an arguement to the --include-file=<> option of modwsgi command as follows:
$python manage.py runmodwsg --include-file=/etc/apache2/sites-available/extra.conf
Plesk on the MediaTemple DV servers uses Python 2.4 for stuff, so the 2.4 install can't be replaced but someone recommended installing a separate python 2.7 install since my app runs on that. I'm new to the whole server thing, so this is new territory. My sense is that I can create a new directory for the source files and use SSH to download the files to said directory and then cd into it and install python 2.7. Then I have to figure out how to make sure Apache knows to use Python 2.7 to run the django app in question. Does this sound correct?
Unless you can make a system wide change to your python installation, you would have to run Apache, python and Django in the same virtual environment. If it is not possible, use gunicorn (instead of apache) to run the Django app in a virtualenv (in a port different from Apache's). If this app runs in a subdomain, you should consider hosting the Django app in a PAAS (Heroku, Google App Engine, etc.) which allow you to easily switch running environments.
Never mind, sorted it. the important thing seemed to be to edit the etc/ld.so.conf by adding usr/local/lib, then running sbin/ldconfig, which then makes ld.so.conf look like:
include ld.so.conf.d/*.conf
/usr/local/lib
Donwload and then compile Python
and use make && make altinstall.
Finally made the switch from Windows to Linux (Ubuntu). I am teaching myself Python + Django.
GOAL: I want to setup a local development environment where I can build a django application and run it locally before deploying it live online.
SO FAR: Python comes installed with Linux. Gedit does also. Ok great. After that I am lost.
I am not sure how to proceed. I am a total Linux noob. I am guessing I need apache running, mysql running, and django to run. I don't know how to setup these things to run or how to set the proper directories or what I need to link to what... really I am not even sure what the right questions are to ask.
Quick answer:
Just install django via their documentation, and you will not even need apache running as it will run its own server. You can use sqlite as a db and you won't even have to worry about mysql. This is if your goal is to learn django and get things running asap.
Otherwise, if you want to take the full route, you'll need to start learning a lot more (which isn't a bad thing). I'd say take a look at some of the slicehost guides for setting up apache, mysql in ubuntu:
http://articles.slicehost.com/2010/5/19/installing-apache-on-ubuntu
http://articles.slicehost.com/2011/3/10/installing-mysql-server-on-ubuntu
And then pick up with just installing django and going from there. The django tutorial is awesome. There's plenty of other documentation out there on the web & tutorials for setting up dev environments.
Assuming you have python
You can install pip:
easy_install pip
From now you can use pip to install your python libraries for example to install django
pip install django
For development I would prefer pydev, it has a support for django with the power of eclipse.
To deploy a site with Python/Django/MySQL I had to do these on the server (RedHat Linux):
Install MySQLPython
Install ModPython
Install Django (using python setup.py install)
Add some directives on httpd.conf file (or use .htaccess)
But, when I deployed another site with PHP (using CodeIgniter) I had to do nothing. I faced some problems while deploying a Django project on a shared server. Now, my questions are:
Can the deployment process of Django project be made easier?
Am I doing too much?
Can some of the steps be omitted?
What is the best way to deploy django site on a shared server?
To enable easy Django deployement I would to the following:
Fisrt-time server configuration
Install mod_wsgi which allow you to run in embedded mode OR in daemon mode.
Install python and virtualenv
In your development environment
Use virtualenv. Take a look at mod_wsgi and virtualenv configuration
Install Django your django version (using python setup.py install)
Install your python libs
Develop your project
Every time you want to deploy
Copy your virtual environment to the production server
Just add an Include directive in your httpd.conf file (or use .htaccess) to your project's apache configuration. As stated in mod_wsgi integration with django documentation, one example of how Apache included file could be configured would be:
Alias /media/ /usr/local/django/mysite/media/
<Directory /usr/local/django/mysite/media>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi
<Directory /usr/local/django/mysite/apache>
Order deny,allow
Allow from all
</Directory>
Automating deployement
I would consider using Fabric to automate deployement
Can the deployment process of django project be made easier?
No. You can script some of this, if you want. However, you're never going to install MySQL, MySQLPuthon, mod_wsgi (or mod_python), or Django again.
You will, however, tweak your application all the time.
Am I doing too much?
No. Python (and Django) are not part of Apache. PHP is embedded in Apache. PHP is exactly like mod_python (or mod_wsgi). Just one piece of the pie. (Apparently, some hosts handle the PHP installation for you, but don't handle the mod_wsgi or mod_python installation.)
Can some of the steps be omitted?
No. However, you only do it once.
What is the best way to deploy django site on a shared server?
You're doing it correctly.
When I deployed another site with php (using CodeIgniter) I had to do nothing
Certainly an unfair comparison. Apparently, they already installed PHP and the database for you. Nice of them.
Also, PHP is not Python. PHP is a plug-in to Apache. Python is "just" a programming language, that requires a separate plug-in to Apache (i.e., mod_python or mod_wsgi).
See How nicely does Python 'flow' with HTML as compared to PHP?
Django hosting support is not as widespread as for PHP, but there are some good options. I can recommend WebFaction - they provide an easy-to-use control panel which offers various combinations of Django versions, Python versions, mod_python, mod_wsgi, MySQL, PostgreSQL etc. They're cost-effective, too. If you use their setup, you get SSH access but just about all of the setting up can be done via their control panel, apart from the actual uploading of your project folder.
Disclaimer: apart from being a happy customer I have no other connection with them.
You didn't have to do anything when deploying a PHP site because your hosting provider had already installed it. Web hosts which support Django typically install and configure it for you.
You just install this already made solution if your allowed to run an image on a virtual machine. I can imagine installations will be done this way in future as complicated security configuration can be done automatically.
Most shared hosting sites run the LAMP (Linux, Apache, MySQL, PHP) stack so deployment is just a matter of copying some files over. If you were using one of the PHP frameworks like CakePHP or something the service hasn't installed (like an imaging library) you'd be going through extra deployment steps as well.
With Django (or Rails, or any other complex framework) you have to set up the stack yourself that one time, then you're good to go.
However, you'll also want to think about post-deployment updating. If it's something you're going to do often you may also want to look into Fabric or Capistrano to help automate that.
P.S. I'll second that WebFaction recommendation. It's as close to one-button installation as I've seen. Pretty happy customer although I mostly use them for test-sites and prototyping.
You can use Python virtualenv and pip (see also "Tools of the Modern Python Hacker: Virtualenv, Fabric and Pip"). I developed my Django project in the virtual environment. I copy the virtual environment file to the production machine when I deploy my application. I use mod_wsgi. You must write that in the mod_wsig file:
import site
site.addsitedir('C:\PythonVirtualEnv\IntegralEnv\Lib\site-packages')