Bob and the Knowledge Factory / Apache Web Server / General Issues / DJANGO
DJANGO |
|||||
Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. A high-level Web framework is software that eases the pain of building dynamic Web sites. It abstracts common problems of Web development and provides shortcuts for frequent programming tasks.
Django grew organically from real-world applications written by a Web development team in Lawrence, Kansas. It was born in the fall of 2003, when the Web programmers at the Lawrence Journal-World newspaper, Adrian Holovaty and Simon Willison, began using Python to build applications. Django is now an open source project with contributors across the planet, the original World Online developers still provide central guidance for the framework’s growth, and World Online contributes other important aspects such as employee time, marketing materials, and hosting/bandwidth for the framework’s Web site Django was designed to handle two challenges: the intensive deadlines of a newsroom and the stringent requirements of the experienced Web developers who wrote it. It lets you build high-performing, elegant Web applications quickly.
How we can setup Django in cPanel Server? In order to setup Django, there are certain server requirements. Lets move on to that. Requirements 1. Python 2. mod_wsgi 3. Apache 4. Django Install PythonBeing a Python Web framework, Django requires Python. It works with any Python version from 2.4 to 2.6 (due to backwards incompatibilities in Python 3.0, Django does not currently work with Python 3.0 ). Before installing Python, its dependencies needed to be installed in the server. Installing Python 2.5 dependenciesInstall sqlite3:$ wget http://www.sqlite.org/sqlite-amalgamation-3.6.4.tar.gz Install Python 2.5Download Python 2.5 source package, unzip, and enter working directory:$ cd Configure Python 2.5 so that we're not overwriting the system's python installation:$ ./configure --prefix=/opt/python2.5 --with-threads --enable-shared Make and install:$ make Add an alias to root's .bash_profile:alias python='/opt/python2.5/bin/python' Make a symbolic link:$ ln -s /opt/python2.5/bin/python /usr/bin/python2.5 Configure ld to find your shared libs:$ cat >> /etc/ld.so.conf.d/opt-python2.5.conf Test python 2.5 installation:$ python You should get an interactive Python 2.5 session like: Python 2.5 (r25:51908, Nov 9 2008, 23:18:24) >>> Exit Install setuptools:-------------------- Setuptools is a Python module that helps to compile, distribute and install Python packages by wrapping them into "egg"s. Eggs contain additional information to process dependencies, etc. $ cd Install MySQLdb package:-------------------------------- If you plan to use Django’s database API functionality, you’ll need to make sure a database server is running. Django supports many different database servers and is officially supported with PostgreSQL, MySQL, Oracle and SQLite (although SQLite doesn’t require a separate server to be running). In addition to a database backend, you’ll need to make sure your Python database bindings are installed.
Here we go for MySQL, hence we need MySQLdb $ cd Verify Python 2.5 Installation:$ cd Installing mod_wsgiIn order to use Django on a production site, use Apache with mod_wsgi. The mod_wsgi is similar to mod_perl – it embeds Python within Apache and loads Python code into memory when the server starts. Code stays in memory throughout the life of an Apache process, which leads to significant performance gains over other server arrangements. Make sure you have Apache installed, with the mod_wsgi module activated. Django will work with any version of Apache that supports mod_wsgi.Configure mod_wsgi to link with Python 2.5 shared libs:$ cd /opt/python2.5/lib/python2.5/config Make and install:$ make Add mod_wsgi to Apache 2.x:Simply add these lines in the apache configuration file. LoadModule wsgi_module /usr/local/apache/modules/mod_wsgi.soSetup a Django 1.0 test project Create a new user/domain via WHM/cPanel Edit users .bash_profile:alias python='/opt/python2.5/bin/python' Create a new project directory:$ mkdir -p /home/username/sites/domain.com Create your apps .wsgi script:$ pico /home/username/public_html/test.wsgi #!/opt/python2.5/bin/python $ chown username: /home/username/public_html/test.wsgi Setup a vhost include (as root)$ mkdir -p /usr/local/apache/conf/userdata/std/2/username/domain.com <IfModule mod_alias.c> <IfModule mod_wsgi.c> WSGIScriptAlias / /home/username/public_html/test.wsgi # This fixes the broken ErrorDocument directive we inherit that breaks auth $ /scripts/verify_vhost_includes domain.com should now be serving a django site. To restart a django instance:$ touch ~/public_html/test.wsgi
|
|||||