LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-18-2010, 05:50 PM   #1
rahmad
Member
 
Registered: Aug 2007
Location: Jordan
Distribution: RHEL, Centos, Debian
Posts: 65

Rep: Reputation: 15
execute CGI on Apache document root


hi

how can I run CGI scripts that are without extensions under the documentroot??

i can not use ScriptAlias on the documentroot, and I applied the following but i didnt work as well. http://httpd.apache.org/docs/2.0/howto/cgi.html

i can run .pl scripts but i cant run any script without extension :S
ofcourse all files are executable on the fs....plz help
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 03-18-2010, 06:15 PM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
http://httpd.apache.org/docs/2.0/mis...e.html#content
 
Old 03-19-2010, 06:38 AM   #3
rahmad
Member
 
Registered: Aug 2007
Location: Jordan
Distribution: RHEL, Centos, Debian
Posts: 65

Original Poster
Rep: Reputation: 15
i went through the link you sent, but can you give me more hint?
 
Old 03-19-2010, 07:28 AM   #4
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
rewrite the visible links to point at your scripts.

eg
http://www.yoursite.com/hello actually points at http://www.yoursite.com/hello.pl

Edit

An example .htaccess file to allow execution of perldiver.pl in the main www root directory, and to be accessed by just http://www.site.com/perldiver

Code:
Options +ExecCGI
AddHandler cgi-script cgi pl
RewriteEngine  on
RewriteBase    /
RewriteRule    ^perldiver$  perldiver.pl
You can give it any name you want :
http://www.site.com/fred
Code:
Options +ExecCGI
AddHandler cgi-script cgi pl
RewriteEngine  on
RewriteBase    /
RewriteRule    ^fred$  perldiver.pl

Last edited by smoker; 03-19-2010 at 01:21 PM.
 
Old 03-20-2010, 01:44 AM   #5
rahmad
Member
 
Registered: Aug 2007
Location: Jordan
Distribution: RHEL, Centos, Debian
Posts: 65

Original Poster
Rep: Reputation: 15
Thanks Smoker.

Ok now I need to rename all scripts to *.pl.

but now my question is, is there any way to execute scripts that are without extensions under the docmentroot and without using ScriptAlias??
 
Old 03-20-2010, 04:40 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
ut now my question is, is there any way to execute scripts that are without extensions under the docmentroot and without using ScriptAlias??
You can use:
Code:
RewriteEngine on

RewriteCond %{REQUEST_URI} !\.[html|php]
RewriteCond %{REQUEST_URI} !^/$
RewriteRule (.*) - [H=cgi-script]
Os course in the 1st RewriteCond line you have to add any file extensions that you don't want to be treated as scripts.

Regards

Last edited by bathory; 03-20-2010 at 05:33 AM.
 
Old 03-20-2010, 09:46 AM   #7
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
And how does that not match directories ?
 
Old 03-20-2010, 11:59 AM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi smoker,

I was showing OP how to use rewrite rules to run scripts without extensions from docroot.
If someone wants really to do this, he must also take care of any kind of files that might be called from a web page (like png, jpg, css, etc) and of course of subdirectories. A more complete example should be:
Code:
RewriteEngine on

RewriteCond %{REQUEST_URI} !\.[html|htm|php|png|jpg|gif|js|css]
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule (.*) - [H=cgi-script]
Regards
 
2 members found this post helpful.
Old 03-20-2010, 04:14 PM   #9
rahmad
Member
 
Registered: Aug 2007
Location: Jordan
Distribution: RHEL, Centos, Debian
Posts: 65

Original Poster
Rep: Reputation: 15
bathory thank you very much

It is working now
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
AD user login to Nagios - unable to execute CGI scripts in apache dbmacartney Linux - Server 1 10-07-2009 03:33 PM
Apache 2.2: Execute CGI script from user directory jf.argentino Linux - Server 6 05-14-2008 03:21 AM
changing permissions of document root and cgi-bin abtimoteo Ubuntu 2 08-13-2005 09:36 AM
Failed to execute cgi script in Apache!! baby_linu Linux - Newbie 4 06-30-2004 04:23 PM
Apache Config for users to execute CGI scripts CragStar Linux - General 9 01-20-2003 12:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:42 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
Open Source Consulting | Domain Registration