php require file - php

I have trouble for requiring a file:
$path_requires = "/var/www/vhosts/website.com/v3" ;
require("$path_requires/vars.inc.php") ;
The error is:
/var/www/vhosts/website.com/portraits Fatal error: require(): Failed
opening required '/var/www/vhosts/website.com/v3/vars.inc.php'
If i do from a terminal:
cat /var/www/vhosts/website.com/v3/vars.inc.php
I checked the permissions on the directory. website.com. it's:
drwxr-xr-x 17 apache psaserv 4096 Oct 18 03:32 v3
I changed the permissions to that directory with no success.
Does anyone know what is going on. Why I can't require this php file ?

Chances are it's looking for the /var/www/vhosts folder inside your actual hosting and quite obviously not finding it. Try:
$path_requires = "/v3" ;
require("$path_requires/vars.inc.php") ;

Check using this
$path_requires = "https://www.website.com/v3" ; (base url)
require("$path_requires/vars.inc.php") ;

phpinfo() result:
open_basedir /var/www/vhosts/website.com/portraits/:/tmp/ no value
The /etc/php.ini:
;open_basedir =
How to change the local value ? If I change /etc/php.ini the local value have the upper hand.
/website.com/portraits/
portraits is the directory of the sub-domain portraits.website.com

Related

Got error 'PHP message: PHP Notice: Unknown: file created in the system's temporary directory in Unknown on line 0\nPHP message: PHP Warning:

