Professional Documents
Culture Documents
Configuración Python (Django), Pogressql, PhpPgAdmin Base Apache.
Configuración Python (Django), Pogressql, PhpPgAdmin Base Apache.
Prerequisites
Before installing new packages, it is always a good practice to update your system packages and
package indexes. To do that execute:
apt-get update
apt-get upgrade
Installing Apache
Since this text focuses on using Apache to serve the application, the server itself is necessary. To install
the necessary packages execute:
Straight after installation Apache will already be running. You can check whether the Apache web
server has been properly set-up by opening your web browser and pointing it to the server IP address.
You should see a simple It works! page on the screen.
To do that execute:
This command will install pip and virtualenv from the Debian package repository. You can verify that
both tools have been properly installed by running them with
--version
switch.
cd /var/www
mkdir sampleapp
cd sampleapp
virtualenv env
where
env
is the virtual environment name - it could be any other word. The output from this
command should look like this:
The virtual environment is now ready and can be used in two different ways.
One way is to run commands using virtual environment interpreter directly. With this method it is
necessary to always remember to execute the correct interpreter or
pip
instance, as there is a
possibility to run a system-wide one.
source env/bin/activate
the environment name will then be prepended to the command line as such
and all commands executed will be using local virtual environment versions
deactivate
(env)root@django:/var/www/sampleapp# deactivate
root@django:/var/www/sampleapp#
The freshly created environment will be used to store all necessary dependencies, including Django
and related libraries. It will also be used by Apache and mod_wsgi later on to serve the application
using correct dependencies.
The last messages shown after executing this command should look like this
Django is now installed inside virtual environment and is not available from within system-wide Python
installation. You can verify that behavior by importing
django
module using both interpreters
root@django:/var/www/sampleapp# python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
>>> exit()
root@django:/var/www/sampleapp# env/bin/python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>>
Please execute:
This will run a test server bound to all interfaces on port 8000. The output should look like this:
Validating models...
0 errors found
April 08, 2014 - 12:29:31
Django version 1.6.2, using settings 'sampleapp.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
If you open your server IP address with port 8000 in your browser (the address should look
like
http://<ip address>:8000/
) you should see the It worked! example Django page. This is the result we
will work towards using Apache web server instead of the built-in Django development server.
Since the Django application is working properly, we can proceed to pair the application with Apache.
The next step will be to configure default Apache virtual host that at the beginning of the article served
It works! page to serve our Django application.
nano /etc/apache2/sites-enabled/000-default
WSGIDaemonProcess sampleapp
python-path=/var/www/sampleapp:/var/www/sampleapp/env/lib/python2.7/site-packages
WSGIProcessGroup sampleapp
WSGIScriptAlias / /var/www/sampleapp/sampleapp/wsgi.py
If we were using global Python installation and global Django instance, the
python-path
directive would
not be necessary. However, using virtual environment makes it obligatory to specify the alternate
Python path so that mod_wsgi will know where to look for Python packages.
The path must contain two directories: the directory of Django project itself -
/var/www/sampleapp
and directory of Python packages inside our virtual environment for that project
-
/var/www/sampleapp/env/lib/python2.7/site-packages
. Directories in path definition are delimited
using a colon sign.
The second line tells that particular virtual host to use the WSGI daemon created beforehand, and as
such, the daemon name must match between those two. We used
sampleapp
in both lines.
The third line is the most important, as it tells Apache and mod_wsgi where to find WSGI configuration.
The
wsgi.py
supplied by Django contains the barebone default configuration for WSGI for
servingDjango application that works just fine and changing the configuration in this file is out of this
article scope.
After that, upon opening the web browser on your server IP address, without any additional ports, you
should see the same Django page as before instead of initial It works! page that we have seen earlier.
Installing PostgreSQL
By default PostgreSQl is available in Ubuntu repository. To install PostgreSQL in Ubuntu Server 13.10 is
simple, just run the following commands:
sudo apt-get update
sudo apt-get install postgresql
Now psql will ask for a new password twice. Enter the new password and continue. Type \q and hit
enter to quit.
To create a database the following command can be run from the terminal:
$ sudo -u postgres createdb mydb
Installing and Configuring PhpPgAdmin
phpPgAdmin
is a php-based web application that provides a GUI interface for the postgresql. It
performs a similar function to phpMyAdmin, which allows users to manipulate database information in
a visual program in MySQL.
Execute the following command to installing PhpPgadmin in ubuntu server:
sudo apt-get install phppgadmin
By default you can only access
phppgadmin
locally. If you want to access remotely from another
computers change the following file:
sudo nano /etc/apache2/conf.d/phppgadmin
Comment out the line: