These scripts worked fine prior to upgrading to Monterey!
I have followed the tutorial from “etresoft” regarding editing the httpd.conf file and restarting Apache, but when executed the Perl script (code) displays in Safari. The scripts live in my Sites directory, and execute properly when run from there.
There are a suite of cgi/perl scripts that function to manage and present a family budget.
The first script opens a data file that contains various accounts: expenses (like groceries, utilities, etc.) and incomes. The script presents an HTML file with a large table, each line in the table documents an account, how much is due, and when. The script allows you to edit the various values. From this table page it is possible to call another script which will present those accounts due for the month and calculate the total amounts owed and the total incomes and the difference.
These are the edits made to /etc/apache2/httpd.conf:
Enabled the php and perl:
LoadModule php_modul/usr/local/opt/php#8.0/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
LoadModule perl_module libexec/apache2/mod_perl.so
Uncommented the LoadModule for userdir_module:
LoadModule userdir_module libexec/apache2/mod_userdir.so
Uncommented the Include line for httpd-userdir.conf:
User home directories
Include /private/etc/apache2/extra/httpd-userdir.conf
Saved the httpd.conf file.
This is the edit made to /etc/apache2/extra/httpd-userdir.conf:
Uncommented the Include line for *.conf
Include /private/etc/apache2/users/*.conf
I edited /etc/apache2/users/<your short user name>.conf. It now looks like this:
<Directory "/Users/rjklaus/Sites/">
AddLanguage en .en
AddHandler perl-script .pl
Options Indexes MultiViews FollowSymLinks Includes ExecCGI
DirectoryIndex index.html index.cgi index.php
AllowOverride None
Require host localhost
</Directory>
From a “Terminal” window I ran the following command:
chmod +a "_www allow execute" ~
I ran apachectl configtest and received a “Syntax OK”.
I next entered http://localhost/ into the Safari address bar. I did NOT see the “It works!” that I was told to expect. Instead I got:
/Users/rjklaus/Ray's%20Stuff/HTML%20Budget/test.pl
“HTML Budget” is a file (not a directory) in a subdirectory of “Ray’s Stuff”. The text string “test.pl” is not in that file. Test.pl is a short perl script in my Sites directory.
I am running perl v5.30.3 from /usr/bin/perl.
There are three versions of Apache2 located in /Users/Shared/ subdirectories labeled:
Previously Relocated Items,
Previously Relocated Items 1, and
Previously Relocated Items 2.
just to be sure, the cgi_module is enabled?
<IfModule !mpm_prefork_module>
LoadModule cgid_module lib/httpd/modules/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
LoadModule cgi_module lib/httpd/modules/mod_cgi.so
</IfModule>
I would like to run perl as CGI . i.e Want to run it in localhost rather than command prompt.
I have installed perl . I have kept my file at /var/www/cgi-bin/
and i have made following changes in /etc/apache2/apche2.conf
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory /var/www/cgi-bin/>
Options ExecCGI
AddHandler cgi-script cgi pl
</Directory>
Its giving me 404 not found error.
Following is the url I am accessing:
http://localhost/cgi-bin/testscript.pl
If your file is at /var/www/cgi-bin/, and your configuration says:
ScriptAlias /cgi-bin/ /home/www/cgi-bin/
Then I'd say that the problem is pretty obvious. /var/www/cgi-bin/ and /home/www/cgi-bin/ are not the same directory.
Update: Ok. So you say that you have fixed the value of ScriptAlias and it still didn't work. Assuming that you're still getting the 404 error, then the next obvious step is to look in your error log and see exactly which file Apache is looking for. There's probably a mismatch between how Apache is configures to map between URLs and files and how you think it is configured.
When you get that error message, add it to your question.
I'm struggling to get my server to recognize cgi-bin in a URL.
If I place my cgi script in any site's root folder, it works perfectly without including cgi-bin in the URL. So my server is processing cgi correctly. If I attempt to use any cgi-bin configuration, it results in a 404 error.
I'm running it on a Mac server with OS 10.10. Ideally I would like to locate the cgi script in /Library/WebServer/CGI-Executables and address it as cgi-bin: Some.com/cgi-bin/my.cgi?yaddayadda .
In pursuit of that, I've edited Apache's httpd.conf file. It was already set with that as the path but resulted in the 404. Currently httpd.conf is:
# "/Library/WebServer/CGI-Executables" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
ScriptAlias /cgi-bin/ /Library/WebServer/CGI-Executables/
<Directory "/Library/WebServer/CGI-Executables">
AllowOverride None
Options +ExecCGI
AddHandler cgi-script .cgi .wsgi
</Directory>
# To allow CGI program execution for any file ending in .cgi in
# users' directories, you can use the following configuration.
#ScriptAlias /cgi-bin/ /home/*
# <Directory /home/*>
# Options +ExecCGI
# AddHandler cgi-script .cgi
# </Directory>
# If you wish designate a cgi-bin subdirectory of a user's directory
# where everything will be treated as a CGI program, you can use the following.
# ScriptAlias /cgi-bin/ /home/cgi-bin/
# <Directory /home/cgi-bin>
# AllowOverride None
# Options +ExecCGI
# AddHandler cgi-script .cgi
# </Directory>
As this shows, I've tried using a cgi-bin folder within the site folders as well. I've also added the .wsgi handler and gotten the same results with a Python Hello World. It too works from the root folder of any site. I just can't get it to refer to what I want as the cgi-bin. Even if I nest a cgi-bin folder inside CGI-Executables. I always get "The requested URL /cgi-bin/my.cgi was not found on this server."
I do restart Apache after every edit and have rebooted the whole machine several times. Nothing changes.
Unless I'm doing something wrong in my edits above, it's almost as if Apache is ignoring the httpd.conf. I don't know how to confirm that the file is being read when Apache starts. There is no other httpd.conf file located anywhere that should matter and those typically bear names that suggest they're from the past: httpd.conf.pre-update and httpd.conf-previous.
My best guess is that I have some error in the path or aliased path. I have tried every variation on them that I can come up with. The full path to my desired cgi-bin is: Server HD2/Library/WebServer/CGI-Executables. Or a cgi-bin folder within a site's root folder would be: Server HD2/Library/WebServer/Documents/TheSite/cgi-bin
I've also checked for any .htaccess files that could be overriding my edits. None found.
Thanks in advance for any suggestions.
I want to set the AllowOverride all But I don't know how to do it. I have found the following code by searching the google and pasted it in .htaccess:
<Directory>
AllowOverride All
</Directory>
But after pasting it I started receiving "Internal Server Error"
Can anyone guide me where to put this code or how to do it?
In case you are on Ubuntu, edit the file /etc/apache2/apache2.conf (here we have an example of /var/www):
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
and change it to;
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
then,
sudo service apache2 restart
You may need to also do sudo a2enmod rewrite to enable module rewrite.
The main goal of AllowOverride is for the manager of main configuration files of apache (the one found in /etc/apache2/ mainly) to decide which part of the configuration may be dynamically altered on a per-path basis by applications.
If you are not the administrator of the server, you depend on the AllowOverride Level that theses admins allows for you. So that they can prevent you to alter some important security settings;
If you are the master apache configuration manager you should always use AllowOverride None and transfer all google_based example you find, based on .htaccess files to Directory sections on the main configuration files. As a .htaccess content for a .htaccess file in /my/path/to/a/directory is the same as a <Directory /my/path/to/a/directory> instruction, except that the .htaccess dynamic per-HTTP-request configuration alteration is something slowing down your web server. Always prefer a static configuration without .htaccess checks (and you will also avoid security attacks by .htaccess alterations).
By the way in your example you use <Directory> and this will always be wrong, Directory instructions are always containing a path, like <Directory /> or <Directory C:> or <Directory /my/path/to/a/directory>. And of course this cannot be put in a .htaccess as a .htaccess is like a Directory instruction but in a file present in this directory. Of course you cannot alter AllowOverride in a .htaccess as this instruction is managing the security level of .htaccess files.
Goto your_severpath/apache_ver/conf/
Open the file httpd.conf in Notepad.
Find this line:
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
Remove the hash symbol:
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Then goto <Directory />
and change to:
<Directory />
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Then restart your local server.
On Linux, in order to relax access to the document root, you should edit the following file:
/etc/httpd/conf/httpd.conf
And depending on what directory level you want to relax access to, you have to change the directive
AllowOverride None
to
AllowOverride All
So, assuming you want to allow access to files on the /var/www/html directory, you should change the following lines from:
<Directory "/var/www/html">
AllowOverride None
</Directory>
to
<Directory "/var/www/html">
AllowOverride All
</Directory>
If you are using Linux you may edit the code in the directory of
/etc/httpd/conf/httpd.conf
now, here find the code line kinda like
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
Change the AllowOveride None to AllowOveride All
Now now you can set any kind of rule in your .httacess file inside your directories
if any other operating system just try to find the file of httpd.conf and edit it.
As other users explained here about the usage of allowoveride directive, which is used to give permission to .htaccess usage. one thing I want to point out that never use allowoverride all if other users have access to write .htaccess instead use allowoveride as to permit certain modules.
Such as AllowOverride AuthConfig mod_rewrite Instead of
AllowOverride All
Because module like mod_mime can render your server side files as plain text.
enter code hereif you are using linux you have to edit the
`/etc/apache2/sites-available/000-default.conf`
under the Documentroot . add the following code
`<Directory /var/www/>
AllowOverride all
Require all granted
</Directory>`
then ,
`sudo service apache2 restart`
and you have to enable the apache mod rewrite
`sudo a2enmod rewrite`
I think you want to set it in your httpd.conf file instead of the .htaccess file.
I am not sure what OS you use, but this link for Ubuntu might give you some pointers on what to do.
https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles
I also meet this problem, and I found the solution as 2 step below:
1. In sites-enabled folder of apache2, you edit in Directory element by set "AllowOverride all" (should be "all" not "none")
2. In kohana project in www folder, rename "example.htaccess" to ".htaccess"
I did it on ubuntu. Hope that it will help you.
There are several answers but there a number of things wrong with this question and I would like to address these:
If you get an error (e.g. 500), look in the log files (if you have access to them). e.g. /var/log/apache2/ssl_error.log
e.g.
cat /var/log/apache2/ssl_error.log
[Tue Jun 01 19:05:34 2021] [alert] [pid 31154] config.c(2119):
[client *******] /var/www/mysite/public/tmp/.htaccess:
<Directory not allowed here [lid YLZo3quRlv2EKOAABVoFLwAAAIM]
Putting AllowOverrides in a .htaccess makes no sense and is not allowed. See Context. See also my explanation below. It should be defined in the Apache configuration (e.g. /etc/apache2)
Allowing everything is usually not the best idea. Be as restrictive as possible!
the Directory directive is missing a directory, should be e.g. <Directory /var/www/html/etc>
the Directory directive does not make sense in an .htaccess. The location of the .htaccess in a directory already has the effect of making the statements within apply to a specific directory
do not mix and match snippets that are intended to be put in the Apache configuration (e.g. in /etc/apache2/...) with statements that are intended to be put in .htaccess - though most of the time, they will be identical, there are some subtle differences
If you have the possibility to modify the Apache configuration directly, do not use .htaccess and deactivate it. (for performance reasons, among others. Also you can have all configuration in one place, put it in version control or manage it via a software configuration management tool, e.g. Puppet, Ansible, SaltStack)
Unless you really cannot access and modify the Apache configuration directly, you do not need .htaccess. This is a common misconception.
That you saw a 500 error proves my point. If you change configuration in the Apache configuration directly (and not in .htaccess), you will usually get an error message with an explanation and information about the error and the line number (e.g. when you do service apache2 reload or apachectl configtest) - which gives you the possibility to fix the error before applying this in production(!).
Also, look in the documentation. It is really quite good. For most directives, you can find where they apply (see "Context").
For example, for IfModule, you can see:
Context: server config, virtual host, directory, .htaccess
For, AllowOverrides it is:
Context: directory
Note the missing .htaccess in the Context!
Instead of googling for information which repeat the same mistakes over and over, look in the documentation!
Docs
AllowOverrides
https://www.danielmorell.com/guides/htaccess-seo/basics/dont-use-htaccess-unless-you-must
SuSE Linux Enterprise Server
Make sure you are editing the right file
https://www.suse.com/documentation/sles11/book_sle_admin/data/sec_apache2_configuration.html
httpd.conf
The main Apache server configuration file. Avoid changing this file. It primarily contains include statements and global settings. Overwrite global settings in the pertinent configuration files listed here. Change host-specific settings (such as document root) in your virtual host configuration.
In such case vhosts.d/*.conf must be edited
Plus those upvoted correct answers sometimes same error could be seen because of mismatched and different settings on SSL part of webserver configurations. (Obviously when not using .htaccess file).
I have installed CruiseControl.NET and VisualSVN Server on my development server. Rather than running CruiseControl.NET Web Dashboard off IIS, I would like to run it off the Apache that VisualSVN Sever installs. I stumbled onto this question on Stackoverflow, and it has helped a lot.
I have the following config in the http-custom.conf file in the "C:\Program Files\VisualSVN Server\conf" folder.
LoadModule aspdotnet_module bin/mod_aspdotnet.so
AddHandler asp.net asax ascx ashx asmx aspx axd config cs csproj licx rem resources resx soap vb vbproj vsdisco webinfo
<IfModule mod_aspdotnet.cpp>
AspNetMount /ccnet "C:/Program Files/CruiseControl.NET/webdashboard"
AliasMatch /ccnet/(.*\.aspx.*) "C:/Program Files/CruiseControl.NET/webdashboard/default.aspx"
Alias /ccnet/ "C:/Program Files/CruiseControl.NET/webdashboard/"
<Directory "C:/Program Files/CruiseControl.NET/webdashboard">
Options FollowSymlinks ExecCGI
# Order allow,deny
# Allow from all
DirectoryIndex default.aspx
</Directory>
AliasMatch /aspnet_client/system_web/(\d+)_(\d+)_(\d+)_(\d+)/(.*) "C:/Windows/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4"
<Directory "C:/Windows/Microsoft.NET/Framework/v*/ASP.NETClientFiles">
Options FollowSymlinks
# Order allow,deny
# Allow from all
</Directory>
</IfModule>
This works fine, except http://localhost/ccnet (notice the missing trailing slash) does not bring up the CruiseControl.NET dashboard, whereas http://localhost/ccnet/ does.
Also, I have had to comment out the Order and Allow directives in the two Directory sections. The VisualSVN Service fails to start if I uncomment any of those 4 commented out directives.
What's up with that?
VisualSVN Server.exe (which is really httpd.exe) reports version number as 2.2.13.0 and mod_aspdotnet.so reports version number as 2.2.0.2006.
It's a bad idea to use mod_aspdotnet since it is not supported for three years and have some critical bugs. Another bad thing that mod_aspdotnet compiled with different settings and could be incompatible with VisualSVN Server binaries.
I recommend you to run CruiseControl.NET on IIS and then reverse proxy requests from VisualSVN Server to IIS. All required modules is already available in VisualSVN Server distribution. Just add the following lines to your httpd-custom.conf (assuming that you running IIS on port 8080)
LoadModule proxy_module bin/mod_proxy.so
LoadModule proxy_http_module bin/mod_proxy_http.so
ProxyPass /ccnet http://localhost:8080/ccnet
ProxyPassReverse /ccnet http://localhost:8080/ccnet
1/ Make sure you use the latest mod. It's name is mod_aspdotnet-2.2.0.2006-setup-r2.msi
2/ Modify the AliasMatch line as follow
AliasMatch "^/(?i)aspnet_client/system_web/(\d+)_(\d+)_(\d+)_(\d+)/(.*)" \
"C:/Windows/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4"
3/ Add this line after Options FollowSymlinks ExecCGI in your webdashboard directory secction
AspNet files
4/ Add Win32DisableAcceptEx on line ... I remember one machine nedded it .. but it was only on Xp installs, not Server2003 or other edition.