sudo apt-get update
sudo apt-get upgrade
sudo raspi-config
sudo apt-get install motion
sudo nano /etc/motion/motion.conf
... daemon on ... stream_port 8081 ... stream_localhost off ... width 640 ... height 480 ... framerate 25 ...
sudo nano /etc/default/motion
... start_motion_daemon=yes ...
sudo service motion restart