openshift: enable execution of cgi scripts - cgi

I have configured .htaccess file under $OPENSHIFT_DATA_DIR/cgi-bin to enable execution of cgi scripts.
AddHandler perl-script .pl
AddHandler cgi-script .cgi
Options +ExecCGI
But when I open the cgi script on browser, it just shows the script.
The server is not enabled to execute cgi scripts.
PS: My cgi script has execute permissions. I have restarted my openshift application as well.

Related

Apache: /cgi-bin/my.cgi was not found on this server

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.

Store Perl CGI Scripts in any directory

Is it possible to store perl scripts in any location like out side of the cgi-bin.
I would like to store them in my www folder instead or any folder under the www folder for viewing via browser e.g. (domain.com/index.pl) and not just limited to (domain.com/cgi-bin/index.pl)
You can store them in any directory you have configured Apache to execute CGI scripts in.
Options +ExecCGI
AddHandler cgi-script .cgi .pl
You can also use features such as mod_rewrite or alias to map a URL on to something in the cgi-bin

How to execute .pl script even if my browser trying to download it?

I've got simple script. I already test it in commandline. Everything is fine.
But my browser cannot execute it. It's always trying to download it. I've cheked all apache configuration file,but i can't find any troubles.
/etc/apache2/sites-available looks like this:
ScriptAlias /cgi-bin/ /var/www/president/cgi
<Directory "/cgi-bin/ /var/www/president/cgi">
AddHandler cgi-script cgi pl
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
script is very simple
#!/usr/bin/perl -w
use CGI;
print "Content-type: text/html\n\n";
foreach (sort keys %ENV) {
print "<i>$_</i>: $ENV{$_}<br/>\n";
}
You should:
check the path to the perl
check the shebang, e.g. #!/path/perl
chmod 755 /var/www/president/cgi/myscriptname.pl, and
check your error_log! ;)
but probably the problem is
AddHandler cgi-script cgi pl
this should be
AddHandler cgi-script .cgi .pl
^ ^ dots here
You also has a wrong <directory... specs..
The section:
<Directory "/var/www/president/cgi">
AddHandler cgi-script .cgi .pl
And/or check the line such:
LoadModule cgi_module lib/apache2/modules/mod_cgi.so
Ps: Unrelated, but still a good advice, please read something about the Plack & PSGI. Could speed up your perl-web-app development many-many-many (really MANY) times. (you can live without such problems) :)

run perl scripts as different user without mod_perl

I'm using web-console in my project. It's a console in the browser where I can type some commands and it runs them in the server with user www-data.
The installation instructions say
If your web server configured to execute Perl scripts under specific
user account, please make sure that this user has write permissions
for recently created directory.
is it possible to run perl scripts in the server with a user different than www-data? I can't see it in the apache docs. I'm using apache 2 with this configuration (without mod_perl):
AddHandler cgi-script .cgi .pl
<Directory /var/www/myproject/public_html/webconsole>
Options Indexes FollowSymLinks MultiViews +ExecCGI
AllowOverride None
Order allow,deny
allow from all
</Directory>
Would this be of any help: "The suEXEC feature provides Apache users the ability to run CGI and SSI programs under user IDs different from the user ID of the calling web server. Normally, when a CGI or SSI program executes, it runs as the same user who is running the web server."
Source: https://httpd.apache.org/docs/2.2/suexec.html

How to run cgi script on apache server

This is my program:
[root#localhost cgi-bin]# locate first.pl
/home/Ram/Desktop/work/first.pl
/usr/local/apache2/cgi-bin/first.pl
[root#localhost cgi-bin]# cd /usr/local/apache2/cgi-bin/
[root#localhost cgi-bin]# vi first.pl
#!/usr/bin/perl -w
use warnings;
use warnings;
use CGI;
print "content-type: text/html\n\n";
print "<h2>Hello, World!</h2>\n";
I am calling the script from my browser like this:
http://localhost/usr/local/apache2/cgi-bin/first.pl
I didn't get output, but I'm getting an error:
Not Found
The requested URL /usr/local/apache2/cgi-bin/first.pl was not found on this server.
Apache/2.2.15 (CentOS) Server at localhost Port 80
I checked in web browser whether the Apache web server is working or not by using :
https://localhost
It us showing the welcome page.
How do I resolve this error?
You basically need to change two files after installing apache2 on linux.
Go to terminal and set the following configs:
sudo vim /etc/apache2/sites-enabled/000-default.conf and add the follwing:
<Files ~ "\.(pl|cgi)$">
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
Options +ExecCGI
PerlSendHeader On
</Files>
sudo vim /etc/apache2/apache2.conf and add the following:
<Directory /var/www/cgi-bin/>
AddHandler cgi-script .cgi .pl
Options FollowSymLinks ExecCGI
AllowOverride None
</Directory>
After adding these two config changes, write a perl script, place it in the cgi-bin directory, and then give it sufficient privileges (sudo chmod 755 <filename>)
Finally, restart apache2: sudo apache2ctl restart
Screenshots:
Yes, the above process works but the easy way is:
Enable the CGI- sudo a2enmod cgi
Restart the Apache and it works -service apache2 restart
Run the cgi file http://localhost/cgi-bin/1.sh
Best Of Luck !!
In your web configuration (httpd.conf or your virtual host configuration file) you should have the following fragment:
ScriptAlias /cgi-bin/ /etc/local/apache2/cgi-bin/
<Directory "/etc/local/apache2/cgi-bin">
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
</Directory>
restart the server, don't forget to chmod +x /usr/local/apache2/cgi-bin/first.pl and then load http://localhost/cgi-bin/first.pl
This assumes that either there are no virtual hosts in your config, or that the virtual host you configured is the default one. See the apache docs if needed.