PHP Warning: File upload error - unable to create a temporary file in Unknown
This is a problem that keeps recurring.
We have servers with PHP FPM and for some strange reason this problem keep happening:
Got error 'PHP message: PHP Notice: Unknown: file created in the system's temporary directory in Unknown on line 0\nPHP message: PHP Warning: File upload error - unable
to create a temporary file in Unknown on line 0\n'.
Our user php conf looks like the following when it first happened:
[USER]
user = $pool
group = $pool
listen = /usr/local/php72/sockets/$pool.sock
listen.owner = $pool
listen.group = apache
listen.mode = 660
pm = ondemand
pm.max_children = 100
pm.process_idle_timeout = 20
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f USER#domain.tld
php_admin_value[session.save_path] = /home/USER/tmp
php_admin_value[open_basedir] = /home/USER/:/tmp/:/var/tmp/:/usr/local/php72/lib/:/usr/local/php54/lib/:/usr/local/php55/lib/:/usr/local/php56/lib/:/usr/local/php70/lib/:/usr/local/php71/lib/:/usr/local/php72/lib/:/usr/local/lib/php/
php_admin_value[mail.log] = /home/USER/.php/php-mail.log
security.limit_extensions = .php .php52 .php53 .php54 .php55 .php56 .php60 .php70 .php71 .inc .php72
It was thought that the actual fix was, by adding the tmp variables in the user php fpm conf:
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
Restart php-fpm, the problem seemed fix at first. But, our websites still cannot upload files.
The temporary fix seems to restart php fpm. But, after a while the problem happens again.
And the conf still has the /tmp variables.
We added, in all the php.ini we could find, the upload_tmp_dir = /tmp, and that also was a temporary fix.
This has happened on multiple shared and dedicated servers, with multiple websites.
I did a test on our test server:
sys_get_temp_dir(): gives the
/tmp
ini_get('upload_tmp_dir'): gives no value:
string(0) ""
But my test files uploaded fine
Test code used from:https://www.w3schools.com/php/php_file_upload.asp
PrivateTmp=true is set to true on the PHP FPM instance. This should not have any effect, because we are giving /tmp as the specified dir...?
Is there any way how to permanently fix this issue?
CentOS Linux release 7.5.1804 (C
DirectAdmin server
PHP-FPM
PHP 7.2.10 (FPM)

Need help in setting up PEAR in PHP

I need to emails from my PHP script. The Server, which I have hosted my website on, does not allow the use of core PHP mail() function. They say I should write SMTP authentication code for sending emails.
I need to use require_once('System.php'); at the beginning of my PHP script, but the script execution stops beyond this line. In Apache logs of the Server, the log entry says:
AH01071: Got error 'PHP message: PHP Warning: require_once(): open_basedir restriction in effect. File(/opt/plesk/php/5.6/share/pear/System.php) is not within the allowed path(s): (/var/www/vhosts/kbcsurveyors.com/:/tmp/) in /var/www/vhosts/kbcsurveyors.com/preinspection.kbcsurveyors.com/test-smtp-mail.php on line 20\nPHP message: PHP Warning: require_once(/opt/plesk/php/5.6/share/pear/System.php): failed to open stream: Operation not permitted in /var/www/vhosts/kbcsurveyors.com/preinspection.kbcsurveyors.com/test-smtp-mail.php on line 20\nPHP message: PHP Fatal error: require_on................
kbcsurveyors.php is the domain that I have hosted.
For SMTP authentication, I need to use PEAR. I had to include the path/to/pear in the php.ini on the Server. Since, the Server does not allow me to change its own php.ini, I copied it to my domain's folder and appended the path/to/pear to include_path.
Here are commands I used and outputs I had from those commands:
shell_exec('cp /opt/plesk/php/5.6/etc/php.ini /var/www/vhosts/kbcsurveyors.com/httpdocs/includes');
shell_exec('pear config-get php_dir');
OUTPUT: /usr/share/pear
shell_exec('php --ini');
OUTPUT:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed: /etc/php.d/00-ioncube-loader.ini,
/etc/php.d/curl.ini,
....
echo get_include_path();
OUTPUT .:/opt/plesk/php/5.6/share/pear
echo 'Class Exists: '.(class_exists('System', false)) ? 'Yes' : 'No';
OUTPUT: Class Exists: Yes
But again, require_once 'System.php'; throws the above error in Apache log.
The phpinfo()ed a script. It shows the include_path as .:/opt/plesk/php/5.6/share/pear in both Local Value and Master Value.
What mistake am I making? Please help.
Thanks in advance
The problem was solved by appending the path shown by
shell_exec('pear config-get php_dir'); to include_path in php.ini of primary domain and all sub-domains.

php file not included despite setting include_path

I have an apache2 server running on my Linux machine. I edited the file /etc/php5/apache2/php.ini by setting include_path to
include_path = ".:/usr/share/php:/var/www/subdir"
To make sure I did not change the wrong file, I also edited all other php.ini files (there was one more) I found on my computer and checked the output of phpinfo() which printed the correct include_path from above. (I also restarted apache2.)
However, when I use lines like
use some\name\space;
require_once('./subsubdir/file.php');
in a file start.php (which lies in another directory /var/www/subdir/anothersubdir/), the require_once command does not work, as I get the following error in the apache log file
[error] [client 127.0.0.1] PHP Fatal error: require_once(): Failed opening required './subsubdir/file.php' (include_path='.:/usr/share/php:/var/www/subdir') in /var/www/subdir/anothersubdir/start.php on line x
I also tried
require_once('/subsubdir/file.php');
but it did not work. How do I have to inlcude file.php when I have set the include_path as shown above ?
Thanks a lot in advance !
The first questions I would be asking myself are:
is the webserver running in a chroot environment?
what are the permissions on the target file?
And a simple way to answer both of these would be:
print getcwd() . "<hr />\n";
$t='/var/www/subdir/anothersubdir/subsubdir/file.php';
function show_permissions($path)
{
if (strlen($path)>1) {
show_permissions(dirname($path));
}
if (is_readable($path)) {
print "Permissions for $path: " . var_export(stat($path)) . "<br />";
} else {
print "can't read $path <br /> \n";
}
}
(my money would be on a permissions problem - not a path issue)
Try rebooting Apache, to clear the internal cache.

Different behavior of PHP’s include/require on Windows and CentOS

These are code of my PHP applications myApp.phpand mypartsA/main.php.
myApp.php
<?php
echo ("##### myApp is starting now !!! </br>");
require_once('/parts/mypartsA/main.php');
?>
mypartsA/main.php
<?php
echo ("#### mypartsA is required </br>");
?>
And myApp.php and mypartsA/main.php are in following structure.
Document_root
|
+--- test
| |
| +--- myApp.php
|
+--- parts
|
+--- mypartsA
|
+---main.php
I’ve used this application on Windows+Apache for a year with no problem but recently I migrate this to CentOS+Apache then I get fatal error related to include_path
PHP Warning: require_once(/parts/mypartsA/main.php)
[<a href='function.require-once'>function.require-once</a>]
: failed to open stream
: No such file or directory
in /var/www/html/test/myApp.php on line 12
PHP Fatal error: require_once() [<a href='function.require'>function.require</a>]
: Failed opening required (/parts/mypartsA/main.php’
(include_path='.:/php/includes:/usr/share/pear:/usr/share/pear/PEAR:/var/www/html')
in /var/www/html/test/myAPP.php on line 12
According to PHP.net if a path is defined the include_path will be ignored.
http://www.php.net/manual/en/function.include.php
I think in my case PHP tries to find parts directory from C:\ or / not from include_path.
require_once(/parts/mypartsA/main.php);
Therefore result of myAPP.php must be fatal error whether on Windows or on CentOS.
But my application has been working for a year with no error on Windows. PHP can find parts directory correctly.
Can sameone try those codes above on Windows and see..
##### myApp is starting now !!!
#### mypartsA is required
or get error?
Now,I want to know is why results of same code are different between running on Windows and running on CentOS.
What dirctive in PHP.ini do I have to check ?
I know if I change this code to add absolute path with $ _SERVER['DOCUMENT_ROOT'].
require_once($_SERVER['DOCUMENT_ROOT']./parts/mypartsA/main.php);
It’ll work well. But there are many applications with same style of coding and I don’t want to change all of them.
These are additional information.
include_path values phpinfo() shows on Windows
.;C:\PHP;C:\PHP\pear;C:\Apache2.2.22\htdocs
include_path values phpinfo() shows on CentOS
.:/php/includes:/usr/share/pear:/usr/share/pear/PEAR:/var/www/html
$path = realpath(dirname(__FILE__)) . "/../../parts/mypartsA/main.php";
require_once($path);
try with this path
$path = "../parts/mypartsA/main.php";
the second path should work with document root.

Why can't I configure Zend-framework

Racking my head as to why I can't include the Zend-framework into my project. The documentation is unclear about how to set up the environment (Or haven't found where it is). Looked at this thread: How to configure Zend Framework on linux machine? but no luck. In the phpinfo() I see Zend configured but why can't I use it? Looked for documentation on how to add this to PEAR/PECL, no luck.
I did see this post: http://devzone.zend.com/article/4683 but still not working
What I have tried:
Option 1
require_once('/usr/share/php/libzend-framework-php/Zend/Loader/Autoloader.php');
Zend_Loader_Autoloader::getInstance();
Option 2
sudo vi /etc/php5/apache2/php.ini
changed this line:
;include_path = ".:/usr/share/php"
to:
include_path=".:/usr/share/php:/usr/share/pear:/usr/share/php/libzend-framework-php"
restarted Apache
Getting this error:
Warning: require_once(Zend/Loader.php): failed to open stream: No such file or directory in /usr/share/php/libzend-framework-php/Zend/Loader/Autoloader.php on
line 24
Call Stack:
0.0002 61600 1. {main}() /var/www/webservice/zend/server.zend.xmlrpc.php:0
0.0009 174412 2. require_once('/usr/share/php/libzend-framework-php/Zend/Loader/Autoloader.php') /var/www/webservice/zend/server.zend.xmlrpc.php:2
Fatal error: require_once(): Failed opening required 'Zend/Loader.php' (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/php/libzend-framework-p
hp/Zend/Loader/Autoloader.php on line 24
Call Stack:
0.0002 61600 1. {main}() /var/www/webservice/zend/server.zend.xmlrpc.php:0
0.0009 174412 2. require_once('/usr/share/php/libzend-framework-php/Zend/Loader/Autoloader.php') /var/www/webservice/zend/server.zend.xmlrpc.php:2
i would suggest to
chmod 775 /usr/share/php/libzend-framework-php -R as Ran BarZik suggestion .
and double check the apache user's permissions .
then symlink it to the your application library by using this :
ln -s /var/www/webservice/library/Zend /usr/share/php/libzend-framework-php/
I;ve installed Zend FW on many Linux system and if I encountered problems it was on the include path that was set incorrectly or permission problem.
Maybe the path isn't right, try 'vi /usr/share/php/libzend-framework-php/Zend/Loader/Autoloader.php' or any other text editor that you like. Does it work?
Maybe it is permission problem, try to change /usr/share/php/libzend-framework-php/ to 755:
chmod 775 /usr/share/php/libzend-framework-php -R
Your main configuration should be in: application/configs/application.ini
This tells the zend controller where to look for the library files etc.
Did you look here when you were installing? : http://framework.zend.com/manual/en/learning.quickstart.create-project.html
According to the error messages, your updated include_path isn't being picked up.
What does phpinfo() have to say about your include_path?
What if you set_include_path(get_include_path . ':/usr/share/php/libzend-framework-php'); before your include?
I'm assuming here that /usr/share/php/libzend-framework-php/Zend exists...
Try to move zend library:
cd /usr/share/php/libzend-framework-php
mv library/Zend /usr/share/php/
revert include_path to original:
include_path = ".:/usr/share/php"
Restart apache
After banging my head up against the wall for a couple of days I think I figured it out. Looking at this page: http://devzone.zend.com/article/4683 I understood I needed to add the zend path in the php.ini file. I did this with no effect. After looking at my PHP Configuration I noticed in /etc/php5/conf.d/ I could load zend by uncommenting the library path in the zend-framework.ini file which PHP loads as an additional module/ini

Categories