/cgi-bin/printenv - doesn't execute - outputs the script itself - apache

I am trying to get cgi scripts working with a clean build of httpd-2.4.6 on SciLinux 6 - x86_64.
My httpd.conf file: http://pastebin.com/P0CKYfqU
This is essentially the one that was installed - with a few edits.
I do have:
ScriptAlias /cgi-bin/ "/var/tmp/apps/cgi-bin/"
in the httpd.conf file.
I built httpd using the following configure command:
./configure --prefix=/var/tmp/apps --with-apr=/var/tmp/apps/bin/apr-1-config --with-apr-util=/var/tmp/apps/bin/apu-1-config --with-pcre=/var/tmp/apps/bin/pcre-config --enable-cgi
I have done the following to /var/tmp/apps/cgi-bin/printenv
edited the #! line
done chmod a+rx
The command works from the command line.
However, when I go to localhost:8001/cgi-bin/printenv I just see the script itself - not the output of the script.
I'm sure I must be missing a configure option or an httpd.conf directive.

It turrns out that in httpd-2.4.6 the mod_cgi module is not built or enabled by default.
Here is a build recipe which works:
Build httpd with there configure options:
configure \
--prefix=$TOP \
--with-apr=$TOP/bin/apr-1-config \
--with-apr-util=$TOP/bin/apu-1-config \
--with-pcre=$TOP/bin/pcre-config \
--enable-modules=all \
--enable-proxy \
--enable-proxy-http \
--disable-userdir \
--enable-cgi
And then in the httpd.conf file make sure the mod_cgi.so module is loaded:
LoadModule cgi_module modules/mod_cgi.so
To get the printenv cgi script to work, add the ExecCGI option to the options for the /cgi-bin/ directory:
<Directory "/var/tmp/apps/cgi-bin">
AllowOverride None
- Options None
+ Options +ExecCGI
Require all granted
</Directory>

Related

Internal Server Error with Trac: "ModuleNotFoundError: No module named 'trac'"

