Apache Doesn't Detect CGI Script - apache

I am running ubuntu with apache2. I have already edited my httpd.conf file to say...
ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/
I have also created a bash script and made it executable, and placed it within within the /usr/local/apache2/cgi-bin/ directory. However, when I send...
http://[domain]/cgi-bin/vlc-http.cgi?226625
I get a standard apache 404 URL not found error. I have no idea how to troubleshoot the situation, since I am new to apache and cgi.
Extra-Information: If I send an http request to /cgi-bin/ then apache tells me I don't have permission to access.

Related

How to suexec public_html/cgi-bin without the "~user/" in url

Apache 2.4.29 (Fedora)
Perl v5.26.1
I have a website which is run, for several reasons, out of the public_html directory of the user "jaf". Apache is set up to run cgi scripts in this directory tree as the local user ("jaf"). So, for instance "http://billyard.ca/~jaf/cgi-bin/simpletest.cgi" successfully executes as user "jaf" (rather than the default "apache"). What I am trying to achieve, unsuccessfully so far, is the following:
To get apache to run all cgi called by "http://billyard.ca/cgi-bin/" as if they were called by "http://billyard.ca/~jaf/cgi-bin/" (i.e., omit the "~jaf/") yet still operate within the "~jaf/public_html" directory as user "jaf" rather than "apache". I've added the following to the apache configuration:
<VirtualHost *:80>
Servername billyard.ca
SuexecUserGroup jaf jaf
DocumentRoot "/home/jaf/public_html"
ScriptAlias /cgi-bin/ /home/jaf/public_html/cgi-bin/
</VirtualHost>
This works "billyard.ca/~jaf/cgi-bin/simpletest.cgi".
This fails "billyard.ca/cgi-bin/simpletest.cgi"; it gives me a 500 internal server error and suexec reports "command not in docroot".
To get selinux to allow this (right now I have to go into permissive mode otherwise I get apache "premature end of header" error messages)

Apache won't autoindex

