php file not included despite setting include_path - php

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.

Related

Starting web server with `php -S` not reading php.ini file

I have a local project I am working on. I have at the root of my project and index.php php.ini and local_connector.php.
When I run php -S ... from inside my project. It says that the php.ini is not loaded.
This is the code I have in my index.php
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
This is what I have in my php.ini
auto_prepend_file = "./local_connector.php"
The idea is I will have multiple pages that use the local_connector but I don't want to include it in every file. Is this possible with php's local server?
I would rather not set up an entire local apache server, so if someone knows a good way of getting this to work, or a work around. That would be very helpful.

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 require file

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

PHP cli command line safe_mode restriction

I'm using the Kohana framework (3.0.9), which generates daily logs. I want to mail the log file if one was made the day before CRON runs the script, but after days trying I can't figure out how to put off safe_mode in PHP CLI modus.
When I'm running my script on the web, there is no problem. But I want to run the script as a CRON task on my Plesk 9.5.2 server (or on the command line as root user) I'm getting the following error:
ErrorException [ 2 ]: dir(): SAFE MODE Restriction in effect. The script whose uid is 10001 is not allowed to access /var/www/vhosts/mydomain.com/subdomains/mysubdomain/httpdocs/application/logs/2011/01 owned by uid 48 ~ APPPATH/classes/controller/ajax.php [ 181 ]
I've allready put SAFE MODE off in my Plesk control panel, which works fine for the web request, but not in on the command line or as an CRON task.
I'm using the following code to test if its working:
$d = dir(APPPATH.'logs/2011/01/');
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
echo $entry."\n";
}
$d->close();
I can read the directory APPPATH.'logs/', and also the directory APPPATH.'logs/2011', but the directory's representing each month with the daily log files always give an error.
At nowadays you can schedule php script execution from UI like this:
In case you still need execute script via command line pay attention that Plesk's PHP binaries are placed in:
# 7.0
/opt/plesk/php/7.0/bin/php
# 5.6
/opt/plesk/php/5.6/bin/php
# 5.5
/opt/plesk/php/5.5/bin/php
# and so on
Original answer:
I know this is a few months old, but for the next person that comes across a problem while using Plesk and cron and PHP, here's the answer.
While Plesk does run cron as ROOT, it also runs PHP by default with safe mode ON, which means that when you setup a cron in Plesk that needs PHP, it's going to have restrictions that you do not experience from the shell or from the web.
So what you do is use the CLI /etc/php.ini option override, like so:
/usr/bin/php -q -d safe_mode=Off /var/www/vhosts/path-to-your-php-file.php
Have you disabled safe_mode in the php.ini for CLI?
You can find the location of this file by running the following command php --ini. Search for safe_mode in this file and change the line to safe_mode = Off.

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