Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Apache: CGI scripts not working
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
evilAngel
n00b
n00b


Joined: 21 Jul 2004
Posts: 53
Location: France

PostPosted: Mon Nov 15, 2010 7:02 pm    Post subject: Apache: CGI scripts not working Reply with quote

Hey all,

I emerged Apache2.
I would like to use a CGI script.

When I enter the URL in my browser, I get the source code.

I did not configure CGI anywhere in my config file.
I am sur there is probably somewhere something to change allow CGI; but I don't know where...

Code:
cat /etc/conf.d/apache2
# /etc/conf.d/apache2: config file for /etc/init.d/apache2

# When you install a module it is easy to activate or deactivate the modules
# and other features of apache using the APACHE2_OPTS line. Every module should
# install a configuration in /etc/apache2/modules.d. In that file will have an
# <IfDefine NNN> directive where NNN is the option to enable that module.
#
# Here are the options available in the default configuration:
#
#  AUTH_DIGEST  Enables mod_auth_digest
#  AUTHNZ_LDAP  Enables authentication through mod_ldap (available if USE=ldap)
#  CACHE        Enables mod_cache
#  DAV          Enables mod_dav
#  ERRORDOCS    Enables default error documents for many languages.
#  INFO         Enables mod_info, a useful module for debugging
#  LANGUAGE     Enables content-negotiation based on language and charset.
#  LDAP         Enables mod_ldap (available if USE=ldap)
#  MANUAL       Enables /manual/ to be the apache manual (available if USE=docs)
#  MEM_CACHE    Enables default configuration mod_mem_cache
#  PROXY        Enables mod_proxy
#  SSL          Enables SSL (available if USE=ssl)
#  SUEXEC       Enables running CGI scripts (in USERDIR) through suexec.
#  USERDIR      Enables /~username mapping to /home/username/public_html
#
#
# The following two options provide the default virtual host for the HTTP and
# HTTPS protocol. YOU NEED TO ENABLE AT LEAST ONE OF THEM, otherwise apache
# will not listen for incomming connections on the approriate port.
#
#  DEFAULT_VHOST      Enables name-based virtual hosts, with the default
#                     virtual host being in /var/www/localhost/htdocs
#  SSL_DEFAULT_VHOST  Enables default vhost for SSL (you should enable this
#                     when you enable SSL)
#
APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE"

# Extended options for advanced uses of Apache ONLY
# You don't need to edit these unless you are doing crazy Apache stuff
# As not having them set correctly, or feeding in an incorrect configuration
# via them will result in Apache failing to start
# YOU HAVE BEEN WARNED.

# PID file
#PIDFILE=/var/run/apache2.pid

# timeout for startup/shutdown checks
#TIMEOUT=10

# ServerRoot setting
#SERVERROOT=/usr/lib64/apache2

# Configuration file location
# - If this does NOT start with a '/', then it is treated relative to
# $SERVERROOT by Apache
#CONFIGFILE=/etc/apache2/httpd.conf

# Location to log startup errors to
# They are normally dumped to your terminal.
#STARTUPERRORLOG="/var/log/apache2/startuperror.log"

# A command that outputs a formatted text version of the HTML at the URL
# of the command line. Designed for lynx, however other programs may work.
#LYNX="lynx -dump"

# The URL to your server's mod_status status page.
# Required for status and fullstatus
#STATUSURL="http://localhost/server-status"

# Method to use when reloading the server
# Valid options are 'restart' and 'graceful'
# See http://httpd.apache.org/docs/2.2/stopping.html for information on
# what they do and how they differ.
#RELOAD_TYPE="graceful"




Any ideas ?

Thanks
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 7618
Location: almost Mile High in the USA

PostPosted: Mon Nov 15, 2010 9:21 pm    Post subject: Reply with quote

Looks like the devs pulled a fast one on us. Changed defaults on us... One day I pulled up my website and saw all my source code. EEEK.

Think the correct fix is adding "cgi" to my APACHE2_MODULES in /etc/make.conf and re-emerge apache.
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
evilAngel
n00b
n00b


Joined: 21 Jul 2004
Posts: 53
Location: France

PostPosted: Tue Nov 16, 2010 8:01 am    Post subject: Reply with quote

