Why isn't apache serving the page? mod_rewrite seems to have found the right file - apache

The project I'm working on has a fairly long & complicated list of RewriteRules, separated into 2 .htaccess files for legacy reasons. I'm putting the app into a Docker container to make it easier to on-board new developers, but the Ubuntu/Apache combo is choking on the RewriteRules and giving me an HTTP 500.
Docker image: php:5.6-Apache
Apache Version: 2.4
I boosted the logging to trace4 and it appears to figure out the right file - here's the last line of the mod_rewrite debug output
[Thu Mar 16 09:08:15.459987 2017] [rewrite:trace1] [pid 17] mod_rewrite.c(475): [client 192.168.99.1:63990] 192.168.99.1 - - [rs.dev/sid#7f51cf6fece0][rid#7f51cf61c8f8/initial/redir#3] [perdir /var/www/appname/public_html/production/] pass through /var/www/appname/public_html/production/login.php
The file '/var/www/appname/public_html/production/login.php' exists, and is the file that should be loaded. However, the response is sent as a 500, (and the page doesn't load). I'm using the /login URL here as an example, but it happens on all URLs.
This works on the localhost of a Mac running macOS, and it works in cPanel servers, I just can't seem to get it running in the Ubuntu base that Docker's providing me.
Does anyone know why Apache would use mod_rewrite and appear to identify the correct file, but then not use the file?
For reference, the entire log output from the request is on pastebin.

It turns out that my problem wasn't in the Rewriting at all, I had forgotten to create a file that PHP was trying to require, so it was throwing a PHP error. However, the way the logs were configured, the error was disappearing into the ether, (or into a log I haven't found yet).
Let that be a lesson - even if you're absolutely sure where the error is, you might still be wrong!

Related

Apache Runs HTML File As Script?

I'm having a bit of an issue with setting up an Apache installation for a project I inherited. The original installation the project uses is Apache 2.2, but I'm currently using 2.4, and since the folder/filename and config options have changed a bit, I'm not sure what's causing my scripts to behave this way.
I have a script that's setup to execute from my cgi-bin directory which, among other things, generates an HTML file and after everything is complete, it uses "Location:whoami.html" to navigate to this page. The page is located within cgi-bin when it is created. However, instead of this page being served client-side, it creates an Internal Server Error message, and the log suggests that the page was interpreted as a script because it says:
(13)Permission denied: AH01241: exec of '/var/www/cgi-bin/whoami.html' failed
[client xxx.xx.xx.xx:xxxxx] End of script output before headers: whoami.html, referrer: http://xxx.xx.xx.xx
So why is it interpreting this page as a script, if in fact, that is what it's doing? The old server has the same directory configurations for the cgi-bin directory, but it serves the page as it's supposed to without error.
The issue was that the script that creates the file wasn't running because I forgot to add the www-data user to the /etc/sudoers file... easy fix that I really should have thought of before.

No permissions on htaccess file

I'm trying to setup a vagrant box with a lamp stack and was mostly successful. However, now I'm stuck with the error "Server unable to read .htaccess file". My setup is a Centos 7 server with Apache 2.4 and PHP 5.6.
Apparently, this seems to happen a lot as I saw many people ask that question, but here's the thing:
1) All my folders are with 777 permissions
2) AllowOverride all and Require all granted is set on all of my folders
3) Even went so far as to add apache user to root group just to see if it would change something
I basically did everything that was suggested in all of the posts I saw and still, apache can't read the .htaccess file.
In my logs, I see:
[Tue Sep 26 15:20:18.178541 2017] [core:crit] [pid 6491:tid 139938095892224] (13)Permission denied: [client 10.0.2.15:52176] AH00529: /var/www/html/Kalendho/public/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/var/www/html/Kalendho/public/' is executable
So I presume apache actually find the file, but for some reason, cannot open it even though it should be able to. So really, any help would be greatly appreciated as I'm currently at my whit's end here.
Thanks in advance
Okay, so apparently, it was an issue with selinux. Here's what I did:
Opened the file /etc/selinux/config and changed the following line:
SELINUX=enforcing
to
SELINUX=disabled
After that, I rebooted my machine and it got rid of the htaccess error.

Can't run any file named install.php on localhost due to apache's access_compat

I'm getting a weird problem here.
I have at least 30 localhost WordPress installs made before and every one of them went fine.
Now (after re-installing Win7 and XAMPP) I can't access ANY install.php file (whether it's WPs own, a dummy empty one, etc). Also, it doesn't matter where it's located (wp-admin folder, a random place outside WP, htdocs root folder, etc).
This is not an antivirus or Windows firewall problem.
It seems to be coming from apache itself.
The apache error log says this
[Fri Nov 30 16:46:40.223524 2012] [access_compat:error] [pid 5876:tid 1604] [client ::1:59365] AH01797: client denied by server configuration: D:/xampp/htdocs/vmf05/wp-admin/install.php
Does anyone have a clue on this?
I've went through all the normal steps and haven't found a solution yet.
Also, if I disable the access_compat module, apache won't start.
Thanks in advance for your help.
I can't believe what the problem was!
I moved a .htaccess file that had the WP better security directives to the root of xampp's site as a backup, and forgot to move it back after.
No install.php file ANYWHERE could be accessed since it had the following:
<files install.php>
Order allow,deny
Deny from all
</files>
And, since the file was on the root, it was affecting the whole server.

What can I fix to avoid this error in apache error log: "File does not exist: /www/site/[object Object]:,"?

I have many errors in my apache error log like this:
[Mon Mar 26 08:12:52 2012] [error] [client 92.xx.xxx.xxx] File does not exist: /www/site/[object Object]:, referer: http://site.com/
I can't figure out, what makes this error.
How can i fix this?
My Apache version is 2.2.9
Check to see if the files referenced in your logs are files that you think exist or should exist on your site. If the files are files that you think should be on your site, then you might have some incorrect links in some of you pages. You can use a web crawler to check this.
If the pages referred to in the messages are things like ".../cmd.exe" or other pages that are not and never were on your site, then these log entries probably represent probes from bots looking for known exploits in some versions of some web servers. There is not much you can do about this. Welcome to the Internet.
If the client address for many of the requests is the same over a period of an hour or more, you are best advised to block that particular IP address at your external firewall.

Apache error log - file does not exist

I am receiving some mysterious errors in my apache error log.
For example:
File does not exist: /home/httpd/vhosts/studentlife.co.il/httpdocs/help_center/div.hot-jobs
File does not exist: /home/httpd/vhosts/studentlife.co.il/httpdocs/solutions/function.filesize
File does not exist: /home/httpd/vhosts/studentlife.co.il/httpdocs/work_abroad/div.publish
Now I don't understand - how did my divs and functions suddenly turn into files?? Of course they do not exist, they are divs and functions written in the code. So I am not sure why I am getting these file does not exist errors.
Also, how can I debug this, since in no place am I trying to access files with these names?
Any insight will be great.
I would say don't worry about it.
I can make a request for /the/answer/to/life/the/universe/and/everything.42 and it would show up in your error log.
Probably some spider is hunting for vulnerabilities in your site and it's randomly trying URLs. If you see the same pages a lot then start checking to see whether you have any broken links, otherwise forget about it.
You could use FireBug to see the return codes (you are looking for 404) of all HTTP requests made when you open your website. Maybe you have some typo in your HTML.
I had this same issue in this scenario:
wamp installation
system was running perfectly til dec 01/2010.
restarted computer on dec 02/2010.
apache wouldn't start up and was logging [Thu Dec 02 09:15:45 2010] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/announce
then, only then, I reminded myself I had just installed SKYPE on dec 01/2010 and that, on windows, we've got this conflict between the phone program and apache fighting for the port 80, I guess.
closed Skype, restarted services and voi là: my system is back. =)
One of my clients had a similar issue with Apache on Windows.
On any request he was getting:
[error] [client 192.168.1.66] File does not exist: D:/apache
I realized that the DocumentRoot was missing form the httpd.conf.
I agree with Gareth, a spider could be hunting for vulnerabilities in your site and it's randomly trying URLs. However, there may be another reason, probably more likely.
After debugging my own scripts to see what was going on, I noticed the following. The error of the form:
[Mon May 06 21:47:29 2013] [error] [client ip] File does not exist: /path/, referer: http://domain/example.html
is visible in the error log and even though it will sound weird, it does not have to do with the static HTML file or script that generates the page. In fact, the source of this problem may be the HTML of the page referencing a broken link to an image/css/js file, so that when the browser receives the HTML and fetches these resources Apache can't find them and prints the "File Does Not Exist" error.
It is nice of Apache as it warns us about broken links.