Currently in my PHP coding I have to put include($_SERVER['DOCUMENT_ROOT']"./ in front of every file path in my web code. I previously asked and discovered I could set include_path. I tried setting this in both .htaccess and the .conf for the virtual host, but it just fails out and doesn't work/load the include.
Code:
this is in the vhost .conf file:
<IfModule mod_php7.c>
php_value include_path ":/var/www/testdomains/domain-test1.local/php"
php_admin_flag engine on
</IfModule>
(I've tried putting this outside the IfModule area with no success.
My .php file on the webserver:
<?php require "/authcheck.php" ?>
What am I doing wrong?
Related
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.
Overview
I'm trying to host a few legacy PHP apps on Heroku with Apache. They all relied on the following deprecated syntax to parse any unknown file types (without the .php extension) as PHP.
DefaultType application/x-httpd-php
This has been replaced by AddType in Apache 2.4 (Heroku currently uses v2.4.37). Heroku also uses mod_proxy_fcgi to process PHP files via fcgi://heroku-fcgi.
Issue
I have a file foo.test and I want to have it handled by PHP FPM. Taking cues from the docs and the default Apache config provided by Heroku, here's what I've tried:
# .htaccess
<FilesMatch \.test$>
<If "-f %{REQUEST_FILENAME}">
SetHandler proxy:fcgi://heroku-fcgi
</If>
</FilesMatch>
# apache_app.conf (properly loaded via Procfile)
ProxyPassMatch "^/(.*\.test(/.*)?)$" "fcgi://heroku-fcgi/app/$1"
With both of these I get a plain-text 403 Access denied. response from PHP FPM. I'm sure both configs are properly loading and pointing to the FCGI handler because changing the endpoint results in other errors.
My Apache skills are long since rusty and I can't seem to find any good pointers online. The Apache error log is also clean. Any ideas (without the obvious "change all extensions to PHP, you dumbass") would be appreciated!
Fairly obvious solution. PHP FPM has its own configuration with a security.limit_extensions flag. It defaults to .php.
The solution was to unset that value: security.limit_extensions =. This naturally can pose some security threats, but these apps are only going up for static demo.
I was using heroku/heroku-buildpack-php but forked that to update this file. The htaccess FilesMatch should work now but I just ended up placing it into the Apache config file to avoid repetition across the sites I'll be serving.
security.limit_extensions can be customized with a configuration file passed as a Procfile argument.
https://devcenter.heroku.com/articles/custom-php-settings#php-fpm-settings
PHP-FPM settings:
In addition to php_value and php_flag for php.ini specific settings, any pool specific PHP-FPM configuration directives are valid in that configuration file, so you can use it to fine tune PHP-FPM’s behavior.
So you can set up it like the following
Procfile
web: vendor/bin/heroku-php-apache2 -C apache.conf -F fpm_custom.conf web/
apache.conf
<FilesMatch \.test$>
<If "-f %{REQUEST_FILENAME}"> # make sure the file exists so that if not, Apache will show its 404 page and not FPM
SetHandler proxy:fcgi://heroku-fcgi
</If>
</FilesMatch>
fpm_custom.conf
security.limit_extensions = .php .test
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"
I was able to install PHPMyAdmin through the command line on my new Ubuntu server. But now when I try to access it I get "You don't have permission to access /phpmyadmin/index.php on this server.".
I believe it has to do with these lines in the .conf file for it since they refer to mod_php and I am using php-fastcgi instead of mod-php (for memory usage purposes).
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
php_flag magic_quotes_gpc Off
php_flag track_vars On
php_flag register_globals Off
php_admin_flag allow_url_fopen Off
php_value include_path .
php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/
</IfModule>
I have tried commenting out the tags, but the php settings don't work outside of it so there must be a way to do this with PHP FastCGI. Does anyone know how to do this?
I am new to using PHP FastCGI.
Turns out I just had to add to the option "ExecCGI" to the apache.conf file for PHPMyAdmin. I had to put this under (within) the directory tag.
You need to check the file ownership if it is for web user, on phpmyadmin directory
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