Apache 2.4.1 configuration - apache

I am facing a unique issue. I have setup Apache 2.4.1 and below are my configuration:
ServerRoot "prakash_prasad/bin"
AddHandler cgi-script .py
ScriptAlias /~prakash_prasad/ "/x/home/prakash_prasad/public_html/"
ScriptAlias /test/ "/x/test/prakash_prasad/public_html/"
DocumentRoot "/mybox/prakash_prasad/bin/htdocs"
<Directory "/x/test/*/public_html/">
Options +ExecCGI
Options ExecCGI
Order allow,deny
Allow from all
Options All
SetHandler cgi-script
AddHandler cgi-script .py
AllowOverride None
Require all granted
AddHandler cgi-script .py
SetHandler cgi-script
AllowOverride None
Require all granted
Options ExecCGI
Order allow,deny
Allow from all
Options All
SetHandler cgi-script
AddHandler cgi-script .py
AllowOverride None
Require all granted
</Directory>
<Directory "/x/home/prakash_prasad/public_html/*">
Options +ExecCGI
Options ExecCGI
Order allow,deny
Allow from all
Options All
SetHandler cgi-script
AddHandler cgi-script .py
AllowOverride None
Require all granted
AddHandler cgi-script .py
SetHandler cgi-script
AllowOverride None
Require all granted
</Directory>
Now I have a sample 'first.py' program dumping "Hello World!" which works fine when I enter the below url in the browser
http://:ip/test/first.py
But when I try to load an HTML page:
http://:ip/test/index.html
I get below error in browser:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at you#example.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
while in LOGS I see:
[Thu May 17 23:07:10.664648 2012] [cgid:error] [pid 10386:tid 47977877412864] (13)Permission denied: AH01241: exec of '/x/test/prakash_prasad/public_html/index.html' failed
[Thu May 17 23:07:10.665034 2012] [cgid:error] [pid 9849:tid 1232931136] [client 10.239.40.209:54712] End of script output before headers: index.html
Please let me know what config I need to correct?
::UPDATES::
I narrowed to a point but not sure the issue could be that:
When I comment the cgid module solved the issue for me:
# LoadModule cgid_module modules/mod_cgid.so
My HTML page comes fine but not my Python script
While I uncomment it
LoadModule cgid_module modules/mod_cgid.so
My script works fine but HTML files give error.
Any idea what could the issue be?

With "Options +ExecCGI" directive webserver will treat all files under public_html as an executable. So you have to place your opython files into a separate directory
ScriptAlias /pyfiles/ /home/x/public_html/pyfiles/
Then put your htmls /home/x/public_html/

Try removing the duplicate directives in your configuration since these could be causing an issue i.e for the first Directory:
<Directory "/x/test/*/public_html/">
Options +ExecCGI
Options ExecCGI
Order allow,deny
Allow from all
Options All
SetHandler cgi-script
AddHandler cgi-script .py
AllowOverride None
Require all granted
</Directory>

Related

Why do I get an Access forbidden in Apache?

Why do I get this error on apache when I access a certain js file??? I tried changing the httpd-xampp.conf from Require local to Require local granted but still to no avail.
I have the right permission to the js file I can even edit it using notepad++.
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.14
here is inside the http-xampp.conf file.
#
# XAMPP settings
#
<IfModule env_module>
SetEnv MIBDIRS "C:/xampp/php/extras/mibs"
SetEnv MYSQL_HOME "\\xampp\\mysql\\bin"
SetEnv OPENSSL_CONF "C:/xampp/apache/bin/openssl.cnf"
SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php"
SetEnv PHPRC "\\xampp\\php"
SetEnv TMP "\\xampp\\tmp"
</IfModule>
#
# PHP-Module setup
#
LoadFile "C:/xampp/php/php5ts.dll"
LoadFile "C:/xampp/php/libpq.dll"
LoadModule php5_module "C:/xampp/php/php5apache2_4.dll"
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
#
# PHP-CGI setup
#
#<FilesMatch "\.php$">
# SetHandler application/x-httpd-php-cgi
#</FilesMatch>
#<IfModule actions_module>
# Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
#</IfModule>
<IfModule php5_module>
PHPINIDir "C:/xampp/php"
</IfModule>
<IfModule mime_module>
AddType text/html .php .phps
</IfModule>
ScriptAlias /php-cgi/ "C:/xampp/php/"
<Directory "C:/xampp/php">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
<Directory "C:/xampp/cgi-bin">
<FilesMatch "\.php$">
SetHandler cgi-script
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler None
</FilesMatch>
</Directory>
<Directory "C:/xampp/htdocs/xampp">
<IfModule php5_module>
<Files "status.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</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
</Directory>
Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
AllowOverride AuthConfig
Require all granted
</Directory>
Alias /webalizer "C:/xampp/webalizer/"
<Directory "C:/xampp/webalizer">
<IfModule php5_module>
<Files "webalizer.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
Require all granted
</Directory>
</IfModule>
#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Require local granted
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
In this section:
<Directory "C:/xampp/php">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
Change
Require all denied
to
Require all granted
Not the perfect solution imho, but should make your dev environment work.
UPDATE:
Change the enitre section to this:
<Directory "C:/xampp/php">
AllowOverride None
Order Allow,Deny
Allow from All
</Directory>
This is the default I use (from symfony.com).
I figured it out. There was just a typo in my code....
this causes the error..
<script src="/hris/admin/../template/assets/js/jquery-ui.custom.js </script>"></script>
doubled the </script> tag