Here (https://forums.gentoo.org/viewtopic-t-836353-start-0.html) , the guy precise that
Quote:
Ok, the solution was to add cgid to APACHE2_MODULES in /etc/make.conf and re-emerge apache.


But isn't there a directive like ExecCGI to add somewhere in a configuration file?

THanks
Back to top
View user's profile Send private message
chiefbag
Guru
Guru


Joined: 01 Oct 2010
Posts: 542
Location: The Kingdom

PostPosted: Tue Nov 16, 2010 10:22 am    Post subject: Reply with quote

You need to add the below in /etc/conf.d/apache2 if its not already there after the re emerge with the cgi flag

APACHE2_OPTS="-D CGI"
Back to top
View user's profile Send private message
chiefbag
Guru
Guru


Joined: 01 Oct 2010
Posts: 542
Location: The Kingdom

PostPosted: Tue Nov 16, 2010 10:24 am    Post subject: Reply with quote

Also in for example your default_vhost.include

ScriptAlias /nagios/cgi-bin /usr/lib/nagios/cgi-bin
<Directory "/usr/lib/nagios/cgi-bin">
AllowOverride AuthConfig
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
Back to top
View user's profile Send private message
evilAngel
n00b
n00b


Joined: 21 Jul 2004
Posts: 53
Location: France

PostPosted: Mon Nov 22, 2010 12:23 pm    Post subject: Reply with quote

Thanks!

I will try this and comment back.
Back to top
View user's profile Send private message
evilAngel
n00b
n00b


Joined: 21 Jul 2004
Posts: 53
Location: France

PostPosted: Mon Nov 22, 2010 2:09 pm    Post subject: Reply with quote

Quote:
the re emerge with the cgi flag


It is this one:
Code:
apache2_modules_cgi
?

http://gentoo-portage.com/www-servers/apache/USE#ptabs


Thanks
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 7618
Location: almost Mile High in the USA

PostPosted: Mon Nov 22, 2010 9:32 pm    Post subject: Reply with quote

In /etc/make.conf, make sure there's "cgi" in the variable APACHE2_MODULES.

Code:
APACHE2_MODULES="cgi"


Need to re-emerge apache (with --newuse).

I think I forgot the other aspects of this issue as others pointed out. I ended up adding

Code:
LoadModule cgi_module modules/mod_cgi.so


into /etc/apache2/httpd.conf ... This makes sure the module gets loaded. Since I've been using an old httpd.conf, this may likely be obsoleted by adding -D CGI as if there's some <ifdefine CGI> in the new httpd.conf.

The third aspect as stated is the directory configuration. In the <Directory xxxx> clause the option for ExecCGI needs to be enabled.
I ended up allowing CGI to be enabled for my root web directory (for all vhosts), so in /etc/apache2/vhosts.d/default_vhost.include I have:

Code:
<Directory "/var/www/localhost/htdocs">
        Options Indexes FollowSymLinks ExecCGI Includes
        AddType text/html .shtml
        AddHandler server-parsed .shtml
        AddHandler server-parsed .html
        AddHandler cgi-script .cgi
        DirectoryIndex index.shtml index.cgi index.php index.html
        AllowOverride All
        Order allow,deny
        Allow from all
</Directory>

The "AllowOverride" is needed if you don't want to put ExecCGI here... (AllowOverride Options or All) If you want your home directory to allow CGI execution, you'll need to make sure CGI is allowed there too. /etc/apache2/modules.d/00_mod_userdir.conf needs to allow ExecCGI or allow it to be overridden.
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
evilAngel
n00b
n00b


Joined: 21 Jul 2004
Posts: 53
Location: France

PostPosted: Tue Nov 23, 2010 8:16 am    Post subject: Reply with quote

Quote:
This makes sure the module gets loaded. Since I've been using an old httpd.conf, this may likely be obsoleted by adding -D CGI as if there's some <ifdefine CGI> in the new httpd.conf.

I suppose, the file to put the
Code:
-D CGI
is
Code:
/etc/conf.d/apache2
?

Thanks
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 7618
Location: almost Mile High in the USA

PostPosted: Tue Nov 23, 2010 3:21 pm    Post subject: Reply with quote

Yes, in /etc/conf.d/apache2 you should see something like

Code:
APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE -D SSL -D SSL_DEFAULT_VHOST -D USERDIR -D SUEXEC -D BW -D PHP5 -D PROXY"


Since I have the LoadModule hard coded manyally in httpd.conf, I don't need it here. But if you have a newer httpd.conf that detects the CGI module, you should add -D CGI. I have no idea if the new httpd.conf does it but I suspect it should.
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
evilAngel
n00b
n00b


Joined: 21 Jul 2004
Posts: 53
Location: France

PostPosted: Fri Nov 26, 2010 8:36 pm    Post subject: Reply with quote

Do I need to re-emerge Apache when I change the
Code:
/etc/conf.d/apache2
file?
I mean, I will modify this in order to add the
Code:
-D CGI
directive.

Will I need to re-ermege then?

Thanks
Back to top
View user's profile Send private message
huuan
Apprentice
Apprentice


Joined: 19 Feb 2007
Posts: 265
Location: California

PostPosted: Thu Dec 05, 2013 12:44 am    Post subject: Reply with quote

in case someone else finds this unanswered tail:

if you already emerged apache with APACHE2_MODULES="cgi" set in make.conf then you only need to restart apache after adding -D CGI to /etc/conf.d/apache2
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum