TurnKey Linux Virtual Appliance Library

Turnkey LAMP and CGI

Hi,

I'm a newbie to Turnkey and have just set up LAMP as a virtual development environment for a website I support. Everything works great, except that the website uses cgi programs and I want to configure LAMP to run them. The cgi scripts are in directory /var/www/SITENAME/privat.  

Reading some other posts on the forum I changed the configuration for the default apache site to:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
 DocumentRoot /var/www/
 <Directory "/var/www/SITENAME/privat/">
  Options +ExecCGI
  AddHandler cgi-script .cgi
 </Directory>
LogLevel error
</VirtualHost>

But when running cgi script from the browser I get a 500 Internal Server Error and the apache logs says:

[error] [client IP] (2)No such file or directory: exec of '/var/www/SITENAME/privat/index.cgi' failed, referer: http://IP/SITENAME/
[Mon Feb 08 10:20:18 2010]
[error] [client IP] Premature end of script headers: index.cgi, referer: http://IP/SITENAME/

Any suggestions as to what I'm doing wrong would be appreciated.

Regards, /Johan

Bump!

Having this issue as well.  Why doesn't CGI work out of the box on LAMP?

Alon Swartz's picture

Sorry for the late reply

I've just tested cgi on LAMP and it works, but requires a minor tweak. I've updated the upcoming 11.0 release to include this tweak, as well as a test cgi script for reference.
 

Test CGI script

/var/www/cgi-bin/test.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n" ;
print <<EOF ;
<html>
<head><title>CGI Test</title></head>
<body>
<h1>Hello, world.</h1>
</body>
</html>
EOF
Don't forget to make the cgi script executable:
chmod +x /var/www/cgi-bin/test.cgi
 

Tell apache about cgi-bin

/etc/apache2/sites-available/default
NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/
</VirtualHost>

<VirtualHost *:443>
        SSLEngine on
        SSLCertificateFile /etc/ssl/certs/cert.pem
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/
</VirtualHost>

ScriptAlias /cgi-bin/ /var/www/cgi-bin/

<Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        Order allow,deny
        allow from all
</Directory>
Don't forget to restart apache after making the change:
/etc/init.d/apache2 restart
OR
service apache2 restart
 
As a side note, if you have a cgi script outside of the ScriptAlias that you want to be executable, you need to specify:
AddHandler cgi-script cgi
Options +ExecCGI
 
I hope the helps.

good, but...

Thanks to you for your detailed info. However, if this is the necessary procedure, why don't you provide a shell script to make everyone life easier.

Jeremy's picture

It should be included in current appliances

This thread is quite old. See Alon's comment above:

I've updated the upcoming 11.0 release to include this tweak, as well as a test cgi script for reference.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)