1- Install and configure ‘Web Server’ and MySQL Database
Using yum I installed the following packages:
$ sudo yum groupinstall “Web Server”
$ sudo yum install make automake gcc gcc-c++ kernel-devel
$ sudo yum install mysql-server mysql-devel
Enable services to be launched at system start-up and run them
$ sudo chkconfig httpd on
$ sudo chkconfig mysqld on
$ sudo service httpd start
$ sudo service mysqld start
Verify that everything is working
$ sudo service httpd status
$ sudo service mysqld status
$ mysql —user root —execute “select version()”
Configure database root password and basic stuff. Leave the test database in order to make tests with django.
$ sudo mysql_secure_installation
I wanted to put my applications in the $HOME/public_html of an user so I changed the config of the server to use the web user directories. For that:
$ getsebool -a | grep httpd
$ sudo setsebool -P httpd_enable_homedirs on
# Read and make the modifications in the file/etc/httpd/conf.d/userdir.conf and restart the web server
$ sudo service httpd restart
Create public_html folder and assign permissions
$ mkdir ~/public_html
$ chmod 711 ~username
$ chmod 755 ~/public_html
2- Install and configure Python, virtualenv, and Django
Normally, global things with yum and easy_install and local ones with pip
$ sudo yum install python
$ sudo yum install python-setuptools python-devel
$ sudo easy_install pip
$ sudo pip install virtualenv
Defining a virtualenv
$ mkdir ~/public_html/testAppDjango
$ cd ~/public_html/testAppDjango
$ virtualenv env —no-site-packages
$ source env/bin/activate
$ pip install django -U
$ django-admin.py startproject testproject
$ cd testproject
$ python manage.py runserver 8000
By now it should run. Stop the server and continue
3- Configuring connection to MySQL and the mod_wsgi
$ pip install MySQL-python
$ sudo yum install mod_wsgi
$ python manage.py startapp testapp
# Modify the settings.py as follows:
- In DATABASES > ‘ENGINE’ : ‘django.db.backends.mysql’, ‘NAME’ : ‘test’, ‘USER’ : ‘root’, ‘PASSWORD’ : ‘password’, ‘HOST’ ; ‘localhost’, ‘PORT’ : ”
- Activate admin in installed_apps (make the same change in the urls.py file).
The ones who knows a little bit of Django, knows what I’m talking about. Now, use your editor to create the following file. The most important one.
$ gedit /etc/httd/conf.d/testApp.conf
Insert the following text:
WSGIPythonPath /home/username/public_html/testAppDjango/testproject:/home/username/public_html/testAppDjango/env/lib/python2.7/site-packages
<VirtualHost *:80>
WSGIScriptAlias / /home/username/public_html/testAppDjango/testproject/testproject/wsgi.py
Alias /static/ /home/username/public_html/testAppDjango/testproject/testproject/static/
Alias /media/ /home/username/public_html/testAppDjango/testproject/testproject/media/
<Directory /home/username/public_html/testAppDjango/testproject>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
<Directory /home/username/public_html/testAppDjango/testproject/testproject/static/>
Order deny,allow
Allow from all
</Directory>
<Directory /home/username/public_html/testAppDjango/testproject/testproject/media/>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Synchronize the database and see what happens in the browser http://localhost
$ python manage.py syncdb
NOW IT SHOULD WORK BUT …. A 500 HTTP ERROR APPEARED IN THE BROWSER :(. Look in the Apache error log:
$ sudo less /etc/httpd/logs/error_log
In my server logs appeared the following #$f..ck@ error:
Error Loading MySQLdb module: /home/username/public_html/testAppDjango/env/lib/python2.7/site-packages/_mysql.so: failed to map segment from shared object: Permission denied
After a deep search on Google and some hopeless guides that told difficult things to recompile libraries and all that stuff I found that this problem is related to a security system included in Fedora the SELinux. Some people have deactivated it and their apps work, but my production server can’t be modified in that way so other guy's guide and a little troubleshot in a website gave me some useful commands:
$ cd /home/username/public_html/testAppDjango/env/lib/python2.7/site-packages/
$ ll -Z
# The _mysql.so file shoud appear as a lib_t not a httpd_user_content.
# With the following it tells that is a shared lib:
$ chcon -t shlib_t *.so
NOW FOR ME IT WORKED!!
Next, do some important things to display the website correctly and to maintain it:
$ cd ~/public_html/testAppDjango/
$ pip freeze > requirements.txt
$ cd testproject/testproject
$ mkdir static
$ mkdir media
$ cp ../../env/lib/python2.7/site-packages/django/contrib/admin/static/admin/* .
Just if you want to verify, my only dependencies in requirements file are:
Django==1.5.3
MySQL-python==1.2.4
wsgiref==0.1.2
Hope this will be useful. RaC!
No hay comentarios.:
Publicar un comentario