Oracle Linux 7.3 (RHEL derivative)
Apache 2.4.6
I'm setting up a repository in /srv/www for yum, scripts, and kickstart files, served via httpd. I want an auto-index, so I don't have any index.html. And, this is the only thing this internal server will do. So, httpd.conf:
DocumentRoot "/srv/www"
<Directory "/srv/www">
AllowOverride all
Options Indexes FollowSymLinks
Require all granted
</Directory>
However, I still get the error message:
[autoindex:error] [pid 12345] [client <IP address>:<port>] AH01276: Cannot serve directory /srv/www: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive.
Except that the Options directive allows auto-indexing! I've tried Options All. I've tried Options +Indexes +FollowSymLinks. I've looked at 7 or 8 Google hits. Nothing is working.
Setting LogLevel debug doesn't increase messaging.
What have I missed?
As noted here, in the absence of an index.html (or other configured index file), the welcome page configured at /etc/httpd/conf.d/welcome.conf will take precedence over other configurations via its LocationMatch directive. Rename the file so it doesn't end in .conf and auto-indexing works.
Obviously landing in another virtualhost or Directory without indexes enabled, or a .htaccess getting in the way.
Set "AllowOverride none" first, since it is absurd to have it active if you are not using any .htaccess file (and since you have access to the main server you don't need it). Once you set AllowOverride, restart the server in case you added Indexes recently and didn't restart to apply changes.
If the issue persists, run apachectl -S and make sure you are landing in the correct virtualhost.
I just want to add that, after updating my mac to Catalina, my apache stopped working with that same error.
I had to:
uncomment the required modules (php7, rewrite, directory, etc...)
add a + sign to the Options (Options +FollowSymLinks +Multiviews +Indexes)
This worked for me.
Solution:
Ensure two apache modules are running:
mod_autoindex.so
mod_dir.so
In your case, mod_autoindex.so is running. Now enable the second one.
PS: Keep Options -Indexes. It's important. It makes sure that directory listings are disabled, as you shouldn't allow anyone to pay a visit to every directory on your server (some with rather private content such as CMS's directories).

Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages

I am sure this is a question which has been asked somewhere, if so excuse me, but googling around did not give me anything tangible.
Here is my scenario:
I am protecting a web directory with apache http basic auth. So I have my .htaccess in the root folder and my httpd.conf is configure to override all so that it takes the .htaccess into consideration. The content of my .htaccess is as follows:
AuthType Basic
AuthName "test"
AuthUserFile /etc/httpd/.test_pass
Require valid-user
.test_pass has been set up with htpasswd successfully. When accessing the web root folder via the browser or any html file I get the authentication pop up correctly. Using the password gives me the expected access.
But when I access a php page, the authentication pop up does not appear and the php page renders.
Here is my set up:
Apache Version: 2.4.6
php-fpm: PHP 5.4.16 (fpm-fcgi) with Zend Engine v2.4.0
Using proxypass from proxy_fcgi_module (shared) for the communication
between apache 2.4 and php-fpm
Also I am not using socket connections because apache 2.4.6 does not
support it
My proxypass setting is as follows and works pretty well:
ProxyPassMatch ^/(..php(/.)?)$
fcgi://127.0.0.1:9000/var/www/html/$1
I need to be able to set a username/password authentication via apache basic auth which protects every files including php files in the directory.
I am using opensource softwares; therefore modifying the software codes is the very last resort.
Is there a work around/solution for php-fpm and mod_proxy_fcgi?
Thanks
After hours of research I understood that the reason that this occurs is because the ProxyPassMatch directive is the first directive to be processed, and this causes apache to ignore the other directives for the .php extensions.
To be able to use other apache directives with php-fpm via the proxy_fcgi_module one should rather use the filesmatch directive instead of proxypassmatch.
The syntax is as follows:
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>

apache ScriptAlias cgi-bin directory

this has been a problem for me for days and I haven't been able to solve it.
I'm working on fedora 14 and using Apache/2.2.17 (Unix)
the document root is /var/www and it is well configured in my httpd.conf
I have several folders inside /var/www that have perl files that require CGI to be run and instead, sometimes the perl file is offered as download and sometimes an error 500 appears
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, root#localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
the cgi_module is being loaded and even if I use ScriptAlias, and the directory tag, the file is still not being ran a script.
I even tried to create a virtual host and it doesnt work.
For instance, if I want a directory called "pyl" located inside the apache root (/var/www) what would the lines for httpd.conf be?
Indeed, check the error log (/var/log/apache2/error.log ?), check your file and dir permissions.
Also make sure your ScriptAlias directive is updated correctly.
So, have a look in your site config file (i.e. sites-available/default) and change this:
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
.. to this:
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin">
.. and reload apache2.
This solution applies to Apache2.4.51 version or may others. The directory structure can change with versions.
Make a change the default CGI config file below:
nano /etc/apache2/conf-available/serve-cgi-bin.conf
Change:
ScriptAlias /cgi/ /home/user/your-folder
<Directory "/home/user/your-folder">
Move your *.cgi, *.py, *.sh, etc files to your folder
Apply chmod 755 to your folder:
chmod 755 /your-folder
Restart apache2:
systemctl restart apache2
Sample pyhton code that you can run:
nano /home/user/your-folder/pythonapp.py
Code:
#!/usr/bin/python3
print("Content-type:text/html")
print()
print("""
<!doctype html>
<html><head></head><title>CGI-Python</title>
<body> Python App </body>
</html>
""")
Save and run your url:
server-ip-or-host/cgi/pythonapp.py

Apache Dynamic Virtual Hosts - 403 Forbidden

I am trying to configure the Apache server on my MacBooks (running Lion OS) to handle dynamic virtual hosts. I have managed to get it "working" but I whenever I access the domain I get a 403 Forbidden message. The hosts file is configured to point to 127.0.0.1 whenever one of these domains are requested. The httpd.conf is shown below:
VirtualDocumentRoot "/web"
<Directory "/web">
Options All
AllowOverride All
Order allow,deny
Allow from all
ScriptAlias /web/cgi-bin/
</Directory>
UseCanonicalName Off
VirtualDocumentRoot /web/%2/%1/public_html
This is set up so that http://foo.bar/ goes to "/web/bar/foo/public_html/".
I have checked the permissions on all the directories and files and they are all set to '777'. I have Googled for hours and hours and I am still getting 403 Forbidden. If there is anyone that can help me that would be greatly appreciated.
-Sam
You got it right, it's about permission. Check your site's parent folder permission, it might be stuck somehow on one of it's parent folder, make sure all of you site's parent folder from the root are readable by apache.