I'm installing Trac on a new RHEL 8 server and am getting an Internal Server Error in the httpd error log:
ModuleNotFoundError: No module named 'trac'
I've tried looking in audit logs with
journal -xe | grep httpd
(and also grepped for trac, and apache) - and zero error information shown there either.
httpd starts normally without error.
Trac is configured to use wsgi, it's not the standalone version that has its own built in server. Apache HTTPD should be error handling.
Here is the httpd trac.conf file:
WSGIScriptAlias /trac /data/www/virtualhosts/trac/cgi-bin/trac.wsgi
<Location "/trac/login">
AuthType Basic
AuthName "Issue Tracker"
AuthUserFile /data/www/virtualhosts/trac/conf/trac.htpasswd
Require valid-user
</Location>
<Directory /data/www/virtualhosts/trac/cgi-bin>
WSGIApplicationGroup %{GLOBAL}
# For Apache 2.2
<IfModule !mod_authz_core.c>
Order deny,allow
Allow from all
</IfModule>
# For Apache 2.4
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
</Directory>
and trac.wsgi
import os
def application(environ, start_request):
if not 'trac.env_parent_dir' in environ:
environ.setdefault('trac.env_path', '/data/www/virtualhosts/trac')
if 'PYTHON_EGG_CACHE' in environ:
os.environ['PYTHON_EGG_CACHE'] = environ['PYTHON_EGG_CACHE']
elif 'trac.env_path' in environ:
os.environ['PYTHON_EGG_CACHE'] = \
os.path.join(environ['trac.env_path'], '.egg-cache')
elif 'trac.env_parent_dir' in environ:
os.environ['PYTHON_EGG_CACHE'] = \
os.path.join(environ['trac.env_parent_dir'], '.egg-cache')
from trac.web.main import dispatch_request
return dispatch_request(environ, start_request)
python version
[user#box] # python --version
Python 2.7.17
I'm at a loss on why I can't get any error information to either display on screen or preferably write to a log file. This server isn't production so I can have stuff on screen for now.
Any help greatly appreciated
The problem might be the permissions on the cgi-bin directory or one of its parents.
The trac-admin deploy command will create a trac.wsgi for you, but you need to deploy outside your environment directory, otherwise, you'll get this error:
Error: Resources cannot be deployed to a target directory that is equal to or below the source directory '/Users/rjollos/Documents/Workspace/trac-dev/tracenvs/proj-1.4/htdocs'.
Please choose a different target directory and try again.
If your environment is /data/www/virtualhosts/trac, run:
$ trac-admin /data/www/virtualhosts/trac deploy /data/www/virtualhosts/www
Then point your virtualhosts file to /data/www/virtualhosts/www/cgi-bin/trac.wsgi.

Symfony 3 / Apache - Post request gives Error 500

I have a Symfony 3 API and I'm trying to register a user but I have an error 500 when executing a POST request (GET request works). It's probably a problem with my Apache configuration because I don't have any errors in my logs files. A var_dump('ok') at the top of my function also give me error 500.
My Apache configuration:
<VirtualHost *:80>
ServerName subscription.api.local
ServerAlias www.subscription.api.local
DocumentRoot /var/www/subscription_backend/web
DirectoryIndex /app.php
<Directory /var/www/subscription_backend/web>
AllowOverride None
Order Allow,Deny
Allow from All
FallbackResource /app.php
</Directory>
<Directory /var/www/subscription_backend>
Options FollowSymlinks
</Directory>
<Directory /var/www/subscription_backend/web/bundles>
FallbackResource disabled
</Directory>
ErrorLog /var/log/subscription-error.log
CustomLog /var/log/subscription-access.log combined
</VirtualHost>
Line added in my hosts file:
127.0.0.1 subscription.api.local www.subscription.api.local
My projet is in ~/Projects/subscription_backend directory and I use a symbolic to /var/www/subscription_backend :
sudo ln -s ~/Projects/subscription_backend /var/www/subscription_backend
Permissions of "~/Projects/subscription_backend directory":
Permissions of "/var/www/subscription_backend directory":
lrwxrwxrwx 1 www-data www-data 55 avril 19 21:45 /var/www/subscription_backend -> /home/khan/Projects/subscription_backend/
What's wrong with my configuration ? Why GET request works but not POST ?
Thx
Finally, i solved the problem.
First,fix permissions https://symfony.com/doc/3.3/setup/file_permissions.html:
cd ~/Projects/subscription_backend
rm -rf var/cache/*
rm -rf var/logs/*
HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data [n]ginx' | grep -v root | head -1 | cut -d\ -f1)
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
composer install
Then install memcache extension:
sudo apt-get install memcached
sudo apt-get install php-memcached
sudo apt-get install php-memcache
sudo service apache2 restart
Clear cache:
bin/console c:c
bin/console c:c --env=prod

run lxr perl module as scripts under apache 2.4

I have been trying to get it right for the past couple of days, but could not. I am not a LAMP guy.
I installed Apache 2 from the default Ubuntu repositories. Here is the contents of the /etc/apache2 directory:
/etc/apache2$ ls
apache2.conf conf-enabled magic mods-enabled sites-available
conf-available envvars mods-available ports.conf sites-e
And here are the contents of the sites-enabled directory:
/etc/apache2/sites-enabled$ ls
000-default.conf
Here is what I added to 000-default.conf:
Alias "/lxr" "/usr/local/share/lxr"
<Location /lxr>
allow from all
Require all granted
</Location>
And here is the contents of the perl module at this link.
My problem is: when I visit the link http://localhost/lxr/source , I get it as a text file, it is not executed as a script.
How can I fix this?
Thank you!
You have first to install mod_perl on your system. If you are in a debian-like distribution, suche as ubuntu, you can use :
sudo apt-get install libapache2-mod-perl2
Then enable this module on apache :
sudo a2enmod perl
and restart the apache server
sudo service apache2 restart
You will also have to add some configuration such as :
PerlModule Apache::Registry
Alias /cgi-bin/ /usr/lib/cgi-bin
<Location /cgi-bin>
SetHandler perl-script
PerlHandler Apache::Registry
PerlSendHeader On
Options +ExecCGI
</Location>
Read this article for more information.

Share folders Docker

I'm used to develop on vagrant but docker looks faster so I just tried it. This seems really good but I need to share the folders between my host and docker to easily update my code without recompiling docker.
I tried to add:
VOLUME /Users/ajouve/dev/test/test:/var/www/test
or
VOLUME /Users/ajouve/dev/test/test:/var/www/test:rw
in my dockerfile but the folders are nos sync
This is my complete dockfile
FROM ubuntu:12.04
MAINTAINER ajouve version: 0.1
RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN mkdir /var/www/test
VOLUME /Users/ajouve/dev/test/test:/var/www/test:rw
COPY test.conf /etc/apache2/sites-availables/
RUN ln -s /etc/apache2/sites-availables/test.conf /etc/apache2/sites-enabled/test.conf
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
EXPOSE 80
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
this is the test.conf
<VirtualHost *:80>
ServerName test.local
DocumentRoot /var/www/test
<Directory /var/www/test>
# enable the .htaccess rewrites
AllowOverride All
Order allow,deny
Allow from All
</Directory>
ErrorLog /var/log/apache2/test-error.log
CustomLog /var/log/apache2/test-access.log combined
</VirtualHost>
I have an empty folder when I'm trying to access to the server via a browser
You can bind the folder when you start your docker instance
with -v /src/dockerShared/:/usr/local/src
have a Look here for a example
Your host folder have to be owned by the same uid:gid of the folder inside the container.

When executing CGI, give me only plain text

When I tried to execute CGI, it gives me only plain text.
I installed PHP5.3.11 with apache2
All of them were installed manually from source code, not from apt-get
## Apache2
./configure --prefix/=usr/loca/apache2
make
make install
## php5
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs
make
make test
make install
The above are commands that I used to install apache2 and php5.
I guess my installation for apache2 and php5 is correct, since I can run php code on my server. So I tried to execute CGI script after properly, I guess, setting a configuration.
However it shows only plain text of CGI script.
###Start###
#!/usr/bin/perl -w
print "Content-type: text/html\r\n\r\n";
print "Hello there!<br />\nJust testing .<br />\n";
for ($i=0; $i<10; $i++){
print $i."<br />";
}
###End###
perl is properly installed at /usr/bin/perl.
I set my httpd.conf like below.
<Directory "/usr/local/apache2/cgi-bin">
Options +ExecCGI
AddHandler cgi-script .cgi .pl
Require all granted
</Directory>
I think cgi-php5 is installed correctly as well, since when I execute "php-cgi -h", it gives me a result.
And when I open phpinfo() through browser,
GATEWAY_INTERFACE is set to CGI/1.1
Any thing I am missing? I appreciate for your help.
I found the answer.
my mistake was on httpd.conf and it was really stupid mistake. :-(
I had to uncomment the following line.
LoadModule cgi-script blahblah
No one knows how many hour I spend for this stupid mistake :-(