Perl scripts will not run in apache (Permission Denied) [duplicate] - apache

This question already has answers here:
How do I configure Apache 2 to run Perl CGI scripts?
(8 answers)
Closed 8 years ago.
I have LAMP installed on Ubuntu 14.04.1.
I want to be able to run cgi scripts from all directories that are within my website. So I added this to /etc/apache2/apache.conf
<Directory /var/www/>
AddHandler cgi-script .cgi .pl
Options FollowSymLinks +ExecCGI
</Directory>
I also did this edit in /etc/apache2/mods-enabled/mime.conf
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
AddHandler cgi-script .cgi .py .pl
But now when i visit my script it says
You don't have permission to access /hello.pl on this server.
But I have chmodded and chowned the script.. in fact look...
ls -la hello.cgi
-rwxrwxrwx 1 www-data www-data 84 Jan 26 03:19 hello.pl

(Self answer by Banned_User moved from question body)
What I did was edit /etc/apache2/sites-enabled/www.example.com/ and add:
<Directory /var/www/www.example.com>
Options +ExecCGI
</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.

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.

Apache giving "No such file or directory" error when trying to run cgi

No such file or directory: AH01241: exec of '/usr/lib/cgi-bin/haml.cgi' failed
Is the main error I'm getting right now. Trying to run a custom CGI, the cgi currently works successfully on another server I have, but it seems I've overlooked some configuration option on this server.
I have the cgi-bin directory set to allow CGI execution:
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
I've set the perms of haml.cgi to 777, simply to eliminate any permission issue from being the problem:
root#jp:/usr/lib/cgi-bin# ls -lah
total 16K
drwxr-xr-x 2 root www-data 4.0K Aug 14 18:28 .
drwxr-xr-x 64 root root 4.0K Oct 28 2014 ..
-rwxrwxrwx 1 root www-data 505 Aug 14 18:20 haml.cgi
I have cgid enabled:
root#jp:/etc/apache2# ls mods-enabled/
access_compat.load alias.load authz_core.load autoindex.load deflate.load filter.load mpm_event.load setenvif.load
actions.conf auth_basic.load authz_host.load cgid.conf dir.conf mime.conf negotiation.conf status.conf
actions.load authn_core.load authz_user.load cgid.load dir.load mime.load negotiation.load status.load
alias.conf authn_file.load autoindex.conf deflate.conf env.load mpm_event.conf setenvif.conf
And my site itself is set up to exec cgi:
DocumentRoot /home/j/web/
DirectoryIndex index.haml index.html
<Directory "/home/j/web">
AllowOverride All
Allow from All
Options +ExecCGI
</Directory>
Am I missing anything here? Any idea why the CGI isn't running?
Ended up actually being my ruby installation that was giving me issues. Running the cgi directly showed me this:
root#jp:/usr/lib/cgi-bin# ./haml.cgi
bash: ./haml.cgi: /usr/bin/ruby: bad interpreter: No such file or directory

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

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>

Munin server with apache - You don't have permission to access /munin on this server

