In Beginning PHP6, Apache, MySQL Web Development (Timothy Boronczyk et al, Wiley, 2009), Chapter 7 (Manipulating and Creating Images with PHP), on page 178 we are told to create a subdirectory in the web documents directory (htdocs or its equivalent, such as /var/www on Ubuntu). Then we are told create a couple of web pages that attempt to upload an image into that directory. But, when I tried this, the upload failed because Apache did not have write-permission in the images subdirectory. The problem was that the subdirectory was owned by root but Apache was being run by user www-data.
I was able to fix this by changing the owner of the subdirectory to the user (and group) that the Apache process was run under:
sudo chown www-data:www-data /var/www/images
Now the web pages could successfully upload images to the subdirectory.
(I then had another problem in that the web pages couldn't display the uploaded images, but that was down to me being tidy and putting the web pages in a subdirectory of their own (/var/www/ch07-1). I fixed this by changing "images" to "../images" in an <img> tag in one of the web pages.)