lost and found ( for me ? )

ubuntu 12.04 : install nginx

# tail -1 /etc/lsb-release ;uname -ri
3.2.0-49-virtual x86_64

# apt-get install -y nginx

# nginx -v
nginx version: nginx/1.1.19

start nginx
# /etc/init.d/nginx start
Starting nginx: nginx.

[ install the latest nginx from PPA ]

at first, uninstall nginx if you have installed

root@ubuntu-vm2:~# /etc/init.d/nginx stop
Stopping nginx: nginx.

root@ubuntu-vm2:~# apt-get remove nginx -y

root@ubuntu-vm2:~# apt-get autoremove -y

add a PPA repo.
root@ubuntu-vm2:~# egrep nginx /etc/apt/sources.list
# for nginx
deb http://ppa.launchpad.net/nginx/development/ubuntu precise main
deb-src http://ppa.launchpad.net/nginx/development/ubuntu precise main

root@ubuntu-vm2:~# apt-get update
root@ubuntu-vm2:~# apt-get install nginx

root@ubuntu-vm2:~# nginx -v
nginx version: nginx/1.5.0

root@ubuntu-vm2:~# service nginx start
* Starting nginx nginx                                                  [ OK ]

root@ubuntu-vm2:/etc/nginx# pwd
root@ubuntu-vm2:/etc/nginx# ls
conf.d          koi-win        naxsi.rules       proxy_params     sites-enabled
fastcgi_params  mime.types     naxsi_core.rules  scgi_params      uwsgi_params
koi-utf         naxsi-ui.conf  nginx.conf        sites-available  win-utf

apache + Django ( ubuntu 12.04 )

I am newbie to Django :D

many thanks.

root@ubuntu1204-vm4:~# python --version
Python 2.7.3
root@ubuntu1204-vm4:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.2 LTS
Release:        12.04
Codename:       precise

#  apt-get install apache2 libapache2-mod-wsgi python-setuptools python-pip

install Django
# pip install django
Successfully installed django
Cleaning up...

[ set up ]

create a directory
# mkdir /srv/www
# mkdir /srv/www/wsgi

put “app.wsgi” under /srv/www/wsgi directory.
# cat /srv/www/wsgi/app.wsgi
def application(environ, start_response):
   status = '200 OK'
   output = 'Hello World!'

   response_headers = [('Content-type', 'text/plain'),
                       ('Content-Length', str(len(output)))]
   start_response(status, response_headers)

   return [output]

enable a new site.
# cat /etc/apache2/sites-available/wsgi
<VirtualHost *:80>

   ServerName wsgi.djangoserver
   DocumentRoot /srv/www/wsgi

   <Directory /srv/www/wsgi>
       Order allow,deny
       Allow from all

   WSGIScriptAlias / /srv/www/wsgi/app.wsgi


enable “wsgi” site, disable “default” site and then restart apache2
# a2ensite wsgi

# a2dissite default

root@ubuntu1204-vm4:~# /etc/init.d/apache2 restart
* Restarting web server apache2

access to apache’s IP

make another project

make a new project
root@ubuntu1204-vm4:/srv/www# pwd
root@ubuntu1204-vm4:/srv/www# django-admin.py startproject test01
root@ubuntu1204-vm4:/srv/www# mkdir /srv/www/test01/apache

# cat /srv/www/test01/apache/django.wsgi
import os
import sys


os.environ['DJANGO_SETTINGS_MODULE'] = 'test01.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

enable a new site called “test01”
# cat /etc/apache2/sites-available/test01
# cat /etc/apache2/sites-available/test01
<VirtualHost *:80>

   ServerName test01.djangoserver
   DocumentRoot /srv/www/test01

   <Directory /srv/www/test01>
       Order allow,deny
       Allow from all

   WSGIDaemonProcess test01.djangoserver processes=2 threads=15 display-name=%{GROUP}
   WSGIProcessGroup test01.djangoserver

   WSGIScriptAlias / /srv/www/test01/apache/django.wsgi


root@ubuntu1204-vm4:/srv/www# a2ensite test01
Enabling site test01.
To activate the new configuration, you need to run:
 service apache2 reload
root@ubuntu1204-vm4:/srv/www# /etc/init.d/apache2 restart

# ls /etc/apache2/sites-enabled/
test01  wsgi

please note that your client needs to map test01.djangoserver to IP address.
So it would be easy to configure /etc/hosts file on the client.
# cat /etc/hosts test01.djangoserver

apache mod_python : upload files over post method

many thanks!

root@ubuntu-vm2:~# tail -1 /etc/lsb-release ;uname -ri
3.2.0-49-virtual x86_64
root@ubuntu-vm2:~# apache2ctl -v
Server version: Apache/2.2.22 (Ubuntu)
Server built:   Jul 12 2013 13:37:10

on the apache server, place the following python script under /var/www/python_works directory.
root@ubuntu-vm2:~# cat /var/www/python_works/index.py
import os

s = """\
<h2>Hello %s!</h2>

def index():
  return s % 'World'
def everybody():
  return s % 'everybody'

def form():
  return """\
<form enctype="multipart/form-data" action="./upload" method="post">
<p>File: <input type="file" name="file"></p>
<p><input type="submit" value="Upload"></p>

def upload(req):
  try: # Windows needs stdio set for binary mode.
     import msvcrt
     msvcrt.setmode (0, os.O_BINARY) # stdin  = 0
     msvcrt.setmode (1, os.O_BINARY) # stdout = 1
  except ImportError:

  # A nested FieldStorage instance holds the file
  fileitem = req.form['file']

  # Test if the file was uploaded
  if fileitem.filename:

     # strip leading path from file name to avoid directory traversal attacks
     fname = os.path.basename(fileitem.filename)
     # build absolute path to files directory
     dir_path = os.path.join(os.path.dirname(req.filename), 'files')
     open(os.path.join(dir_path, fname), 'wb').write(fileitem.file.read())
     message = 'The file "%s" was uploaded successfully' % fname

     message = 'No file was uploaded'
  return """\
<p><a href="./form">Upload another file</a></p>
""" % message

make directory under /var/www/python_works.
uploaded files are copied to /var/www/python_works/files directory.
root@ubuntu-vm2:/var/www/python_works# pwd
root@ubuntu-vm2:/var/www/python_works# mkdir files

root@ubuntu-vm2:/var/www/python_works# chmod 777 files/

access to http://apache IP/python_works/index.py/form

select a file you would like to upload to the apache server and then click “Upload”

15M.png was copied to /var/www/python_works/files directory.

root@ubuntu-vm2:~# ls /var/www/python_works/files/

php : upload large files ( Ubuntu 12.04 )

there are file size limitation options you can upload in /etc/php5/apache2/php.ini  file.

In case of ubuntu apache with php5, you can change allowable file size by modifying /etc/php5/apache2/php.ini
; Maximum size of POST data that PHP will accept.
; http://php.net/post-max-size
#post_max_size = 8M
post_max_size = 500M

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
#upload_max_filesize = 2M
upload_max_filesize = 500M

restart apache2
# /etc/init.d/apache2 restart

If you upload larger files without modifying above options, you will see the following error.
[error] [client] PHP Warning:  POST Content-Length of 10486037 bytes exceeds the limit of 8388608 bytes in Unknown on line 0, referer: