httpd.conf and Location Match error - apache

This is how part of my httpd.conf file looks
(apache 2.215, mod_perl 2.0000005-orsomething, newest HTML::Mason)
# user's Mason Handler Thingy Handler
SetEnv PERL5 /home/user/perl5/lib
PerlSwitches -I/home/user/perl5/lib
PerlModule HTML::Mason::ApacheHandler
<Directory /var/www/html/user>
<LocationMatch "\.html$">
SetHandler modperl
PerlResponseHandler HTML::Mason::ApacheHandler
</LocationMatch>
</Directory>
# end user's Mason Handler Thingy Handler
The error I get on restarting apache back up is:
[root#server folder]# /etc/init.d/httpd start
Starting httpd: Syntax error on line 1020 of /etc/httpd/conf/httpd.conf:
<LocationMatch not allowed here
[FAILED]
[root#server folder]#
Line 1020 is the location match tag
I don't exactly know what's wrong with this configuration, I can't get apache to restart back up.

The error is telling you that you can't nest LocationMatch in Directory. You probably want FilesMatch.

Related

.htaccess cgi perl - Invalid command 'Deny', perhaps misspelled or defined by a module not included in the server configuration

i'm trying to set up this: https://github.com/oprel/emanon
But everytime i try to run post.cgi i receive this error on the error log:
[Sat Jul 02 13:03:13.380647 2022]
/fs5d/9kun/public/board/.htaccess: Invalid command 'Deny', perhaps misspelled or
defined by a module not included in the server configuration
The 'Invalid command' is from .htaccess:
<FilesMatch "\.(txt|pm)$">
deny from all
</FilesMatch>
Lines 3,4,5
What should i do?? I run apache with cgi.
I would expect you are on Apache 2.4
<FilesMatch "\.(txt|pm)$">
deny from all
</FilesMatch>
Deny is an Apache 2.2 (and earlier) directive and is formerly deprecated on Apache 2.4 and moved (from a base module) to mod_access_compat (an optional extension). This module is probably not enabled, hence the error.
You should be using the corresponding Require directive on Apache 2.4 instead. For example:
Require all denied
Reference:
https://httpd.apache.org/docs/2.4/mod/mod_authz_core.html#require
The problem is that you are not ordering the statement at all, therefore Apache has no idea whether you want to deny or allow it. Try this below...
<FilesMatch "\.(txt|pm)$">
Order Allow,Deny
Deny from all
</FilesMatch>

Why Apache configuration works when I use root directory

I have a VirtualHost that I am using to serve requests to files in /var/www/project/src.
I also have a Perl script (CGI binary) that is in /var/www/project/src/cgi-bin/index.pl.
Here's the part of the directive relevant to my question:
<VirtualHost example.com:443>
...
DocumentRoot "/var/www/project/src"
<Directory "/var/www/project/src">
Require all granted
Options +MultiViews +ExecCGI
AddHandler cgi-script .pl
DirectoryIndex /cgi-bin/index.pl
</Directory>
</VirtualHost>
The server starts, but access to the host fails as I get a 403 error.
The Apache logs indicate that the web server cannot find {document-root}/cgi-bin/index.pl:
[Thu Nov 09 11:37:03.578316 2017] [autoindex:error]
[pid 122783] [client example-client.com:57203] AH01276:
Cannot serve directory /var/www/project/src/: No matching
DirectoryIndex (/cgi-bin/index.pl) found, and server-
generated directory index forbidden by Options directive
This directory and index.pl file are in the right location, are owned by the apache user, and have permissions which allow others to read the contents of directories and execute the index.pl CGI-bin.
Moreover, if I change paths in DocumentRoot and Directory variables, the following configuration works:
<VirtualHost example.com:443>
...
DocumentRoot "/"
<Directory "/">
Require all granted
Options +MultiViews +ExecCGI
AddHandler cgi-script .pl
DirectoryIndex /var/www/project/src/cgi-bin/index.pl
</Directory>
</VirtualHost>
Apache starts up, and my access to the host in turn loads /cgi-bin/index.pl, which is rendered correctly.
Question: What would cause the first set of directives to fail, where the second set works?
More specifically: What is preventing the first set of directives from finding /cgi-bin/index.pl in the specified document root, while the second set correctly finds the fully-qualified path /var/www/project/src/cgi-bin/index.pl?
Note: The items in ... do not seem relevant to the issue — whether I remove them, alter them, or leave them, the error and log messages are the same in any case — so I am leaving them out for brevity.
Try changing permissions for /var/www, /var/www/project, /var/www/project/src and/or /var/www/project/src/cgi-bin
Update: Also, don't forget to restart Apache server after making changes.
What's happening is your excessive zeal an excess in your zeal... in the first example, DirectoryIndex /cgi-bin/index.pl points towards your ROOT directory, then searching for a folder caller cgi-bin. This also happens in the second example, but since you give the full path, Apache finds it. Try removing the / before cgi-bin and the issue should fix itself.

Why is WSGIScriptAlias not having an effect?

I'm running into an issue with setting a WSGIScriptAlias in Apache, where attempting to use the alias is giving a 404 error due to trying to reach the "literal" URL. Here's the test set-up in my Apache2 sites-available/000-default.conf (mimicking the mod_wsgi Quick Start Guide):
DocumentRoot /var/www/html
WSGIScriptAlias /wsgi_test /var/www/html/test.wsgi
<Directory /var/www/html>
Order allow,deny
Allow from all
</Directory>
After restarting Apache2 and going to mydomain.com/wsgi_test, a 404 page is displayed. The first line of Apache's error.log file below shows the server attempting to access the URL path wsgi_test in DocumentRoot, not the aliased file path:
AH00128: File does not exist: /var/www/html/wsgi_test
AH01964: Connection to child 1 established (server nathanclonts.com:443)
(70007)The timeout specified has expired: [client 67.161.148.188:33883] AH01991: SSL input filter read failed.
The file /var/www/html/test.wsgi has the same code as the above-mentioned Quick Start Guide:
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
With permissions set to:
-rwxrw-r-- 1 username www-data 278 Apr 16 11:31 test.wsgi
Does anyone have suggestions on where to look for other configuration that may be affecting this, or any other debugging tips?
What's odd is that I have set up another (Django) application with mod_wsgi that is currently working in the same VirtualHost, but obviously I'm missing something in this test.
This was resolved by updating the <VirtualHost *:443> configuration file to include the WSGIScriptAlias line (as the server uses SSL), instead of having WSGIScriptAlias under the <VirtualHost *> configuration.
I wasn't aware that all Aliases needed to be included in the 443 port to function, but eventually worked it out after playing with a vanilla Alias and locating which files they were defined in with:
grep -R "Alias" /etc/apache2/*

trying to enable mod_status but I get "Syntax error..."

I am trying to enable mod_status on my server. I have mod_status.so module installed and the relevant part of my .conf file is (I plan to restrict access to only my IP once I get it running):
LoadModule status_module modules/mod_status.so
<Location /server-status>
SetHandler server-status
Order Allow,Deny
Allow from all
</Location>
I restart apache and get an error: "Syntax error on line 4 of /path/to/httpd.conf"...which points to the line:
Order Allow,Deny
I've tried all combinations of lowercase, uppercase and a space between the comma and "Deny". What am I doing wrong?
I am using Apache 2.2.25 (and I do have 2 virtualhosts)
Thanks!

Apache/xampp command line start error: AH00436: No installed service named "Apache2.4"

I installed Apache server on Windows 7 Pro with Xampp distribution. Apache starts fine from the XAMPP Control Panel, but I want to be able to control it from a command prompt. When I try to start it from the command prompt, I am getting the following error:
C:\>httpd -k start
[Fri Jun 14 13:21:59.055815 2013] [mpm_winnt:error] [pid 6344:tid 144] (OS 2)The system cannot find the file specified. : AH00436: No installed service named "Apache2.4".
I tried to change the Listen port in httpd.conf. It does not change anything. Any clues ?
Thanks.
I had absolutely the same problem with the "AH00436: No installed service named “Apache2.4”" after I downloaded Apache 2.4 for Windows and tried to start it the first time.
The solution was very very simple. You get the error message when you manually try to start the webserver by "httpd -k start", but no service was defined yet.
just do a "httpd -k install" and the windows service is added to the registry. after that, the "httpd -k start" works without error message.
I have just got a similar error message when running the same command, but in my case I had just installed wamp from http://www.wampserver.com/en/
C:\wampserver\bin\apache\apache2.4.9\bin>httpd -k start [Mon Sep 29
14:27:05.203039 2014] [mpm_winnt:error] [pid 10720:tid 424] (OS 2)The
system cannot find the file specified. : AH00436: No installed
service named "Apache2.4".
I found that when I used the "-n" switch in the command line
to include the name of the Apache web server service then it would work.
C:\wampserver\bin\apache\apache2.4.9\bin>httpd -n wampapache64 -k
start
So it seems to me that unless the name of the service is included using the
"-n" switch in the command line it is assumed that the name of the service
to start is "Apache2.4".
In my case I did not have a service called Apache2.4, so the command failed.
I do have a service called wampapache64 though, so when I specified that
service name in the command line it ran without error.
I resolved the problem by installing the apache service. For apache, when i went to Apache -> Service, i couldn't even start the service, because those lines were disabled... so i installed the service, the line below the horizontal rule line.
Apparently, my apache didn't have allowed access on my computer... (That's when a window popped-up after installing the service asking to "Allow access" for apache on the computer)
Hope this helps.
Update
I'm using wamp, not xampp.
Any action triggered by the option -k (they are called signals), needs the Apache service to exist in Windows services list.
Therefore, if you see this error message, there are only two possible causes:
Your Apache service does not exist
Then just create it with
httpd.exe -h install
Now you should be able to send the restart signal
httpd.exe -k restart
Your Apache service has a custom name
If the service exists, but has a custom name such as "My Awesome Apache Service", then you have to specify that name when you want to send it any signal.
So, if you have installed it with
httpd.exe -k install -n "My Awesome Apache Service"
you have to restart it with
httpd.exe -k restart -n "My Awesome Apache Service"
Here is the solution for your above Error:
Please change the ServerRoot and DocumentRoot directives in httpd.conf file from default path (c:\Apache24) to the zip installation path (current apache24 zip extraction path)
ServerRoot "D:\httpd-2.4.4-win32\Apache24"
DocumentRoot "D:\httpd-2.4.4-win32\Apache24\htdocs"
After that restart the server and try to open the default page
http://example.com:
Please let me know your status on this
Thanks,
Amarnath Polu & Bhaskar
I had the same problem and resolved it in two steps:
First of all, be sure that Apache 2.4 is installed as a service. You can do this by executing Xampp Control Panel as Administrator and clicking the icon in "service" column.
By default, Apache uses 2 ports: 80 and 443. You must be sure these ports are free. In my case, I had in use 443 port (SSL). You can change this by modifiying the Listen port in "conf/httpd.conf" (for standard port) and "conf/extra/httpd-ssl.conf" (for SSL port).
Good Luck!
Greetings.
If you have Skype installed, make sure it uses "alternate ports" as it will take up port 80. If you quit Skype and try to start Wamp, it might work. This was my issue when trying to manually start the httpd-service and getting this error.
The same problem happened to me. When I check using httpd.exe -e warn it showed the error.
Only one usage of each socket address (protocol/network address/port)
is normally permitted : AH00072: make_sock: could not bind to address
[::]:80
Only one usage of each socket address (protocol/network address/port)
is normally permitted : AH00072: make_sock: could not bind to address
0.0.0.0:80
So the error in my case was multiple Listen entries along with Listen 80 in httpd.config. I just comment #Listen 80 and restart the service and problem is solved.
If you don't have VMware ou Skype , follow those steps :
1) in Xampp control panel -> config -> Apache(httpd.conf)
Listen 80
ServerName localhost:80
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory "C:/xampp/htdocs">
...
Require all granted
</Directory>
<Files ".ht*">
Require all denied
</Files>
<Directory "C:/xampp/cgi-bin">
AllowOverride All
Options None
Require all granted
</Directory>
2) in Xampp control panel -> config -> Apache(httpd-ssl.conf)
Listen 443
<VirtualHost _default_:443>
ServerName localhost:443
3) in Xampp control panel -> config -> Apache(httpd-xampp.conf)
<Directory "C:/xampp/php">
AllowOverride None
Options None
**Require all denied**
<Files "php-cgi.exe">
**Require all granted**
</Files>
</Directory>
<IfModule alias_module>
Alias /licenses "C:/xampp/licenses/"
<Directory "C:/xampp/licenses">
Options +Indexes
<IfModule autoindex_color_module>
DirectoryIndexTextColor "#000000"
DirectoryIndexBGColor "#f8e8a0"
DirectoryIndexLinkColor "#bb3902"
DirectoryIndexVLinkColor "#bb3902"
DirectoryIndexALinkColor "#bb3902"
</IfModule>
**Require all granted**
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
AllowOverride AuthConfig
**Require all granted**
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
Alias /webalizer "C:/xampp/webalizer/"
<Directory "C:/xampp/webalizer">
<IfModule php7_module>
<Files "webalizer.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
**Require all granted**
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
</IfModule>
4) Find cmd.exe and right click to select run as administrator
5) Type cd C:\xampp\apache\bin (installation path for Xampp)
6) Type httpd -k install
7) Type httpd -k start
8) Start Apache
Solution was pretty straightforward, I had Apache for x86 and PHP for x64, when I reinstalled PHP for x86, this error vanished.
Don't mix Apache and PHP version for different platforms.
For this to work with XAMPP Apache needs to be run as a service.
Open XAMPP control panel (Make sure to "Run as administrator").
Stop Apache.
Click the red cross on the Service column of Apache (so that it becomes a green tick).
Start Apache.
Bonus:
When you do this Apache will start every time you start your PC. If you want to start it manually (as it was before), change Startup Type in service.msc (search bar -> Services) from Automatic to Manual.