On a fresh apache and munin server install when I to to domain.com/munin I get this error.
Forbidden
You don't have permission to access /munin on this server.
for these directories I did a chown -R munin:munin
dbdir /var/lib/munin
htmldir /var/cache/munin/www
logdir /var/log/munin
rundir /var/run/munin
What am I supposed to do with apache? I restated apache with /etc/init.d/apache restart but still get forbidden. I have made no changes to the apache config files from a fresh apache install.
Apache < 2.4
Open the Munin Apache config file:
vim /etc/munin/apache.conf
change the the following lines:
Order allow,deny
Allow from localhost 127.0.0.0/8 ::1
Options None
like so:
Order allow,deny
Allow from all
Options FollowSymLinks SymLinksIfOwnerMatch
Restart Apache and you're golden.
Apache > 2.4
Open the Munin Apache config file:
vim /etc/munin/apache24.conf
change the the following lines:
Require local
Options None
like so:
Require all granted
Options FollowSymLinks SymLinksIfOwnerMatch
Restart Apache and you're golden.
sudo service apache2 restart
For Apache 2.4 (which ships with Ubuntu 13.10), the /etc/munin/apache.conf configuration file syntax has changed:
Order allow, deny
Allow from all
needs to be changed to
Require all granted
Additional detail regarding upgrading from Apache 2.2 to Apache 2.4 can be found in the Apache upgrade notes.
I had the same problem, and none of the advices were helpful.
So I've browsed a little bit in the directory tree, and found the apache24.conf file. So I've add to this /etc/munin/apache24.conf file the following, as j7nn7k described:
Require all granted
Options FollowSymLinks SymLinksIfOwnerMatch
And of course I deleted the old values.
Now It's working!
I don't know if it's the same problem but I found a solution that fixed it for me.
I followed the tutorial here (from the italian ubuntu wiki), and changed the string from:
htmldir /var/cache/munin/www
To:
htmldir /var/www/munin
Then I edited the file:
vim /etc/munin/apache.conf
Allowing from all, as Johe Green did. But then take a close look to the Directory path, since it must be modified as the htmldir path in the munin conf.
Alias /munin /var/www/munin
<Directory /var/www/munin>
Order allow, deny
Allow from all
[...]
I had the same issue, after a clean install of apache2, munin and munin-node on Ubuntu 12.04LTS. Tried all the suggested options above with no effect. Found in the end that I had to
chmod 755 /var/www/munin
chown -R munin:munin /var/www/munin
That solved it for me.
cd /pub
more beer
I'm using apache 2.4.10 and munin 2.0.25-1 on ubuntu 15.04
To solve the problem, I followed Lars' sugestion, i.e. using Require all granted, but applying the changes to the file /etc/munin/apache24.conf
Changing /etc/munin/apache.conf had no effect for me. I have tried to grep me to the file determining which apache config file is chosen without success. But at list I solve the problem.
I faced the same problem and changed the /etc/munin/apache.conf line to Allow from all but still got the same 403 Forbidden error, I also had to change munin-node.conf
Comment block from munin-node.conf file where I made a change
#A list of addresses that are allowed to connect. This must be a
regular expression, since Net::Server does not understand CIDR-style
network notation unless the perl module Net::CIDR is installed. You
may repeat the allow line as many times as you'd like
Added my munin IP here in similar format and it worked
allow ^127.0.0.1$
P.S I am running munin master and node on the same box when testing this.
I have the same issue when create a soft link named 'share' under the root document and let it point to a package like /Users/me/desktop/share
firstly I do
chmod 655 /Users/me/desktop/share
I can not work
then I do
chmod 655 /Users/me/desktop
It works, I can see the 'share' listed under the root document path.
I user Mac Yosemite 10.10.3 and its in build Apache 2.4
hope its helpful
I was having the same problem as the OP using Ubuntu 14.04 and the stock versions available with apt-get. I tried the official Ubuntu documentation, the DigitalOcean instructions, and couldn't get graphs to show up (403 errors). I uninstalled (purged)/reinstalled munin since it was supposedly a random bug. I finally had luck when following this howtoforge writeup. It does not aim to move munin data from /var/cache/munin/www. Rather, it ensures:
Extra plugins are installed: apt-get install munin munin-node munin-plugins-extra
Apache fcgid is enabled: a2enmod fcgid
A sparse /etc/munin/apache.conf file is used (see below)
Replace your entire /etc/munin/apache.conf file contents with:
Alias /munin /var/cache/munin/www
<Directory /var/cache/munin/www>
# Require local
Require all granted
Options FollowSymLinks SymLinksIfOwnerMatch
Options None
</Directory>
ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
<Location /munin-cgi/munin-cgi-graph>
# Require local
Require all granted
Options FollowSymLinks SymLinksIfOwnerMatch
<IfModule mod_fcgid.c>
SetHandler fcgid-script
</IfModule>
<IfModule !mod_fcgid.c>
SetHandler cgi-script
</IfModule>
</Location>
I had the same issue and solved it.
I was using Munin with Apache 2.4.18 so there was a seperate configuration file (/etc/munin/apache24.conf) which I had to edit.
Editing /etc/munin/apache.conf had NO effect.
Here is my complete install procedure for installing Munin on Linux Mint 17.3 (kernal 3.19), and should also work with recent Ubuntu.
Unlike Monit, Munin does not have its own web server, so is a bit more complicated to install.
#!/bin/bash
# Install script for Apache 2 with MySQL, PHP 5, etc.
# Update the Package Lists
apt-get update
# Install the MySQL Server and Client before installing Apache
apt-get install mysql-server mysql-client
# Install Apache
apt-get install apache2
# Install PHP5
apt-get install php5 libapache2-mod-php5
# Restart Apache
/etc/init.d/apache2 restart
# Install some extras
apt-get install snmp php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
# Once again, restart
/etc/init.d/apache2 restart
# Install the Munin Server and the Client
apt-get install munin munin-node
# Restart the machine
shutdown -r now
Ignore the uninstall part and replace your entire /etc/munin/apache.conf file contents as hamx0r says earlier in this thread (please vote up his post):
https://stackoverflow.com/a/35656044/5178979
"Allow from all" makes sense to me, but it no longer works.
Maybe because I installed Munin prior to installing Apache2, I was missing the following symbolic links:
/etc/apache2/conf-available/munin.conf -> ../../munin/apache.conf
/etc/apache2/conf-enabled/munin.conf -> ../conf-available/munin.conf
cd /etc/apache2/conf-available && ll
If you do not see the link, create it:
ln -s ../../munin/apache.conf munin.conf && ll
If the first file is missing, this one is probably also missing
cd /etc/apache2/conf-enabled/ && ll
Create the link:
ln -s ../conf-available/munin.conf munin.conf && ll
Restart Apache2, wait 5 minutes, and hopefully it works.
If you want to monitor a machine other than the one running Munin, you simply install munin-node, and then add a line to /etc/munin/munin-node.conf
Find this line
allow ^127.0.0.1$
Add another similar line that includes the address of the munin server like:
allow ^192.168.1.100$
This is not necessary for Windows clients running munin-node.
Don't forget to add machines you want to monitor to your Munin server
/etc/munin/munin.conf
# MyMachine
[MyMachineName.mydomain]
address 127.0.0.1
use_node_name yes
Now for a question for the experts. Why do some machines not report hard drive temperature? I know that is a vague question and probably needs more details.
Edit /etc/munin/apache.conf and uncomment the 4 lines following from AuthUserFile.
AuthUserFile /etc/munin/.htpasswd
AuthName "Munin"
AuthType Basic
require valid-user