Cgi not working

apps

#1

I am having a little issue.
I have installed a 3rd party application called advanced stock tracker http://advancedstocktracker.org

I believe I have everything set up correctly but I get a error 500 - The server encountered an internal error or misconfiguration and was unable to complete your request.

after the install, I learnt (via these forums - thanks people) that I had to rename the cgi which was called ‘ast’ to ‘ast.cgi’ and that I had to set the permissions to 6755.

any ideas where to go from here?


#2

If that is the problem, you can use unix command.

To rename ast to ast.cgi, type mv ast ast.cgi (mv oldfilename newfilename). Please make sure you are in the right folder.

To set the permission to 6755, type chmod 6755 ast.cgi (chmod permission filename) after you have renamed the file.

More info, you can refer
http://wiki.dreamhost.com/UNIX_commands
http://wiki.dreamhost.com/Unix_File_Permissions

Save $97 (MAX Discount) with code: [color=#CC0000]97YES[/color] Sign Up NOW or More Codes Here


#3

Many thanks, but that is what I had already done…

I still have an Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.


#4

If the directory in which the program is placed, and the program itself, have their permission set to 755, the most common causes of "500 Internal Server Error"s are:

  1. The shebang! line of the perl program is incorrect (does not properly locate perl)

  2. The source code file was not uploaded in ASCII mode and/or the file does not have *nix style line endings.

That’s not to say that either of these are the problem in your particular instance, only that these are most commonly the problems. :wink:

Have you checked your error logs to determine if there is more information their to help identify the source of the error?

–rlparker


#5

Thanks… log shows premature end of script headers…

I will do some searching and investigate…


#6

That “premature end of script headers” does sound like a script formatting problem to me. Watch out for *nix style line-endings!

–rlparker


#7

I have checked the formatting and all files that are readable have *nix style line endings…

Still not working though…

any other thoughts on what could cause this?

Thanks


#8

Well, that was one of the “likely suspects”, but there are others.

What are the contents of your shebang! line?

What happens if you run the script from the command line?

–rlparker


#9

If I run the script from the command line I see a “Killed” response

I checked the shebang - and as it seems I had it wrong… Line 1 is now fixed and I now get another error (in the shell)…
can’t do setuid (cannot exec sperl)


#10

Well, that got me to actually go and look at the application you are trying to run. Did you successfully install all those dependencies?

Several of those are not installed on my DH server by default.

–rlparker


#11

I went with option 2 in the install instructions and copied the binary and satisfied the gnuplot dependency.

Managed to stumble my way through to where I am now…

At present for testing (and going back to basics) I have stopped trying to get the main file to work and will create a test file…

What I have tried in recent minutes… I have created a test.cgi file as per http://discussion.dreamhost.com/showthreaded.pl?Cat=0&Board=forum_programming&Number=78000&page=&view=&sb=&o=&vc=1#Post78000

  • I used nano at the shell to ensure line breaks were correct
  • chmod 6755 test.cgi
  • I web browsed to this test.cgi script and saw a 500 error as previous
  • logs showed same premature script headers message

if I run it from shell, I see the message “can’t do setuid (cannot exec sperl)”

For info, I will post the INSTALL content in the next message to give an indication of what is asked.


#12

AST Installation

  1. Automatic Installation

On most systems AST can be installed by running install.pl. You must
install gnuplot separately. install.pl will modify your crontab and apache
configuration.

  1. Manual Installation

If install.pl doesn’t work with your system (e.g. you are not running
apache, or on a host without shell access) then you probably want to do the
manual installation. The first thing you need to do is locate your web root.
Here is a list of common webroots:

DISTRIBUTION WEB ROOT
Gentoo Linux /var/www/localhost/htdocs
SUSE Linux 9, 10 /srv/www/htdocs
Ubuntu, Debian /var/www
Fedora, Red Hat /var/www/html

You can also use the cgi-bin in your home directory (~/public_html/cgi-bin).
If you are using a hosting provider, you will want to use your cgi-bin
directory.

Once you have determined your web root, copy all files from the AST tarball
into a directory in your webroot.

mkdir -p /var/www/localhost/htdocs/ast
cp -R * /var/www/localhost/htdocs/ast/

You need to make AST setuid some user, because it will be run by many different
users and the files need to be compatible with each other. Using your web
server user id is probably the best way to do it. If you are using apache,
you can find this in the configuration file, the settings User and Group. If
you are using your public_html directory this is already done for you.

cd /var/www/localhost/htdocs/ast
chown apache:apache ast
chmod 6755 ast

Finally you need to make your new directory able to execute CGI scripts. If
you are using apache, you should add this to your configuration file:

<Directory “/var/www/localhost/htdocs/ast”>
AllowOverride All
Options ExecCGI
SetHandler cgi-script
DirectoryIndex ast

To make these settings take effect, you must restart the web server:

/etc/init.d/apache2 restart

The last thing you need to do is load up the crontab file which will execute scheduled events:

crontab /var/www/localhost/htdocs/ast/share/example/crontab

Make sure to merge these files if you already have something in your crontab!


#13

First of all, if you cannot get that simple “Hello world!” script to run properly, there is no sense in proceeding, because something is fundamentally wrong.

Are you used to working with perl scripts? I’m only asking because I’m trying to figure out what might be the problem, and I don’t know where to start as I don’t know how you familiar you are with all this.

For that test script, it just doesn’t get any easier:

  1. Create that script in a nix editor and save it in a file named test.pl

  2. Place it in a web accessible directory that has permission set to 755.

  3. Set the script itself to 755 permissions

  4. Use a browser to visit http://yourdomain.com/dirwhereyouputthescript/test.pl

If that script doesn’t run when you do that, we have to stop all the rest of this and figure out why.

–rlparker


#14

Oops! Sorry, I replied to the wrong message in the thread; my last reply was to your preceeding message.

Moving onto this last message:

"You need to make AST setuid some user, because it will be run by many different
users and the files need to be compatible with each other. Using your web
server user id is probably the best way to do it. If you are using apache,
you can find this in the configuration file, the settings User and Group. If
you are using your public_html directory this is already done for you.

cd /var/www/localhost/htdocs/ast
chown apache:apache ast
chmod 6755 ast"

This is likely to be a problem for you on a DH shared server, as CGI runs under suexec on DreamHost; perl CGI scripts run as your own user and files that the script creates will also be owned by that user. I do not know of a workaround for this on DreamHost (I “get by” in perl and can install most things, but this is beyond my expertise).

Hopefully, a real perl wizard with a better grasp of how, or if, this can be done in the DreamHost environment will jump in!

–rlparker