Im trying to create cronjob from php, I added it to crotanb:
sudo crontab -u www-data -l:
*/1 * * * * /usr/bin/php /var/www/html/service_script/cronTest.php
cronTest.php
<?php
echo 'it works';
include_once('../core/external_init.php');
And this is the output:
it works
PHP Warning: include_once(../core/external_init.php): failed to open stream: No such file or directory in /var/www/html/service_script/cronTest.php on line 3
PHP Warning: include_once(): Failed opening '../core/external_init.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/service_script/cronTest.php on line 3
PHP Fatal error: Uncaught Error: Class 'pluginClassManagement' not found in /var/www/html/service_script/cronTest.php:6
Stack trace:
#0 {main}
thrown in /var/www/html/service_script/cronTest.php on line 6
This cronTest.php works when I run it from browser.
If I change /usr/bin/php to /usr/lib/php I get this error instead:
/bin/sh: 1: /usr/lib/php: Permission denied
I dont really know what path should be here.
I have php7, i tried all kinds of thing to make this work, setting rights, make the script executable etc but now Im stuck on this and dont know what to do anymore
Try it with an absolute include path (like /var/www/path/to/core/external_init.php). I'm pretty sure, it uses the wrong working directory when run as cron.
Related
I don't know about cron jobs and I am trying to set them in my cPanel, so I have 2 php files I am trying to run:
covid-19_data.php
And utilities.php
on cPanel I run:
/usr/local/bin/php -q -f /public_html/wp-content/themes/siteName/scripts/data/shared/utilities.php
And
/usr/local/bin/php /home/siteName/public_html/wp-content/themes/siteName/scripts/covid-19_data.php
But i keep receiving:
Could not open input file: /public_html/wp-content/themes/siteName/scripts/data/shared/utilities.php
And
Warning: include_once(../shared/utilities.php): failed to open stream: No such file or directory in /home1/siteName/public_html/wp-content/themes/siteName/scripts/covid-19_data.php on line 3
Warning: include_once(): Failed opening '../shared/utilities.php' for inclusion (include_path='.:/opt/php56/lib/php') in /home1/siteName/public_html/wp-content/themes/siteName/scripts/covid-19_data.php on line 3
Warning: chdir(): No such file or directory (errno 2) in /home1/siteName/public_html/wp-content/themes/siteName/scripts/covid-19_data.php on line 12
Fatal error: Call to undefined function downloadFile() in /home1/siteName/public_html/wp-content/themes/siteName/scripts/covid-19_data.php on line 16
I tried running utilities.php every minute and covid-19_data.php every two minutes but doesn't work.
When I need to make it work, I only manually run via the browser wwww... covid-19_data.php and works fine, I don't need to run utilities.php I only made it run to try if that was the issue.
It sounds like your host runs cron jobs as nobody, or some other user that does not have access to the files in your account. Try changing the permissions of covid-19_data.php to allow "other" to read/execute it:
chmod o+rx /home/siteName/public_html/wp-content/themes/siteName/scripts/covid-19_data.php
Trying to run php tests with python script.
Using codeception framework, which is successfully works when i'm executing it manually in terminal. But it generates permission issues when i'm trying to call it with subprocess.call like that
subprocess.call(['vendor/bin/codecept', 'run'])
Errors like
PHP Warning: require_once(/root/opt/testing/vendor/bin/autoload.php): failed to open stream: Permission denied in /root/opt/testing/vendor/bin/codecept on line 7
PHP Fatal error: require_once(): Failed opening required '/root/opt/testing/vendor/bin/autoload.php' (include_path='.:/usr/share/php') in /root/opt/testing/vendor/bin/codecept on line 7
Can't find the reason why. Changed all permissions to chmod a+x but still no results.
Looks like it definitely something with python.
I am trying to run the server but keep getting these messages when running php app/console server:run:
PHP Warning: require(/var/www/html/symfony_demo/app/../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/symfony_demo/app/autoload.php on line 11
PHP Stack trace:
PHP 1. {main}() /var/www/html/symfony_demo/app/console:0
PHP 2. require() /var/www/html/symfony_demo/app/console:17
PHP Fatal error: require(): Failed opening required '/var/www/html/symfony_demo/app/../vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/symfony_demo/app/autoload.php on line 11
PHP Stack trace:
PHP 1. {main}() /var/www/html/symfony_demo/app/console:0
PHP 2. require() /var/www/html/symfony_demo/app/console:17
If I run php bin/console server:run I get this message:
Could not open input file: bin/console
The only change I have made recently was use winSCP to copy my files from the remote server to my local PC. Can someone help me with the errors?
EDIT: Like an idiot I copied over the wrong project.
EDIT: Still didn't fix my issue.
You most likely didn't run composer install or forgot to copy the vendor directory.
I'm trying to run a script using crontab, but I have problems making it work even from the command line. The script runs fine from the browser and it creates some excel files in reports/ folder which is owned by apache. The script file is owned by me: john.
When I try to run the script from the command line, I get the following warnings, and the excel file doesn't create. I've tryed with the full path, but I get the same results.
This is what I got after I try to run the script from command line
public_html]$ php include/tests/mailme.php
PHP Warning: fopen(reports/4-March.xls): failed to open stream: Permission denied in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php on line 90
Warning: fopen(reports/4-March.xls): failed to open stream: Permission denied in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php on line 90
PHP Fatal error: Uncaught exception 'Exception' with message 'Can't open reports/4-March.xls. It may be in use or protected.' in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php:93
Stack trace:
#0 /home/john/public_html/PHPExcel/Writer/Excel5.php(233): PHPExcel_Shared_OLE_PPS_Root->save('reports/...')
#1 /home/john/public_html/include/generate_daily_excel.inc(401): PHPExcel_Writer_Excel5->save('reports/...')
#2 /home/john/public_html/include/tests/mailme.php(41): generateDailyExcel('04-02-2013')
#3 {main}
thrown in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php on line 93
Fatal error: Uncaught exception 'Exception' with message 'Can't open reports/4-March.xls. It may be in use or protected.' in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php:93
Stack trace:
#0 /home/john/public_html/PHPExcel/Writer/Excel5.php(233): PHPExcel_Shared_OLE_PPS_Root->save('reports/...')
#1 /home/john/public_html/include/generate_daily_excel.inc(401): PHPExcel_Writer_Excel5->save('reports/...')
#2 /home/john/public_html/include/tests/mailme.php(41): generateDailyExcel('04-02-2013')
#3 {main}
thrown in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php on line 93
I assume that if I change the owner of reports, the browser version will not be allowed to save. I'm new to linux and rights.
When you run php code from command line. The script runs with your user permission , not with www-data user permissions.
You should run script as root (not recommend) , or instead change the file permissions:
sudo chown yourUser:www-data file
sudo chmod 664 file
And you should do nearly the same with the directory:
sudo chown yourUser:www-data dir
sudo chmod 775 dir
The error is laid out very explicitely for you: "failed to open stream: Permission denied". When you are running this from the command line, you are user "john" (I assume from your home path). Does user "john" have permission to write in the reports directory?
What are the permissions of the actual reports directory?
ls -al /home/john/public_html/reports
I just installed PHP and PEAR on my Mac OSX using MacPorts and then installed PHPUnit using PEAR. When I try to run PHPUnit, I get the following error message:
$ phpunit StackTest.php
PHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
PHP Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/php/includes:/usr/local/php5/lib/php:/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/php/includes:/usr/local/php5/lib/php:/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Okay, so the file File/Iterator/Autoload.php isn't in my include_path, so I tried
$ ls -l /opt/local/lib/php/File/Iterator/Autoload.php
-rw-r--r-- 1 root admin 2682 May 23 14:38 /opt/local/lib/php/File/Iterator/Autoload.php
$ phpunit --include-path /opt/local/lib/php StackTest.php
PHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
PHP Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/php/includes:/usr/local/php5/lib/php:/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/php/includes:/usr/local/php5/lib/php:/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
It's still not working, and the it's not including the new path that it should be. Does anybody know what I can do about this? (I'd rather not modify my php.ini file if I can help it because it's read-only and I'm fairly new to PHP and don't want to mangle it in ways I don't understand.) Thanks.
Still don't have an answer for why --include-path on the command line isn't working, so here's what I did:
$ which phpunit
/opt/local/bin/phpunit
$ sudo emacs /opt/local/bin/phpunit
The plan is to modify the php.ini file, so first I had to figure out which php.ini was initializing phpunit. If anyone has a better way to do this, I'm happy to hear it. I added the following line to the phpunit code right after the <?php opening tag:
echo php_ini_loaded_file();
Now, when I ran phpunit, I got the following (here truncated) output:
/opt/local/etc/php5/php.iniPHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45...
Then:
$ sudo emacs /opt/local/etc/php5/php.ini
I searched for the include_path directive and appended :/opt/local/lib/php to the end. So now, phpunit works, although I have no idea if I broke anything else in terms of my setup.
I had a similar problem with a Windows install, but I am not sure that it is the same problem on OSX. I found the that the PEAR install created the wrong path in the batch file used to launch the program.
The standard install causes the installed batch files to have errors. The final script line of the pear.bat batch file needs to have the include_path wrapped in single quotes ("include_path='%VARIABLE%'").
The change I made is:
"%PHP_PEAR_PHP_BIN%" -C -d memory_limit="-1" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d auto_append_file="" -d variables_order=EGPCS -d open_basedir="" -d output_buffering=1 -d "include_path='%PHP_PEAR_INSTALL_DIR%'" -f "%PHP_PEAR_INSTALL_DIR%\pearcmd.php" -- %1 %2 %3 %4 %5 %6 %7 %8 %9
I am not sure if you have a similar problem to the one above for your install.
Failing that, my batch file for PHPUnit on Windows 7 is
if "%PHPBIN%" == "" set PHPBIN=C:\Program Files (x86)\PHP\php.exe
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "C:\Program Files (x86)\PHP\phpunit" %*
A less invasive way (without changing the php.ini permanently) is to include the following line in the script that fails: set_include_path("/opt/local/lib/php/");
The location you are including might be slightly different. If this doesn't work, search for a file called Autoload.php that is in a folder structure like this: File/Iterator/Autoload.php and use the path to File as the path in set_include_path().