php include in .htaccess not getting set - php

I am trying to set the include path for php in my htaccess file. It works on my local computer but on my dev server it doesn't work. Both ubuntun running apache2.2 Here is my .htaccess file:
AddType application/x-httpd-php .html .htm .php
# ---------------------------------------------------------------------------
# PHP.INI VALUES
# Upload Variables, Include Path, Etc
# ---------------------------------------------------------------------------
php_value include_path "/var/www/includes:.:/usr/local/lib/php:/var/www/"
php_value upload_max_filesize 5242880
php_value post_max_size 5242880
php_value memory_limit 32M
# ---------------------------------------------------------------------------
# Prepend File
# ---------------------------------------------------------------------------
php_value auto_prepend_file "/var/www/includes/prepend.php"
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
I am lost as to why this isn't working. Any ideas?
The apache error is saying:
PHP Fatal error: require_once(): Failed opening required 'db.inc.php' (include_oath='.:/usr/share/php:/usr/share/pear') in /var/www/concert2.php on line 3

Check:
Your directory structure is the exact same
Apache has permissions to read this file
The path in your code. Make sure there's no typos, etc.
This related article might help:
PHP Fatal Error Failed opening required File
In my experience, these problems are almost always either path related (you're not actually pointing where you think you're pointing) or permissions related.

Related

Include html or php at beginning of each page

I need insert some code or file (banner) to every web site using .htaccess on php7.3-fpm.
File .htaccess.
<FilesMatch \.php$>
# Apache 2.4.10+ can proxy to unix socket
#SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/"
SetHandler "proxy:unix:/var/run/php/php7.3-fpm.sock|fcgi://localhost/"
</FilesMatch>
I tried add
SetEnv PHP_VALUE 'auto_prepend_file "/var/www/html/test/banner.php"'
or
php_value auto_prepend_file "/dir/path/banner.php"
but nothing worked. Is possible to do this via .htaccess file, or I must set it in configuration file of php-fpm?
Thanks.

.htaccess php_value include_path not working

