Run an external command on page request - apache

Problem
I have an Apache server, and I'm trying to add my own custom analytics to it. What I want is to have the server call a script whenever a page is requested, and for that script to record the requested URL.
If it's not possible to run an external command, I'd want Apache to POST to a URL to record the page visit.
Research
I've tried searching for a way to run an external command from Apache, but everything I've seen is a CGI script. I don't want to change how Apache handles the URL, I just want a way to give it to a script to record it.
Question
Is there a way I can have Apache run an external command or POST to a URL whenever a page is requested?

Apache already records the URL for every request - in the access log. Further, its trivial to drop in a filter script between Apache and the file if you want to trigger more complex and specific side effects.
I don't want to change how Apache handles the URL
Why do you believe using a script handler (no sane person uses CGI nowadays) will change the way the request is handled?
Perhaps if you explained why you want to record the URL you might get more appropriate answers.

Related

Redirecting all traffic to a script

I am on Centos 6.5 with Apache2 and Perl 5.23. I need to pass all traffic to the single perl script, check this request in a database, and show needed content (have both static and dynamic content).
The problem is I don't know how not to get caught to the infinite loop in mod_rewrite.
F.e. first time I pass a request to a script script sees that the user needs a static content and redirects it to the needed page, but this way the user gets to the .htaccess rules again.
I thought to add some kind of a parameter, but not sured. Need your help!

List of served files in apache

I am doing some reverse engineering on a website.
We are using LAMP stack under CENTOS 5, without any commercial/open source framework (symfony, laravel, etc). Just plain PHP with an in-house framework.
I wonder if there is any way to know which files in the server have been used to produce a request.
For example, let's say I am requesting http://myserver.com/index.php.
Let's assume that 'index.php' calls other PHP scripts (e.g. to connect to the database and retrieve some info), it also includes a couple of other html files, etc
How can I get the list of those accessed files?
I already tried to enable the server-status directive in apache, and although it is working I can't get what I want (I also passed the 'refresh' parameter)
I also used lsof -c httpd, as suggested in other forums, but it is producing a very big output and I can't find what I'm looking for.
I also read the apache logs, but I am only getting the requests that the server handled.
Some other users suggested to add the PHP directives like 'self', but that means I need to know which files I need to modify to include that directive beforehand (which I don't) and which is precisely what I am trying to find out.
Is that actually possible to trace the internal activity of the server and get those file names and locations?
Regards.
Not that I tried this, but it looks like mod_log_config is the answer to my own question

Masking or changing certain text in URL

I'm using Composer with Toran Proxy hosted on a personal server to manage my package dependencies for Symfony2, today I encountered a problem, one of the URLs that Composer needs to download ends with dependecy-injection.json, every other URL downloads OK, but having those words it's something the proxy doesn't like, so it blocks it.
I have full access to the server, is there a way to mask o change that certain URL to make it look like another one and so "bypassing" the proxy?
This is the URL:
http://domainexample/toran/web/app.php/repo/packagist/p/symfony/dependency-injection.json
I'm using Apache2 as web server.

Append file date to css file in apache

I am trying to find a way to make sure browsers dont cache versions of my css files everytime I push a new update.
I was thinking the best way would be to somehow get the file timestamp of the css file on the filesytem and append append it tot he css URL somehow like www.mysite.com/css/style.css?13245645434
Is this possible at all? If not, then any idea how i can make sure the browser gets a new version of the file when it is updated? I dont want to eliminate browser cache all together because if the file hasnt been touched then i would like it to be cached. However, when i push a new update i would like to someone tell the browser that.
I understand i can write server side code to put the style.css?2342343 in but i want to see if its possible through apache at all.
Thanks
everytime I push a new update
How do you push updates? If there is an automated build process you have then that is the right place to rewrite your URLs.
If you wanted to do the rewriting via apache you'd need a module which would parse the html and rewrite the links. That would not be optimal.
Lastly, consider rewriting to /css/42/style.css (where 42 is the current version) because in case you cache your site through a proxy or CDN, query parameters may not work.

Getting Apache to execute command on every page view

Is there any way to get Apache to run a command/program every time a web page is requested? I know I could scan the logs for new entries every minute or so, but can I get Apache to directly call the command? There might be an option like this in one of the configuration files, but if there is I don't know what it is. My server is running Ubuntu 9.04.
You can use the CustomLog directive to pipe the access log to a script or program, which could be useful in your situation. All you would have to do is set up a while loop (or similar structure) on STDIN in the language of your choice and then execute your command from there.
http://httpd.apache.org/docs/2.2/logs.html#piped