A lot of people have been asking me about the django configuration and its installation. I published a post regarding its installation. Its quite easy because you don't have to do anything you just need to run a script and its installed. The next thing is configuring django on Cent OS. So i thought of writing a post for newbie's to Linux and django environment to make them configure django on a freshly installed Cent OS
If the Cent OS is freshly installed then it would not have pip and easy_install. So first we need to install these tools. Its not mandatory but pip is used for installing and managing Python packages. Easy_install is used for downloading, installing, uninstalling, upgrading and building python packages easily.
Now that you have installed the main python tools. Its time for some dependencies to be installed
It will save a lot of time if they are installed on this stage and prevent errors that will pop in future during the process.
Now that dependencies are installed we are good to go.
Now change mode of wsgi file so that it can be called from httpd
Now we have to edit httpd.conf
Paste these few lines that are necessary to show your required folders. I have to do this in my case beacause i have similar folders in my site
Now that you have done all the settings you need to make a wsgi file and place it into your project directory
Paste the given code into the file
Enjoy Python and Django and make applications.
Feel free to ask any queries in the comments below.
If the Cent OS is freshly installed then it would not have pip and easy_install. So first we need to install these tools. Its not mandatory but pip is used for installing and managing Python packages. Easy_install is used for downloading, installing, uninstalling, upgrading and building python packages easily.
Easy_Install:wget http://peak.telecommunity.com/dist/ez_setup.pypython ez_setup.py
PIP
easy_install pip
Now that you have installed the main python tools. Its time for some dependencies to be installed
It will save a lot of time if they are installed on this stage and prevent errors that will pop in future during the process.
Dependencies:
- yum install httpd-devel
- yum install make
- yum install gcc(compiler to make/complie C files)
- or alternatively yum install python-devel
- or alternatively yum install gcc-c++
- yum install MySQL-python
Now that dependencies are installed we are good to go.
INTALL DJANGO
pip install django
INSTALL MySQL
yum install mysql mysql-server
INSTALL HTTPD
yum install httpd. Type the command service httpd restart to check the status you can type service httpd status.
INSTALL MOD_WSGI yum install mod_wsgiIf this command does not work properly then install manually through wget command
tar xzf mod_wsgi-2.6.tar.gz
cd mod_wsgi-2.6
./configure
--with-python=/usr/bin/python2.5
make
sudo make install
Now change mode of wsgi file so that it can be called from httpd
chmod 755 /etc/httpd/modules/mod_wsgi.so
Now we have to edit httpd.conf
vi /etc/httpd/conf/httpd.confEdit and add the given line in LoadModule section
LoadModule wsgi_module modules/mod_wsgi.soAdd WSGIScriptAlias
WSGIScriptAlias / /var/www/sitefolder/<project>/wsgi.py
Paste these few lines that are necessary to show your required folders. I have to do this in my case beacause i have similar folders in my site
AliasMatch ^/([^/]*\.css) /var/www/sitefolder/<project>/static/css/$1AliasMatch ^/([^/]*\.[jpg|gif|png]) /var/www/<sitefolder/<project>/static/images/$1 Alias /media/ /var/www/wtoolgui/sitefolder/<project>/media/Alias /static/ /var/www/wtoolgui/sitefolder/<project>/static/ <Directory /var/www/<project>/static/ > Order deny,allow Allow from all</Directory> <Directory /var/www/<project>/media/ > Order deny,allow Allow from all</Directory> WSGIRestrictStdout Off
Now that you have done all the settings you need to make a wsgi file and place it into your project directory
vi /var/www/<project>/wsgi.py
Paste the given code into the file
import osimport sys path = '/var/www/<project>/'if path not in sys.path: sys.path.append(path) os.environ['DJANGO_SETTINGS_MODULE'] = '<project>.settings' import django.core.handlers.wsgiapplication = django.core.handlers.wsgi.WSGIHandler()Now you are all set up to make a django project. Make models after creating app and then run the command python manage.py syncdb to add those tables in the database.
Enjoy Python and Django and make applications.
Feel free to ask any queries in the comments below.
No comments:
Post a Comment