I have a simple setup with Apache2.4 and PHP-FPM and I am trying to enable +Indexes option but I get 404 "File not found." when trying to access a folder that doesn't have an index file even when autoindex is enabled.
Here's part of my vhost:
#php
ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/var/run/fpm/fatal.sock|fcgi://
#super public directory with Indexes!
<Location /pub>
Options +Indexes
IndexOptions +FancyIndexing
</Location>
When I try to access http://domain.com/pub/ I expected to see a list of files I put there but instead I get error 404 Not Found.
I wonder where this comes from since ProxyPassMatch shouldn't forward the request because there is no .php in the query so next is directory index which looks for index.php which doesn't exists (404) but why then mod_autoindex doesn't work?
When I remove the ProxyPassMatch line the autoindex works just fine and I see the folder content listed.
Any ideas?
I found the answer here http://blog.famillecollet.com/post/2014/03/28/PHP-FPM-and-HTTPD-2.4-improvement
As the ProxyPassMatch directive is evaluated at the very beginning of each request:
AddType (for MultiView) or DirectoryIndex directives are not usable
right management per directory is not available
each Alias directive needs another proxy rule
The SetHandler directive, evaluated later, is much more flexible / usable.
So I changed my vhost to look like this and got rid of the ProxyPassMatch directive.
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/fpm/fatal.sock|fcgi://"
</FilesMatch>
Note: this solution applies to Apache 2.4.9+
(I do wonder if there are any performance difference and in what direction?)
Related
I have a problem with a .htaccess file not being read by Apache. I'm using it on my local machine, port 81. I'm using Windows 10.
I created a .htaccess file in the root directory of my .php files.
When I enter some rubbish inside .htaccess file nothing happens (website loads normally). I've checked many tutorials, threads and was unable to find a viable solution.
What I have done so far:
Entered anything in the .htaccess file to check or the 500 error (didn't work)
Checked the httpd.conf file for AllowOverride All (for directory as well)
Re-installed Xampp
This is how my settings in httpd.conf look like now:
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
<Directory />
AllowOverride All
# Require all denied
</Directory>
I've got no idea what to do next. Any ideas?
Is this section in httpd.con like this, or is looking for any other file name?
#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess
hoping someone can help me, i am having the same problem with the php files trying to download.
i have tried all answers but the:
ln -s /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php5.conf ln -s /etc/apache2/mods-available/php5.load /etc/apache2/mods-enabled/php5.load
when i try them i get unable to create symbolic link file exists, so i guess thats done all ready, anyone else have anything more i can try, i am new to linux and i followed this guide to set everything up: http://www.howtoforge.com/perfect-server-ubuntu-12.04-lts-apache2-bind-dovecot-ispconfig-3
the strange thing is joomla and drupal sites work, but own php script doesent.
i have tried everything on this page:
apache2 on ubuntu - php files downloading
but none of them work.
when i try to run this command: sudo a2enmod php
i get, module php does not exist. i guess i need to run a command to install it? if so what is it please.
thanks all.
Heres More info as requested:
not sure where isp config stores the folders for each website, but i connected to the ftp site and uploaded into the web folder, same as i did for the working drupal and joomla sites that are working
sites enabled:
/
000-apps.vhost#
000-default#
000-ispconfig.conf#
000-ispconfig.vhost#
100-analytics.cyberglide.co.uk.vhost#
100-cyberglide.co.uk.vhost#
100-hideandcollars.co.uk.vhost#
100-jubileeleather.co.uk.vhost#
100-rookselectrical.co.uk.vhost#
100-wolds-uniforms.co.uk.vhost#
all sites are working (they are running joomla or drupal) but www.jubileeleather.co.uk/index.php
had to put up a html file until i can get it sorted.
php script:
<?php
//Add required class and config files below
require ('_class/cms.php');
require ('config/db.php');
//Get Required Page, if its not set call it the index
$page = (isset($_GET['page'])) ? $_GET['page'] : 'index';
//If the page is set as index
if($page == 'index'){
//Include Index
require ('public/index.php');
}
//Else if the page is contact
elseif ($page == 'contact') {
//Include Contact
require ('public/contact.php');
//If the page is none of the above
} else {
//Include Layout
require ('public/layout.php');
}
?>
i am using putty via ssh, how would i copy content from a file to post on here? also which files would you need? thanks again.
here is the contents of the jubileeleather v host file, not sure what i am looking for in here:
AllowOverride None
Order Deny,Allow
Deny from all
DocumentRoot /var/www/jubileeleather.co.uk/web
ServerName jubileeleather.co.uk
ServerAlias www.jubileeleather.co.uk
ServerAdmin webmaster#jubileeleather.co.uk
ErrorLog /var/log/ispconfig/httpd/jubileeleather.co.uk/error.log
Alias /error/ "/var/www/jubileeleather.co.uk/web/error/"
ErrorDocument 400 /error/400.html
ErrorDocument 401 /error/401.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 405 /error/405.html
ErrorDocument 500 /error/500.html
ErrorDocument 502 /error/502.html
ErrorDocument 503 /error/503.html
<IfModule mod_ssl.c>
</IfModule>
<Directory /var/www/jubileeleather.co.uk/web>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/clients/client3/web4/web>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# suexec enabled
<IfModule mod_suexec.c>
SuexecUserGroup web4 client3
</IfModule>
# Clear PHP settings of this website
<FilesMatch "\.ph(p3?|tml)$">
SetHandler None
</FilesMatch>
# php as fast-cgi enabled
# For config options see: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
<IfModule mod_fcgid.c>
IdleTimeout 300
ProcessLifeTime 3600
# MaxProcessCount 1000
DefaultMinClassProcessCount 0
DefaultMaxClassProcessCount 100
IPCConnectTimeout 3
IPCCommTimeout 360
BusyTimeout 300
</IfModule>
<Directory /var/www/jubileeleather.co.uk/web>
AddHandler fcgid-script .php .php3 .php4 .php5
FCGIWrapper /var/www/php-fcgi-scripts/web4/.php-fcgi-starter .php
Options +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/clients/client3/web4/web>
AddHandler fcgid-script .php .php3 .php4 .php5
FCGIWrapper /var/www/php-fcgi-scripts/web4/.php-fcgi-starter .php
Options +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# add support for apache mpm_itk
<IfModule mpm_itk_module>
AssignUserId web4 client3
</IfModule>
<IfModule mod_dav_fs.c>
# Do not execute PHP files in webdav directory
<Directory /var/www/clients/client3/web4/webdav>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler None
</FilesMatch>
</Directory>
DavLockDB /var/www/clients/client3/web4/tmp/DavLock
# DO NOT REMOVE THE COMMENTS!
# IF YOU REMOVE THEM, WEBDAV WILL NOT WORK ANYMORE!
# WEBDAV BEGIN
# WEBDAV END
</IfModule>
Apart from having the own PHP files in a directory with PHP parsing enabled (can't really say how it's done with Apache as I'm not using for some time), you should check if your script has the correct extension (should be always .php) and script opening tag <?php - don't use short tag <? to avoid possible problems when moving the script to live server.
Tho since your files are returned for download, I think you don't have your scripts in directory with enabled PHP parsing. Posting your Apache and PHP config files could help us to identify the problem.
On my development machine, this works as expected (requests to server.com/.myhandler are executed as php), but when I uploaded to the production machine (running ubuntu server 11.04) it just serves the un-executed php. Is there anything extra I must configure for this to work?
Contents of .htaccess file:
AddType text/html .myhandler
<FilesMatch "\.myhandler$">
SetHandler application/x-httpd-php
</FilesMatch>
DirectoryIndex .myhandler index.php index.htm
Most possibly this type of configuration is not allowed via .htaccess in the directory where your script and .htaccess reside in. Put this in your Apache site / VirtualHost configuration:
<Directory /absolute/path/to/webroot/>
AllowOverride All
</Directory>
I am trying to set up simpleSAML.php but I am running into an issue with the Apache Alias directory. I have successfully used Alias so that when the user visits domain.com/auth then it uses the folder /var/saml/www.
However, for some reason it just lists the contents of the folder /var/saml/www rather than running the index.php file.
I have included the relevant virtual host below.
<VirtualHost *:80>
ServerAdmin helpdesk#domain.com
DocumentRoot /var/www/html/open
ServerName open.domain.com
ErrorLog logs/open.domain.com-error_log
CustomLog logs/open.domain.com-access_log common
Alias /auth/ /var/saml/www
Alias /auth /var/saml/www
<Directory /var/saml/www>
Options All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You can add the following line to your config:
AddType application/x-httpd-php .php
This way apache knows it has to parse the files using php.
P.S. I think you may have to restart Apache rather than a reload.
Update
As Alfabravo commented:
Agree. He also needs to check the DirectoryIndex directive and add index.php to it
Greetings experts and gurus, I am looking for some help with an apache php configuration problem.
I have been running several websites from an apache2 setup on an ubuntu server for some time now without problems using the line NameVirtualHost * in my etc/apache2/conf.d/virtual.conf file. I recently updated the server version to the latest lts version and I am now unable to run php files.
I am running all my sites for the location "/home/www/[site-name]/htdocs" and I have setup and enabled all my sites in /etc/apache2/sites-available. I have also disabled the default site.
for each sites file I have specified the following:
# Indexes + Directory Root.
# DirectoryIndex index.html index.htm index.php
DocumentRoot /home/www/[site-name]/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ /home/www/[site-name]/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog /home/www/[site-name]/logs/error.log
CustomLog /home/www/[site-name]/logs/access.log combined
I restart apache and enter the url for a php test page on my server and I am met with an "Internal Server Error". When I check the error log I get:
Script "/home/www/[site-name]/htdocs/test.php" resolving to "/home/www/[site-name]/htdocs/test.php" not within configured docroot.
For some reason when looking into the error, suphp came up a lot. According to this link:
Don't be fooled into thiking this has anything to do with the Apche virtual host document root, this is actually another setting in the suphp config file. Including the paths which contained the RoundCube scripts fixed this one. For example:
docroot=/var/www:/usr/share/roundcube:/var/lib/roundcube:${HOME}/public_html
You need to edit your /etc/suphp/suphp.conf file and change the docroot to whatever is appropriate.
It looks you missed the virtual hosts configuration for every site name:
<VirtualHost IP:80>
ServerName yourdomainname
ServerAlias www.yourdomainname
DocumentRoot /home/www/[site-name]/htdocs/
ScriptAlias /cgi-bin/ /home/www/[site-name]/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
ErrorLog /home/www/[site-name]/logs/yourdomainname.ua-error.log
CustomLog /home/www/[site-name]/logs/yourdomainname-access.log combined
</VirtualHost>
<Directory "/home/www/[site-name]/htdocs/">
Options FollowSymLinks
AllowOverride None
Order allow,deny
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
Thanks for all the help, I got there in the end. It seems that upgrading to Ubuntu 10.04 turned on suPHP. It has ended up being a good thing as the reason why I was getting errors was down to file management in my htdocs getting sloppy.
To fix my issues I had to do several things:
First I turned on suphp error messages in /etc/apache2/sites-available/[site-name]. This gave me the true error, which told me that some of my pages had the wrong permissions. I then set all my folder permissions in www to 755 and the files to 644. I also had to lower the min_uid and min_gid fileds in suphp.conf to 33.