I'm working on a project in a group. I'm the only guy using Linux. Anyways, we use git and there's one file which causes me problems.
The htaccess contains the following:
<IfModule authz_core_module>
Require all granted
</IfModule>
If I comment out the Require all granted, it works, however, when it's not commented out, it gives me a 500 server error.
I do have authz_core_module and I can't disable it because if it's not a module it will Deny from all.
Why is that line giving me a 500 server error? The file works correctly at all those other guys who use Windows. Is it something because of my Linux apache?
I got it to work by adding these 2 lines to my httpd.conf file:
<Directory /THEPATHHERE/>
Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo Indexes Authconfig
</Directory>
I've just installed ubuntu-server_6.04.2_LTS, after the fresh installation I've enabled mod_rewrite, it's showing in phpinfo()
my .htaccess file is OK
but, still requests are not going through index.php
You should check if for that specific directory (root folder of your project), apache is configured to allow overriding through .htaccess.
If you want to allow such override, the directives found in apache.conf or the specific settings for your virtual host should look like this:
<Directory /var/www/>
AllowOverride All
Require all granted
</Directory>
I'm working on a new server and I installed via yum the "Web Server" group. Php and mysql work fine but I can't get .htaccess to work.
Heres my test .htaccess file:
WASD_TEST_CALL_ERROR
I put this as .htaccess in a test folder along with an index.html page.
Instead of reporting an error it goes ahead and loads the index page without displaying any errors.
Thanks
Make sure AccessFileName set to .htaccess
Search httpd.conf for AccessFileName directive. It defines name of the distributed configuration file:
grep -i AccessFileName httpd.conf
Make sure users are allowed to use .htaccess file
What you can put in these files is determined by the AllowOverride directive. This directive specifies, in categories, what directives will be honored if they are found in a .htaccess file. If this directive is set to None, then .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem.
grep -i AllowOverride httpd.conf
When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files:
AllowOverride All
Save and close the file. Restart httpd:
service httpd restart
Have you set AllowOverride in Apache config? If not, set AllowOverride from none to all.
On CentOS7, the following should help:
Under string AllowOverride controls what directives may be placed in .htaccess files in /etc/httpd/conf/httpd.conf:replace AllowOverride None to AllowOverride All
In /etc/httpd/conf.modules.d/00-base.conf check rewrite_module must be:
LoadModule rewrite_module modules/mod_rewrite.so
.htaccess file must be in /var/www/html/
Example content .htaccess:
AuthUserFile /var/www/.htpasswd
AuthGroupFile /dev/null
AuthName "Please Enter Password"
AuthType Basic
Require valid-user
check and restart Apache:
httpd -t
/bin/systemctl restart httpd.service
Go to /etc/httpd/conf/httpd.conf and find below line. htaccess Context is allowed in .htaccess files: AllowOverride All
Save and close the file. Restart httpd:
/etc/httpd/conf/httpd.conf:replace AllowOverride None to AllowOverride All
httpd -M | grep rewrite_module should result
rewrite_module (shared)
Still not working even after making sure all above in place? Then make sure your .htaccess has below line at the top.
RewriteEngine On
I know there are a lot of questions on here about this, but most of them seem to be from people who don't know that 'memory_limit', 'post_max_size', and 'upload_max_filesize' are PHP_INI_PERDIR (i.e. they can't be changed using ini_set()). I already learned that the hard way.
However, everything indicates that I should be able to change them using a .htaccess file—everything, that is, except my actual experience.
Here are the contents of my .htaccess file:
# Allow large file uploads
php_value memory_limit 4294967296
php_value post_max_size 1073741824
php_value upload_max_filesize 524288000
I've tried a number of different combinations, but none of them seem to have any effect on anything. I know I've gotta be missing something, but I can't for the life of me figure out what that something is.
P.S. I'm running PHP 5.2.4 locally on Mac OS X 10.4 from entropy.ch.
You need to permit those settings to be changed in a .htaccess file. For that, you need AllowOverride Options or AllowOverride All in a relevant section your httpd.conf file (in a <Directory> block for that directory or a parent thereof).
Note also this will only work if you're using Apache and mod_php5 (i.e., no CGI/FastCGI/whatever).
See also the manual.
I would like to configure Apache 2 running on Kubuntu to execute Perl CGI scripts. I've tried some steps that I came across by googling, but nothing seems to work.
What is the right way of achieving this?
This post is intended to rescue the people who are suffering from *not being able to properly setup Apache2 for Perl on Ubuntu. (The system configurations specific to your Linux machine will be mentioned within square brackets, like [this]).
Possible outcome of an improperly setup Apache 2:
Browser trying to download the .pl file instead of executing and giving out the result.
Forbidden.
Internal server error.
If one follows the steps described below with a reasonable intelligence, he/she can get through the errors mentioned above.
Before starting the steps. Go to /etc/hosts file and add IP address / domain-name` for example:
127.0.0.1 www.BECK.com
Step 1: Install apache2
Step 2: Install mod_perl
Step 3: Configure apache2
open sites-available/default and add the following,
<Files ~ "\.(pl|cgi)$">
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
Options +ExecCGI
PerlSendHeader On
</Files>
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory [path-to-store-your-website-files-like-.html-(perl-scripts-should-be-stored-in-cgi-bin] >
####(The Perl/CGI scripts can be stored out of the cgi-bin directory, but that's a story for another day. Let's concentrate on washing out the issue at hand)
####
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ [path-where-you-want-your-.pl-and-.cgi-files]
<Directory [path-where-you-want-your-.pl-and-.cgi-files]>
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
AddHandler cgi-script .pl
Order allow,deny
allow from all
</Directory>
<Files ~ "\.(pl|cgi)$">
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
Options +ExecCGI
PerlSendHeader On
</Files>
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory [path-to-store-your-website-files-like-.html-(perl-scripts-should-be-stored-in-cgi-bin] >
####(The Perl/CGI scripts can be stored out of the cgi-bin directory, but that's a story for another day. Let's concentrate on washing out the issue at hand)
####
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ [path-where-you-want-your-.pl-and-.cgi-files]
<Directory [path-where-you-want-your-.pl-and-.cgi-files]>
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
AddHandler cgi-script .pl
Order allow,deny
allow from all
</Directory>
Step 4:
Add the following lines to your /etc/apache2/apache2.conf file.
AddHandler cgi-script .cgi .pl
<Files ~ "\.pl$">
Options +ExecCGI
</Files>
<Files ~ "\.cgi$">
Options +ExecCGI
</Files>
<IfModule mod_perl.c>
<IfModule mod_alias.c>
Alias /perl/ /home/sly/host/perl/
</IfModule>
<Location /perl>
SetHandler perl-script
PerlHandler Apache::Registry
Options +ExecCGI
</Location>
</IfModule>
<Files ~ "\.pl$">
Options +ExecCGI
</Files>
Step 5:
Very important, or at least I guess so, only after doing this step, I got it to work.
AddHandler cgi-script .cgi .pl
<Files ~ "\.pl$">
Options +ExecCGI
</Files>
<Files ~ "\.cgi$">
Options +ExecCGI
</Files>
<IfModule mod_perl.c>
<IfModule mod_alias.c>
Alias /perl/ /home/sly/host/perl/
</IfModule>
<Location /perl>
SetHandler perl-script
PerlHandler Apache::Registry
Options +ExecCGI
</Location>
</IfModule>
<Files ~ "\.pl$">
Options +ExecCGI
</Files>
Step 6
Very important, or at least I guess so, only after doing this step, I got it to work.
Add the following to you /etc/apache2/sites-enabled/000-default file
<Files ~ "\.(pl|cgi)$">
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
Options +ExecCGI
PerlSendHeader On
</Files>
Step 7:
Now add, your Perl script as test.pl in the place where you mentioned before in step 3 as [path-where-you-want-your-.pl-and-.cgi-files].
Give permissions to the .pl file using chmod and then, type the webaddress/cgi-bin/test.pl in the address bar of the browser, there you go, you got it.
(Now, many of the things would have been redundant in this post. Kindly ignore it.)
You'll need to take a look at your Apache error log to see what the "internal server error" is. The four most likely cases, in my experience would be:
The CGI program is in a directory which does not have CGI execution enabled. Solution: Add the ExecCGI option to that directory via either httpd.conf or a .htaccess file.
Apache is only configured to run CGIs from a dedicated cgi-bin directory. Solution: Move the CGI program there or add an AddHandler cgi-script .cgi statement to httpd.conf.
The CGI program is not set as executable. Solution (assuming a *nix-type operating system): chmod +x my_prog.cgi
The CGI program is exiting without sending headers. Solution: Run the program from the command line and verify that a) it actually runs rather than dying with a compile-time error and b) it generates the correct output, which should include, at the very minimum, a Content-Type header and a blank line following the last of its headers.
(Google search brought me to this question even though I did not ask for perl)
I had a problem with running scripts (albeit bash not perl). Apache had a config of ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ however Apache error log showed File does not exist: /var/www/cgi-bin/test.html.
Tried putting the script in both /usr/lib/cgi-bin/ and /var/www/cgi-bin/ but neither were working.
After a prolonged googling session what cracked it for me was
sudo a2enmod cgi and everything fell into place using /usr/lib/cgi-bin/.
If you have successfully installed Apache web server and Perl please follow the following steps to run cgi script using perl on ubuntu systems.
Before starting with CGI scripting it is necessary to configure apache server in such a way that it recognizes the CGI directory (where the cgi programs are saved) and allow for the execution of programs within that directory.
In Ubuntu cgi-bin directory usually resides in path /usr/lib , if not present create the cgi-bin directory using the following command.cgi-bin should be in this path itself.
mkdir /usr/lib/cgi-bin
Issue the following command to check the permission status of the directory.
ls -l /usr/lib | less
Check whether the permission looks as “drwxr-xr-x 2 root root 4096 2011-11-23 09:08 cgi- bin” if yes go to step 3.
If not issue the following command to ensure the appropriate permission for our cgi-bin directory.
sudo chmod 755 /usr/lib/cgi-bin
sudo chmod root.root /usr/lib/cgi-bin
Give execution permission to cgi-bin directory
sudo chmod 755 /usr/lib/cgi-bin
Thus your cgi-bin directory is ready to go. This is where you put all your cgi scripts for execution. Our next step is configure apache to recognize cgi-bin directory and allow execution of all programs in it as cgi scripts.
Configuring Apache to run CGI script using perl
A directive need to be added in the configuration file of apache server so it knows the presence of CGI and the location of its directories. Initially go to location of configuration file of apache and open it with your favorite text editor
cd /etc/apache2/sites-available/
sudo gedit 000-default.conf
Copy the below content to the file 000-default.conf between the line of codes “DocumentRoot /var/www/html/” and “ErrorLog $ {APACHE_LOG_DIR}/error.log”
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
Restart apache server with the following code
sudo service apache2 restart
Now we need to enable cgi module which is present in newer versions of ubuntu by default
sudo a2enmod cgi.load
sudo a2enmod cgid.load
At this point we can reload the apache webserver so that it reads the configuration files again.
sudo service apache2 reload
The configuration part of apache is over now let us check it with a sample cgi perl program.
Testing it out
Go to the cgi-bin directory and create a cgi file with extension .pl
cd /usr/lib/cgi-bin/
sudo gedit test.pl
Copy the following code on test.pl and save it.
#!/usr/bin/perl -w
print “Content-type: text/html\r\n\r\n”;
print “CGI working perfectly!! \n”;
Now give the test.pl execution permission.
sudo chmod 755 test.pl
Now open that file in your web browser http://Localhost/cgi-bin/test.pl
If you see the output “CGI working perfectly” you are ready to go.Now dump all your programs into the cgi-bin directory and start using them.
NB: Don't forget to give your new programs in cgi-bin, chmod 755 permissions so as to run it successfully without any internal server errors.
As of Ubuntu 12.04 (Precise Pangolin) (and perhaps a release or two before) simply installing apache2 and mod-perl via Synaptic and placing your CGI scripts in /usr/lib/cgi-bin is really all you need to do.
There are two ways to handle CGI scripts, SetHandler and AddHandler.
SetHandler cgi-script
applies to all files in a given context, no matter how they are named, even index.html or style.css.
AddHandler cgi-script .pl
is similar, but applies to files ending in .pl, in a given context. You may choose another extension or several, if you like.
Additionally, the CGI module must be loaded and Options +ExecCGI configured. To activate the module, issue
a2enmod cgi
and restart or reload Apache. Finally, the Perl CGI script must be executable. So the execute bits must be set
chmod a+x script.pl
and it should start with
#! /usr/bin/perl
as its first line.
When you use SetHandler or AddHandler (and Options +ExecCGI) outside of any directive, it is applied globally to all files. But you may restrict the context to a subset by enclosing these directives inside, e.g. Directory
<Directory /path/to/some/cgi-dir>
SetHandler cgi-script
Options +ExecCGI
</Directory>
Now SetHandler applies only to the files inside /path/to/some/cgi-dir instead of all files of the web site. Same is with AddHandler inside a Directory or Location directive, of course. It then applies to the files inside /path/to/some/cgi-dir, ending in .pl.
I'm guessing you've taken a look at mod_perl?
Have you tried the following tutorial?
EDIT: In relation to your posting - perhaps you could include a sample of the code inside your .cgi file. Perhaps even the first few lines?
For those like me who have been groping your way through much-more-than-you-need-to-know-right-now tutorials and Docs, and just want to see the thing working for starters, I found the only thing I had to do was add:
AddHandler cgi-script .pl .cgi
To my configuration file.
http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addhandler
For my situation this works best as I can put my perl script anywhere I want, and just add the .pl or .cgi extension.
Dave Sherohman's answer mentions the AddHandler solution also.
Of course you still must make sure the permissions/ownership on your script are set correctly, especially that the script will be executable. Take note of who the "user" is when run from an http request - eg, www or www-data.