Script on Perl doesn't work. Apache gave me 500 Internal Server Error

So. I check my script
perl -cw /var/www/cgi/env.pl
var/www/cgi/env.pl syntax OK
I double check it in commandline. It works and shows me my environment values.
My /etc/apache2/sites-available/mysite.com looks like this:
ServerAdmin webmaster#localhost
ServerName mysite.com
DocumentRoot /var/www
<Directory />
Options FollowSymLinks +ExecCGI
AllowOverride None
AddHandler cgi-script .cgi .pl
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /var/www/cgi/
<Directory "/var/www/cgi">
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
It should work, but i've got 500 error.
Apache log says:
[Fri Sep 19 09:29:04 2014] [error] [client 127.0.0.1] (2)No such file or directory: exec of '/var/www/cgi/env.pl' failed
[Fri Sep 19 09:29:04 2014] [error] [client 127.0.0.1] Premature end of script headers: env.pl
What should I do to make it work?
Is it possible that phpmyadmin influent to apache server like this. I do not use php except phpmyadmin for database. Maybe here is the problem?
Okay.
This is my mistake.
This script was written on Windows machine and I forget about this fact for a while.
So I tried to delete carriage return symbol.
Now my script works.
Solution is:
perl -pi -e 's/\r\n/\n/g /path/to/your/script'

Apache php httpd-xampp.conf alias not working

I have httpd-xampp.conf with
<IfModule alias_module>
...
Alias /examples "D:/xampp/htdocs/examples/"
<Directory "D:/xampp/htdocs/examples">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</IfModule>
an in examples folder i have index.html, but when i access http://localhost:8880/examples, i have error
This page was not found
You are not logged in.
Back Log in Issues
Is there any error of my config? other alias : phpmyadmin, security work well.
I change httpd-xampp.conf to
<IfModule alias_module>
...
#!!! Don't know why
#Alias /examples "D:/xampp/examples/" don't work
Alias /my-examples "D:/xampp/examples/"
<Directory "D:/xampp/examples">
AllowOverride AuthConfig
Require all granted
</Directory>
</IfModule>
#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info|my-examples))">
Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
and http://localhost:8880/my-examples work now

Running mod-wsgi code (.wsgi) with Apache2

I'm using mod_wsgi on apache2/Mac OS X by setting apache server as follows.
<Directory /Library/WebServer/Documents/wsgi/scripts>
Order allow,deny
Allow from all
</Directory>
<IfModule wsgi_module>
WSGIScriptAlias /test /Library/WebServer/Documents/wsgi/scripts/test.wsgi
</IfModule>
With this configuration, I could call test.wsgi with http://.../test
Now, I need to execute it by calling as follows.
http://.../wsgi/test.wsgi
I have the following code.
<Directory /Library/WebServer/Documents/wsgi/scripts>
Order allow,deny
Allow from all
AddHandler wsgi-script .wsgi
</Directory>
<IfModule wsgi_module>
WSGIScriptAlias /test /Library/WebServer/Documents/wsgi/scripts/test.wsgi
Alias /wsgi/ /Library/WebServer/Documents/wsgi/scripts/
</IfModule>
I thought about using Alias so that I could link wsgi script directory to /wsgi/, and I expect Addhandler can handle the wsgi file, but it doesn't work.
What's wrong with my apache2 setup?
SOLVED
<Directory /Library/WebServer/Documents/wsgi/scripts>
Options ExecCGI Indexes
AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi
Order allow,deny
Allow from all
</Directory>
Alias /wsgi/ /Library/WebServer/Documents/wsgi/scripts/
Don't use AddHandler with WSGIScriptAlias, you need to use AddHandler with Alias directive. You will need to set ExecCGI option as well for directory. See:
http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines

attempt to invoke directory as script?

is something wrong with my apache config ?
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin">
AllowOverride None
AddHandler cgi-script pl cgi
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
nothing is wrong with your httpd configs, you need to configure httpd to redirect to the directory index. it is literally trying to execute the directory "/etc/www/cgi-bin" as cgi.