Thursday, May 22, 2014

Setup first web application with Django on RedHat

This artical introduces how to setup a simple web application with Django on RedHat, also describes how to troubleshoot the potential errors.

0: Prerequisite Without these component, you may meet errors in the following steps.
rpm -ivh /mntRedHat57/Server/zlib-devel-1.2.3-4.el5.x86_64.rpm
yum install /mntRedHat57/Server/openssl-devel-0.9.8e-20.el5.x86_64.rpm
yum install /mntRedHat57/Server/sqlite-devel-3.3.6-5.x86_64.rpm

1: Install Python 2.7.5
(1) wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
(2) cd Python-2.7.5
(3) ./configure
(4) make
(5) export PATH=/root/installer/Python-2.7.5:$PATH
Set Python 2.7.5 as default python, /root/installer/Python-2.7.5 is the Python installation path
(6) Check that Python 2.7.5 can work well

2: Install PIP
(1) Download get-pip.py from this page https://pip.pypa.io/en/latest/installing.html
(2) python get-pip.py

3: Install Django
(1) pip install Django
If you meet "bad interpreter: Permission Denied", go to /usr/local/bin/pip, replace first line #!/usr/local/bin/python2.7 with your actual Python path #!/root/installer/Python-2.7.5/python

Check Django is installed by below command.
python -c "import django; print(django.get_version())"
(2) django-admin.py startproject mysite
Go to a location you want to save web app, then run this command to start a new web app.
(3) python manage.py runserver 8080
Start the web server then you can access 127.0.0.1:8080. The default port number is 8000 if you don't specify. Now the web server can be accessed only in the local host. If you access this web server from another machine, you will meet "Page is not available" or 404 not found error. You need to specify the IP address in the command as below step.
(4) python manage.py runserver IP:8080
With server IP info in the command, the new web server can be accessed from another machine. Below is the expected output.
[root@Ifx mysite]# python ../manage.py runserver 172.19.112.29:8082
Validating models...
0 errors found
May 22, 2014 - 15:15:24
Django version 1.6.5, using settings 'mysite.settings'
Starting development server at http://172.19.112.29:8082/
Quit the server with CONTROL-C.

4:Follow this link to evolution your web app

No comments:

Post a Comment