LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-14-2015, 09:50 AM   #1
_n00b
Member
 
Registered: Aug 2015
Posts: 35

Rep: Reputation: Disabled
Execute .sh files in webbrowser with apache2 as server


Hi, i just installed "apache2" on my Ubuntu 14.04 virtual machine.
I try to execute this simple .sh file from the browser.

Code:
#!/bin/bash
DATE="$(date)"
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Test</title></head><body>"
echo "Today is $DATE <br>"
I saved this file as "date.sh" under "/var/www/html/projekt/cgi-bin/date.sh" and changed it's permissions to 755 with chmod. In firefox i write this into the address bar:
Code:
localhost/projekt/cgi-bin/date.sh
But the window in the following screenshot opens, and the code is not executed.


It is a save/open file dialog. I already searched for a solution on google and found this:
Code:
sudo a2enmod cgi
service apache2 reload
I get "Module cgi already enabled".
And the problem still remains, even after restarting the browser.
Does anyone know how to solve this?

Last edited by _n00b; 09-14-2015 at 09:56 AM.
 
Old 09-14-2015, 01:30 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,291

Rep: Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697
Since this is not the default cgi-bin directory for apache in ubuntu, you need to add the following:
Code:
<Directory /var/www/html/projekt/cgi-bin>
Options +ExecCGI
AddHandler cgi-script .sh
</Directory>
 
1 members found this post helpful.
Old 09-15-2015, 02:18 AM   #3
_n00b
Member
 
Registered: Aug 2015
Posts: 35

Original Poster
Rep: Reputation: Disabled
Smile Solved

Quote:
Originally Posted by bathory View Post
Since this is not the default cgi-bin directory for apache in ubuntu, you need to add the following:
Code:
<Directory /var/www/html/projekt/cgi-bin>
Options +ExecCGI
AddHandler cgi-script .sh
</Directory>
Thank you for the hint! I added these lines to my /etc/apache2/apache2.conf file. After this i restartet my browser and apache2, now it finally works!! Thank you very much sir.

Last edited by _n00b; 09-15-2015 at 02:19 AM.
 
Old 09-15-2015, 10:02 AM   #4
_n00b
Member
 
Registered: Aug 2015
Posts: 35

Original Poster
Rep: Reputation: Disabled
Ok with .sh it works fine. But i just tried it with this simple perl script.
Code:
#! /usr/bin/perl
use CGI':standard';
print "<p>Hello World</p>";
exit(0);
But it tries to download it again.
Should i create an extra thread for this problem?
 
Old 09-15-2015, 05:15 PM   #5
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,291

Rep: Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697
Quote:
Originally Posted by _n00b View Post
Ok with .sh it works fine. But i just tried it with this simple perl script.
Code:
#! /usr/bin/perl
use CGI':standard';
print "<p>Hello World</p>";
exit(0);
But it tries to download it again.
Should i create an extra thread for this problem?
If the perl script has a .pl extension, you should add it in the AddHandler directive:
Code:
<Directory /var/www/html/projekt/cgi-bin>
Options +ExecCGI
AddHandler cgi-script .sh .pl
</Directory>
 
Old 09-16-2015, 09:42 AM   #6
_n00b
Member
 
Registered: Aug 2015
Posts: 35

Original Poster
Rep: Reputation: Disabled
I already tried this before exactly like you wrote, it still tries to download tho.
 
Old 09-16-2015, 11:30 AM   #7
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,291

Rep: Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697
Quote:
Originally Posted by _n00b View Post
I already tried this before exactly like you wrote, it still tries to download tho.
Are you sure it's mot your browser cache?
Clear the cache, or use another browser and try again
 
Old 09-18-2015, 02:36 AM   #8
_n00b
Member
 
Registered: Aug 2015
Posts: 35

Original Poster
Rep: Reputation: Disabled
Ah ok, but now i get internal server error. Do you know what a possible cause could be? I already did "chmod 755 test.pl". I tried to execute the script from the console, following output appeared: <p>Hello World</p>, so the script should work, right?
But why i get the internal server error then?

Edit

Solved, i had to add this line to my script:

So this is the working script:

Code:
#! /usr/bin/perl
use CGI':standard';
print "Content-type: text/html\n\n";
print "<p>Hello World</p>";
exit(0);

Last edited by _n00b; 09-18-2015 at 03:35 AM. Reason: Solved
 
Old 09-18-2015, 04:43 AM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,291

Rep: Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697Reputation: 1697
Quote:
Originally Posted by _n00b View Post
Ah ok, but now i get internal server error. Do you know what a possible cause could be? I already did "chmod 755 test.pl". I tried to execute the script from the console, following output appeared: <p>Hello World</p>, so the script should work, right?
But why i get the internal server error then?

Edit

Solved, i had to add this line to my script:

So this is the working script:
Edit

Solved, i had to add this line to my script:

So this is the working script:

Code:

#! /usr/bin/perl
use CGI':standard';
print "Content-type: text/html\n\n";
print "<p>Hello World</p>";
exit(0);


Code:
#! /usr/bin/perl
use CGI':standard';
print "Content-type: text/html\n\n";
print "<p>Hello World</p>";
exit(0);
Glad to see you've made it and thx for providing the solution.
You can mark the thread "SOLVED" using the "Thread Tools_ on top of the page

Regards
 
  


Reply

Tags
apache, cgi, html, php


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] files on apache2 server visible internally but not via external ip:port nobuntu Linux - Server 1 12-29-2012 03:44 PM
[SOLVED] How to execute .jar files in ubuntu linux server ankit.pandey3 Linux - Newbie 31 06-21-2011 02:57 AM
How to execute .jar files in ubuntu linux server ankit.pandey3 Linux - General 3 05-19-2011 03:51 AM
CGI doesn't execute under apache2 wichne Linux - Server 1 05-09-2008 08:38 PM
Apache2 cannot execute cgi files on a USB drive bhoult Linux - Software 2 07-11-2005 11:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration