Instalar apache2 + mod_python en Debian

Hechamos mano de nuestro querido apt-get y tecleamos lo siguiente:

apt-get install apache2
apt-get install libapache2-mod-python

Abrimos el fichero de configuración de nuestro sitio por defecto o del sitio en el que queramos ejecutar ficheros .py.

nano /etc/apache2/sites-available/default

Añadimos las líneas en rojo:

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On

# This directive allows us to have apache2′s default start page
# in /apache2-default/, but still have / go to the right place
# RedirectMatch ^/$ /apache2-default/
</Directory>

Reiniciamos el servidor:

/etc/init.d/apache2 restart

Creamos un fichero de prueba en /var/www llamado test.py con el siguiente contenido:

nano /var/www/test.py

def index(req):
return “Test OK”;

Y para comprobar si todo ha ido bien abrimos http://localhost/test.py

Y ya estaría instalado ;)

Categorized: Uncategorized
Tagged:

6 comments on “Instalar apache2 + mod_python en Debian

  1. Pingback: Haciendo tile cache de WMS en ubuntu « igo software

  2. Muy buen post! bastante claro y directo

    Una aclaración por el formateo, en el ejemplo existe un espacio delante de “return …” que no se vé:

    def index(req):
    return “Test OK”;

    Saludos

  3. Buen día,

    Al reiniciar el server de apache me aparece el error de abajo, como puedo solucionarlo?

    Muchas gracias por su ayuda.

    Saludos.

    root@jhcanof-desktop:~# /etc/init.d/apache2 restart
    Syntax error on line 14 of /etc/apache2/sites-enabled/000-default:
    AddHandler requires at least two arguments, a handler name followed by one or more file extensions
    Action ‘configtest’ failed.
    The Apache error log may have more information.
    …fail!
    root@jhcanof-desktop:~#

  4. Hola jhcanof, comprueba que hayas puesto un espacio entre mod_python y .py en la configuración de Apache. Si no funciona pegame lo que tengas desde la línea 11 a la 17.

    Saludos!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>