Creating scheduled tasks in plesk result in error - php

When creating a scheduled task to run a php script in Plesk Onyx on windows it results in an error.
However when i run the same script in the browser it works without any issues.
I have been looking for the permission settings in the webroot and set them to allow access to all user groups on the server.
The error i get is the following:
Warning: require(\pcp2\inc\db_config.php): failed to open stream: No such file or directory in D:\www\domain\pcp2\conversion\addBooking.php on line 5
Fatal error: require(): Failed opening required '\pcp2\inc\db_config.php' (include_path='.;.\includes;.\pear') in D:\www\domain\pcp2\conversion\addBooking.php on line 5
Line 5 contains the following info:
require($_SERVER['DOCUMENT_ROOT']."\pcp2\inc\db_config.php");

It's failing becasue $_SERVER['DOCUMENT_ROOT'] is a value provided by the web server, and is thus undefined when run without a web server (i.e., from the command line.) You'll need to provide an alternative mechanism to set the base directory.
You might use relative paths:
require("pcp2\inc\db_config.php");
Or absolute paths based on the magic constant __DIR__. (This assumes the script doing the require'ing is in the document root directory.)
require(__DIR__."\pcp2\inc\db_config.php");
Ideally however, you're better off using PSR-4 namespacing with an autoloader.

Related

My dynamic site is not loading when the site is online but works well in localhost

I'm getting this error when my site is online
[host www.sitename.com] Backend fatal error: PHP Fatal error: require_once() [function.require]: Failed opening required 'admin/config/connection.php' (include_path='.:/opt/cpanel/ea-php53/root/usr/share/pear:/opt/cpanel/ea-php53/root/usr/share/php') in /home/mistrybu/public_html/index.php on line 373\n
The site works well in localhost but when its put online , the dynamic part is not showing.
I changed the php version from php7 to php5 in cpanel. Now the front end is working but the backend is not.
Can someone help me solve this error?
PHP version
Definitely do not go back to PHP5. Keep it to 7. If that means rewriting some of the existing code, so be it, it will make your site more secure and more future proof.
Error Message
Your require_once() method cannot find or access a particular file. This is most probably because:
File missing
The file (connection.php) doesn't exist in the given location (admin/config). Now keep in mind that as the location doesn't start with a /, it's going to be relative to where the require_once() method is being run from.
Since you're running require_once() from:
home/mistrybu/public_html/
it's going to look for the file here:
/home/mistrybu/public_html/admin/config/.
Does that location exist? Does the connection.php reside in the folder?
Folder mismatch
Try adding the following prefix to your path, and see if that makes a difference:
require_once $_SERVER['DOCUMENT_ROOT'].'/admin/config/connection.php';
File errors
Maybe the file exists, but for some reason, gives an error. Try running the following from your command line and see if you get any errors:
php -f admin/config/connection.php

Use php require for local directory

I have recently been trying to add PHPMailer script to my site, following the accepted answer from here:
Send attachments with PHP Mail()?
I have never used a require statment before so I assume I must be doing it wrong, currently testing on my local host version of the site. I have downloaded the entire zip of git (unzipped it) and moved it to the dir my scripts are in.
In my script I added the following line:
require_once(__DIR__.'/PHPMailer-master/class.phpmailer.php');
Which to my understanding was all I needed to do to use it. However I get this error:
Warning:
require_once(C:\xampp\htdocs\Website\PHPMailer-master\class.phpmailer.php):
failed to open stream: No such file or directory in
C:\xampp\htdocs\Website\include\mailer.php on line 10
Fatal error: require_once(): Failed opening required
'C:\xampp\htdocs\Website\PHPMailer-master\class.phpmailer.php'
(include_path='C:\xampp\php\PEAR') in
C:\xampp\htdocs\Website\include\mailer.php on line 10
Any ideas what is causing this error? Am running PHP 5.6.21 if this is relevant.
Try to use the full path to the file, using realpath() - http://php.net/realpath, and use dirname(__FILE__) to get your current directory:

Error during composer update/install upon migrating to remote server

The error in question:
[RuntimeException]
Error Output: PHP Warning: require(/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php): failed to open stream: N
o such file or directory in /home/admin/web/"webpage"/public_html/test/vendor/composer/autoload_real.php on line 58
PHP Stack trace:
PHP 1. {main}() /home/admin/web/"webpage"/public_html/test/artisan:0
PHP 2. require() /home/admin/web/"webpage"/public_html/test/artisan:16
PHP 3. require() /home/admin/web/"webpage"/public_html/test/bootstrap/autoload.php:17
PHP 4. ComposerAutoloaderInit95cd02d44d232a8b8d6e5e52544d8647::getLoader() /home/admin/web/"webpage"/public_html/test/vendor
/autoload.php:7
PHP 5. composerRequire95cd02d44d232a8b8d6e5e52544d8647() /home/admin/web/"webpage"/public_html/test/vendor/composer/autoload
_real.php:49
PHP Fatal error: require(): Failed opening required '/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php' (includ
e_path='/home/admin/web/"webpage"/public_html/test/vendor/phpunit/php-text-template:/home/admin/web/"webpage"/pub
lic_html/test/vendor/phpunit/php-timer:.:/usr/share/pear:/usr/share/php') in /home/admin/web/"webpage"/public_html/test/vendor
/composer/autoload_real.php on line 58
PHP Stack trace:
PHP 1. {main}() /home/admin/web/"webpage"/public_html/test/artisan:0
PHP 2. require() /home/admin/web/"webpage"/public_html/test/artisan:16
PHP 3. require() /home/admin/web/"webpage"/public_html/test/bootstrap/autoload.php:17
PHP 4. ComposerAutoloaderInit95cd02d44d232a8b8d6e5e52544d8647::getLoader() /home/admin/web/"webpage"/public_html/test/vendor
/autoload.php:7
PHP 5. composerRequire95cd02d44d232a8b8d6e5e52544d8647() /home/admin/web/"webpage"/public_html/test/vendor/composer/autoload
_real.php:49
Background: Was developing locally, got to the point where I wanted to have a staging site. Set up the staging site on digital ocean (entOS 6.5 x64). I then cloned my git repo into my desired folder - configured vhosts DefaultDirectory to my public path.
A default installation works, composer update/install works. However, with my cloned repository I am getting said error. '/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php' is a file I made with some helper methods I could use in various controllers. It has not caused any problems locally. I can composer update/install locally, without any problems.
Any guidance would be greatly appreciated!
Are those literal quotation marks in your file path
/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php
Or are you just using that to indicate your website name normally goes there? If the former, I'd consider not doing that as it's pretty weird to have quotes in unix file names, and you may run into problems based on assumptions other people have made.
Regardless -- you have the information you need
[RuntimeException] Error Output: PHP Warning: require(/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php): failed to open stream: N o such file or directory in /home/admin/web/"webpage"/public_html/test/vendor/composer/autoload_real.php
PHP is telling you it tried to require in a specific file
/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php
but it could not find it ("failed to open stream"). This means either the file doesn't exist on the computer you're trying to load it from, or PHP can't see it for some reason (try dumping the results of is_readable('/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php'); to see if PHP thinks it can read the file or not.

include path error in the cron job in php

i have the functionality to generate XML file on each day using php.
This works fine in the browser.but it doesn't work in the cron job.
The cron give me error for the required once and Fatal error.And it stops the execution of my cron job.
the included file is also including other files.
the error which i am getting is like,
Warning: require_once(/common/configs/config_local.inc.php) [function.require-once]: failed to open stream: No such file or directory in /home/wwwsite/public_html/sitename/common/configs/config.inc.php on line 281
Fatal error: require_once() [function.require]: Failed opening required '/common/configs/config_local.inc.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/wwwsite/public_html/sitename/common/configs/config.inc.php on line 281
any one having solution to this issue?
It's telling you it can't find '/common/configs/...' note the absolute path there with the first character being a '/'.
You can either make it a relative path from where you are defining it, or put the prefix in there as well ('/home/wwwsite/public_html/sitename/'), maybe with a variable ($sitebase ='/home/wwwsite/public_html/sitename/';) and prefix the include filename with it.
The reason it is working on a website, but not on the command line could be one of a few ways. Most obvious is that the php.ini include_path for the CLI (command line interface) doesn't include the '.' for checking from the current directory. There's also a good reason it doesn't have it by default. The other way is maybe your code puts the ..../sitename/ directory into the include_path - or otherwise sets up the files to be included automatically.
i have got the solution,
curl yoursitename/yourfilename.php > /dev/null 2>&1
This has run my cron job as i have set without any error

Error while trying to use dynamic require links in php

I am trying to use the code require $_SERVER['DOCUMENT_ROOT'].'/resources/mysql.php'; to include the file /resources/mysql.php (relative to root).
On my computer this works, and there are no problems, however my website users have complained that EVERY page except the root (/index.php) fails to load with the error
Fatal error: require() [function.require]: Failed opening required '/home/website/public_html/resources/mysql.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/website/public_html/website/events/index.php on line 2
Why is this failing only on some computers. I have tried to replicate the problem on my computer and even after clearing my browser and DNS cache I cannot get this error to occur. What am I doing wrong and is there a better way to dynamically include php files?
This looks weird that you can access the website but some people not.
You could use ( if you are in php > 5.3 ):
__DIR__
You could also use:
dirname(__FILE__);
Be aware that DOCUMENT_ROOT is not available ( i think ) when you are running your script through CLI

Categories