Results 1 to 10 of 10

Thread: cgi scripts, common problems and their solutions

  1. #1
    Forum Administrator Power Poster Lyle@Spry's Avatar
    Join Date
    May 2005
    Posts
    455

    Default cgi scripts, common problems and their solutions

    Ever installed a cgi script only to see a "500 Internal Server Error" message when you first tried it out? Here are some tips for troubleshooting those annoying problems.

    • Permissions - Most often the script is not executable. Try chmod a+x filename
    • Ownership - Another common mistake is to upload/extract/write the script file as the wrong user. Make sure the file is owned by the user/group that owns the site. Try chown username: filename
    • Directory permissions - If the script is in a subdirectory of your cgi-bin, are the permissions/ownership of the containing directory correct? I've seen some apache configurations which will disallow execution of cgi scripts if the permissions are too loose (i.e. world writable) or too tight (apache daemon can't even read the file.) Try chmod 755 dirname
    • ScriptAlias - Is the script outside of your normal cgi-bin directory? If so, Apache must be configured to execute the script versus just serving the file as a downloadable. Check your httpd.conf or .htaccess file for ScriptAlias directives.
    • shebang line - Interpreted languages like Ruby, Python, and Perl have a line at the top of every script that looks like:
      Code:
      #!/usr/bin/ruby
      This is the path to the interpreter required to run this script. This path must point to the correct location, else the kernel will not know how to even run the script. Try which ruby to find the path that should be in this line and edit accordingly. The name comes from a contraction of the names of the first two characters. "#" = "Hash", "!" = "Bang". "Hash-Bang" "sh-bang"
    • error log - Check the Apache error log. Sometimes scripts will give a little more information about why they are failing here. Consult your httpd.conf file to find the location of the error_log.
    • command line - Try to run the cgi script from command line. It should output proper HTTP headers, at least one blank line, and then html. If not, it won't run properly for Apache either.


    If you know of or encounter any other cgi related problems, share the knowledge here!
    Last edited by Lyle@Spry; 12-20-2005 at 01:24 PM.

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2006
    Posts
    5

    Question .CGI extensions and external use?

    I've been going around in circles to get a script ending with the .cgi extension to be executed by the webserver.

    I've made combinations of various changes using information located here:
    http://httpd.apache.org/docs/1.3/misc/FAQ-F.html

    I've edited the /etc/httpd/conf/httpd.conf file and restarted apache.
    I've added an additional ScriptAlias directive to handle the directory outside of the cgi-bin directory.
    I've modified the virtual host httpd.include config file to use (\.pl$|\.cgi$) for the files directive if mod perl is in use.

    The only extension that I can get to work is of course the .pl extension but the problem is that I'm moving my site over from another host and these scripts are already in use as is, where is.

    If anyone could post the steps to making somescript.cgi execute in an outside directory (but within the web root of course) that'd be great.

    As an example, how would I get http://www.somedomain.com/forum/index.cgi to execute?

    I'm currently using the Plesk VPS 200 hosting option. My account ends on the 17 at the other host and this is the only thing keeping me from changing over. I'm hoping to avoid renewing at my old host.

  3. #3
    Forum Administrator Power Poster Lyle@Spry's Avatar
    Join Date
    May 2005
    Posts
    455

    Default AddHandler

    Quote Originally Posted by justdave
    I've edited the /etc/httpd/conf/httpd.conf file and restarted apache.
    Do be aware that Plesk will rewrite that file when you use the control panel to modify any other site. Best to put this sort of modification in the vhost.conf file for the site in question.
    Quote Originally Posted by justdave
    I've added an additional ScriptAlias directive to handle the directory outside of the cgi-bin directory.
    You don't need a ScriptAlias for this, just the AddHandler if it's inside the DocumentRoot still.
    Quote Originally Posted by justdave
    I've modified the virtual host httpd.include config file to use (\.pl$|\.cgi$) for the files directive if mod perl is in use.
    Are you really using mod_perl? Try removing the IfModule test and just having the AddHandler cgi-script .cgi line in your VirtualHost definition. Again, read the note at the top of the httpd.include file, there's a warning about modifying it. Use the file vhost.conf (in the same directory as the httpd.include for this domain) to insert this directive.

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2006
    Posts
    5

    Exclamation vhost.conf doesn't seem to work...

    Or at least the "AddHandler cgi-script .cgi" line has no affect in it.

    I then tried adding:

    <Directory /path/to/website/directory/with/script>
    Options ExecCGI
    </Directory>

    to the vhost.conf file but that didn't change things either.

    I wasn't using mod_perl but was trying everything at that point. lol

  5. #5
    Forum Administrator Power Poster Lyle@Spry's Avatar
    Join Date
    May 2005
    Posts
    455

    Default More info?

    Does this script work inside a regular cgi-bin directory? How about from command line? Could you PM me your servers information so I may take a closer look?

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2006
    Posts
    5

    Default Thanks.

    I'll PM you the info after this post. I just tried using the .pl extension to show that it works that way but I think the previous changes to my vhost.conf file have stopped it.

  7. #7
    Forum Administrator Power Poster Lyle@Spry's Avatar
    Join Date
    May 2005
    Posts
    455

    Default vhost.conf not working :(

    After adding:
    Code:
    <Directory /var/www/vhosts/example.com/httpdocs/directory/script/is/in>
    AddHandler cgi-script .cgi
    Options ExecCGI
    </Directory>
    to the /var/www/vhosts/example.com/conf/httpd.include and restarting apache, the script works with the .cgi extension.

    I'm still trying to figure out why the vhost.conf file is not being included into the configuration though. Strange that the httpd.include file has this to say but then doesn't work as advertised:
    Code:
    # ATTENTION!
    # DO NOT MODIFY THIS FILE OR ANY PART OF IT. THIS CAN RESULT IN IMPROPER PLESK
    # FUNCTIONING OR FAILURE, CAUSE DAMAGE AND LOSS OF DATA. IF YOU REQUIRE CUSTOM
    # MODIFICATIONS TO BE APPLIED TO THE CONFIGURATION, PLEASE, PERFORM THEM IN THE
    # FOLLOWING FILE(S):
    # /var/www/vhosts/example.com/conf/vhost.conf
    # /var/www/vhosts/example.com/subdomains/<subdomain-name>/conf/vhost.conf

  8. #8
    Junior Member Newbie
    Join Date
    Jan 2006
    Posts
    5

    Default Thanks!

    Yeah that is odd. No wonder that didn't get me anywhere the first time. lol

    Will the only time that _that_ domain's httpd.include file will be modified by plesk is when I edit that domain directly? Or are all virtual host files overwritten when plesk updates? I'll just have to remember to update the file manually if I make any changes via plesk.

    Thanks again! Now I can say goodbye to my old host. I had them for 5 years and they have been good but they didn't have a vps offering.

    ~Dave

  9. #9
    Former Employee Newbie
    Join Date
    Oct 2005
    Posts
    31

    Default

    Hi Dave,

    Regarding the updating of the include files, try the following command once logged into your server via SSH:

    [root@server /]# grep Include /etc/httpd/conf/httpd.include | sed 's/Include //' | xargs ls -l

    It looks like there are different file modification times on the files, which would lead my to believe that when you update a site in Plesk it doesn't update all of the files. If it did, the file modification times would be the same. This doesn't mean that all changes in Plesk will only affect one file, so I'd say to be safe, check on the file modification times to see if the include file for the domain in question was modified.

    Regards,
    Dustin

    Quote Originally Posted by justdave
    Yeah that is odd. No wonder that didn't get me anywhere the first time. lol

    Will the only time that _that_ domain's httpd.include file will be modified by plesk is when I edit that domain directly? Or are all virtual host files overwritten when plesk updates? I'll just have to remember to update the file manually if I make any changes via plesk.

    Thanks again! Now I can say goodbye to my old host. I had them for 5 years and they have been good but they didn't have a vps offering.

    ~Dave

  10. #10
    Junior Member Newbie
    Join Date
    Sep 2006
    Posts
    1

    Default plesk and .cgi solution

    The fix is actually simple (acquired a headache through trial and error):

    log on as root
    cd /etc/httpd/conf
    open in a text editor the httpd.conf , example: nano httpd.conf
    locate line that says #AddHandler cgi-script .cgi and uncomment by deleting #
    save, restart apache and viola! The cgi scripts in httpdocs work. Chmod permissins to 711 for an extra security and you are rolling! The modification is not reversed by plesk to some default as when you try to modify the vhost config files.

    Now, if you get script error message, it has nothing to do with config, but rather with you.
    Probably ya tembel uploaded your script in binary instead of ascii mode, or you have includes that are not there where they are 'possed to be.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •