I want to monitor/keep track of all the files uploaded using web server (mainly using PHP/Apache
There is no easy way. You can find all files using the move_uploaded_file
function, but this will only intercept POST file uploads. AJAX uploads such as HTML5/PLupload will not be recognized.
The question is, why do you want to track "all uploaded files"? Since you don't even know what those files are nor where they are, there seems to be little point in knowing the file names, sizes, and ownerships - which is all you're going to be able to get.
If you're trying to intercept alterations to the system, e.g. web attacks, then you'd be much better served by tripwire
, and/or some log scanning utility, or possibly Snort, or specialized security packages (e.g. for Wordpress). Or you might be interested in famd
, or decide to be proactive and deploy (and configure, and maintain) AppArmor.
If it is accountability you're after, you will need to modify the upload scripts no matter what. And you'll need to do that on a script-by-script basis if you're running several different upload frameworks.
If you want to track traffic or quotas, there are much better ways.
But basically, you should not have to worry about files uploaded on your hosted web sites, unless you have other problems upstream. Worrying about file uploads makes me suspect yours, as stated, is a XY problem.
If you're still of the idea of monitoring files created (as stated before, uploaded is too restrictive), possibly the simplest way is to set up a strace
process, but it depends now on how PHP is called - is it an Apache module, or CGI, or FPM? For the Apache module, assuming the binary is called httpd
:
strace -f -p "$( pidof httpd )" -e open 2>&1 | grep -F -v ', O_RDONLY'
will get you something like,
[pid 28882] open("/var/lib/php5/sess_8v107eun48rj0u42uf9ncplrbobj4cqackscb2thx1138k78uk01", O_RDWR|O_CREAT, 0600) = 12
[pid 29739] open("/var/lib/php5/sess_8v107eun48rj0u42uf9ncplrbobj4cqackscb2thx1138k78uk01", O_RDWR|O_CREAT, 0600) = 12
[pid 28882] open("/srv/www/wiki.matrix.boa/data/boawiki.sqlite", O_RDWR|O_CREAT|O_CLOEXEC, 0644) = 13
[pid 29739] open("/srv/www/wiki.matrix.boa/data/boawiki.sqlite", O_RDWR|O_CREAT|O_CLOEXEC, 0644) = 13