I have a small project in local. I'm working under Windows and with XAMPP. My file directory structure is:
Root directory: C:\xampp\htdocs\routes
Under this folder, I have my bootstrap.php with the configuration I want to initialize my project.
Public folder: C:\xampp\htdocs\routes\htdocs
Under this folder I have my index.php and my .htaccess.
Inside this .htaccess I have the following configuration:
php_value include_path .:/routes
php_value auto_prepend_file bootstrap.php
If I do a get_include_path() inside the index.php, it shows ".:/routes".
But the message I get on my web browsers (after typing http://localhost/routes/htdocs) all the time is:
Fatal error: Unknown: Failed opening required 'bootstrap.php' (include_path='.:/routes') in Unknown on line 0
I have tried a lot of combinations of include_path inside the .htaccess:
php_value include_path ".:/routes"
php_value include_path .:../routes
php_value include_path ".:./routes"
php_value include_path ".:routes"
...
The configuration of my httpd.conf is:
DocumentRoot "C:/xampp/htdocs"
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory /routes>
AllowOverride all
</Directory>
If I hard code the info in bootstrap inside the index.php, it works (at least this tells me the requirements inside bootstrap are well configured).
I don't know what to do for my project to recognize the bootstrap.php.
What am I missing? What am I doing wrong?
Thank you in advance for your help
First, the <Directory> block has no effect for include. Since this is not an Apache query, but rather a preprocessing order.
Second, use absolute paths in your include_path, to make it independent from where your files are sitting.
Third, make sure the path to bootstrap.php is openable by the user your webserver runs as, and that the file itself is readable.
if you are using Windows it should be ;
php_value include_path ".;./routes"

413: Request Entity Too Large on HTTPS

I've seen several questions with the same problem and most propose the following solutions
increse the post_max_size in the php.ini file (set to 8M)
increse upload_max_filesize in php.ini file (set to 8M)
set the LimitRequestBody directive in httpd.conf (set to 8388608 = 8M)
none of them worked for me!
Then I restarted the apache service but even still the same problem. the form I am trying to send has only 5 fields (two checkboxes, 2 selects, one file), I'm uploading a file of 653KB and dont work (work if the file is less 80K), never had this problem before.
Setup:
ArchLinux
x86_64 Linux 3.10.6-2-ARCH
PHP 5.4.18
Apache/2.2.25
Virtual host with SSL enabled
I found that the problem is when I have SSL enabled, it has a default configuration SSLRenegBufferSize in 131072 (128k).
Adding this directive in the virtual host directory I can increase the size and the error no longer appears:
<VirtualHost *:443>
# ...
<Directory ...>
#...
SSLRenegBufferSize 8388608 # 8M
</Directory>
</VirtualHost>
add only
SSLRenegBufferSize 8388608
(without # 8M )

PHP Include Always Fails

Apache HTTP Server 2.2.21 with VirtualHosts under SuExec
PHP 5.3.8 via fcgid
Arch Linux 2011.08.19
I am in the process of migrating from shared hosting to VPS. The code I had ran fine before the move but is now failing at this line:
require_once($_SERVER['DOCUMENT_ROOT'] . 'includes/content/header.php');
Error log says:
PHP Fatal error: require_once(): Failed opening
required '/srv/www/hostname/public/includes/content/header.php'
(include_path='.:/usr/share/pear') in
/srv/www/hostname/public/index.php on line 3
I tried the same line without the document root part, with and without ./, etc. with no luck. No difference with require, include_once, or include, either. Yet, I can verify that the file exists at that exact location by copy-pasting from the error log and cding to it…
But just to be absolutely sure, I tested the return values of the includes as well as file_exists—they all return false. Yet all of the files are chown'd by the SuExec user/group, and no combination of permissions helps (on directories or files); have tried from 644 to 777. What's going on here?
Edit:
Same result with files in the same directory.
Apache & SuExec error logs reports nothing.
Safe Mode is set to "Off" in php.ini.
dirname(__FILE__) and exec('pwd') return the same as $_SERVER['DOCUMENT_ROOT'] but without the trailing slash.
fread, file_get_contents, and realpath(dirname(__FILE__)) all return false.
set_include_path() has no effect.
Running require via php-cgi directly from the command line returns Internal Server Error while include returns blank output; running either via php returns blank output.
Here's my vhost config:
<VirtualHost *:80>
ServerAdmin admin#hostname.com
DocumentRoot "/srv/www/hostname/public/"
ServerName hostname.com
ServerAlias www.hostname.com
SuexecUserGroup hostname hostname
ErrorLog "/srv/www/hostname/logs/error.log"
LogLevel debug
CustomLog "/srv/www/hostname/logs/access.log" combined
<Directory /srv/www/hostname/public>
Order allow,deny
Allow from all
</Directory>
# http://www.linode.com/forums/viewtopic.php?t=2982
<IfModule !mod_php5.c>
<IfModule !mod_php5_filter.c>
<IfModule !mod_php5_hooks.c>
<IfModule mod_actions.c>
<IfModule mod_alias.c>
<IfModule mod_mime.c>
<IfModule mod_fcgid.c>
AddHandler php-fcgi .php
Action php-fcgi /fcgid-bin/php-fcgid-wrapper
Alias /fcgid-bin/ /srv/www/hostname/fcgid-bin/
<Location /fcgid-bin/>
SetHandler fcgid-script
Options +ExecCGI
Order allow,deny
Allow from all
</Location>
ReWriteEngine On
ReWriteRule ^/fcgid-bin/[^/]*$ / [PT]
</IfModule>
</IfModule>
</IfModule>
</IfModule>
</IfModule>
</IfModule>
</IfModule>
</VirtualHost>
First make sure the file exists...
Then try to navigate to it using
www.hostname/public/includes/content/header.php (if your using
something local it would be
localhost/public/includes/content/header.php)
If that does not load either something is wrong with your
installation or your file is corrupt.
Try loading the header from somewhere else
Did you check permission of folders containg that files ?
Folder should has read permission for apache (or any user that runs http-server).
Have you try add path to include path ?
$path = '/includes/content';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
http://php.net/manual/en/function.set-include-path.php
It always works to me ->
if ( DIRECTORY_SEPARATOR == '/' )
{
$path = dirname(__FILE__).'/';
}
else
{
$path = str_replace('\\', '/', dirname(__FILE__)).'/';
}
give a try!
[EDITED]
using dirname() function always works! $path = dirname(__FILE__).'/'; perhaps the problem is in your server. Not in the programming (script).
DerfK over at ServerFault nailed it: it was an open_basedir restriction.
Circling back to post the solution:
I didn't realize that open_basedir was unaffected by Safe Mode being off—it was looking in /srv/http/ but not /srv/www/, which would be the containing directory for /srv/www/hostname/public/includes/content/.

.htaccess files, PHP, includes directories, and windows XAMPP configuration nightmare

XAMPP makes configuring a local LAMP stack for windows a breeze. So it's quite disappointing that enabling .htaccess files is such a nightmare.
My problem:
I've got a PHP application that requires apache/php to search for an /includes/ directory contained within the application. To do this, .htaccess files must be allowed in Apache and the .htaccess file must specify exactly where the includes directory is.
Problem is, I can't get my Apache config to view these .htaccess files. I had major hassles installing this app at uni and getting the admins there to help with the setup. This shouldn't be so hard but for some reason I just can't get Apache to play nice.
This is my setup:
c:\xampp
c:\xampp\htdocs
c:\xampp\apache\conf\httpd.conf - where I've made the changes listed below
c:\xampp\apache\bin\php.ini - where changes to this file affect the PHP installation
It is interesting to note that c:\xampp\php\php.ini changes mean nothing - this is NOT the ini that affects the PHP installation.
The following lines are additions I've made to the httpd.conf file
#AccessFileName .htaccess
AccessFileName htaccess.txt
#
# The following lines prevent .htaccess and .htpasswd
# files from being viewed by Web clients.
#
#<Files ~ "^\.ht">
<Files ~ "^htaccess\.">
Order allow,deny
Deny from all
</Files>
<Directory "c:/xampp/htdocs">
#
# AllowOverride controls what directives may be placed in
# .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
The following is the entire .htaccess file contained in:
c:\xampp\htdocs\application\htaccess.txt
<Files ~ "\.inc$">
Order deny,allow
Deny from all
</Files>
php_value default_charset "UTF-8"
php_value include_path ".;c:\xampp\htdocs\application\includes"
php_value register_globals 0
php_value magic_quotes_gpc 0
php_value magic_quotes_runtime 0
php_value magic_quotes_sybase 0
php_value session.use_cookies 1
php_value session.use_only_cookies 0
php_value session.use_trans_sid 1
php_value session.gc_maxlifetime 3600
php_value arg_separator.output "&"
php_value url_rewriter.tags "a=href,area=href,frame=src,input=src,fieldset="
The includes directory exists at the location specified.
When I try to access the application I receive the following error:
Warning: require(include.general.inc) [function.require]: failed to open stream: No such file or directory in C:\xampp\htdocs\application\menu\logon.php on line 21
Fatal error: require() [function.require]: Failed opening required include.general.inc (include_path='.;C:\xampp\php\pear\random') in C:\xampp\htdocs\application\menu\logon.php on line 21
The include path c..\random\ is specified in the php.ini file listed above. The XAMPP install fails to allow another include path as specified in the htaccess.txt file.
I'm guessing there's probably an error with the httpd.conf OR the htaccess.txt file.. but it doesn't seem to be reading the .htaccess file. I've tried to be as thorough as possible so forgive the verbosity of the post.
Now I know a workaround could be to simply add the include_path to the PHP file, but I'm not going to have access to the php.ini file on the location I plan to deploy my app. I will, however, be able to request the server admin allows .htaccess files.
renamed htacces.txt to .htaccess and ammended the appropriate directives in the httpd.conf file and all seems to work. The application suggested the naming of htaccess.txt and the ammended directives in the httpd. These are obviously wrong (at least for a XAMPP stack).
By the way, using ini_set() is a much friendlier way if the app needs to be deployed to multiple locations so thanks especially for that pointer.
Why do you need to rename .htaccess to htaccess.txt
Try setting the include_path using set_include_path() and see if that helps (as an intermediate fix)
Verify which php.ini to use through a phpinfo()
You can alter the include_path on each request using ini_set(). This would avoid having to use htaccess at all.
My htaccess works under XAMPP fine - though some modules are disabled by default - are you sure that the modules you want are enabled?
I think the searchprase you are looking for is:
AllowOverride All
My guess is that within xampp you need to enable AllowOverride (through an .htaccess) in httpd.conf. It's a simple security measure that prevents newbies from installing a hackable platform :P
You need to enable AllowOverride All in main http.conf file. Look inside XAMPP_DIR/apache/conf/http.conf)
Simply Do this:
open file ...\xampp\apache\conf\httpd.conf
find line "LoadModule rewrite_module modules/mod_rewrite.so"
if here is a # before this line remove it.(remove comment)
its working

Categories