Oktarin
Oktarin

Reputation: 77

PHP script via cron is not finding files called in the code

I want to run php script that is located on server at:

/var/www/my_directory/myfile.php

Script executes one function that uses certificate files located at:

/var/www/my_directory/my_cert_dir/cert_file.pem

inside PHP script they look like this:

$key="my_cert_dir/cert_file.pem";

I have also tried to add $_SERVER["DOCUMENT_ROOT"]:

$key=$_SERVER["DOCUMENT_ROOT"]."/my_cert_dir/cert_file.pem";

In both cases I get "file not found" for my certificate files. However, when run through CLI or browser they execute without problems.

First I used cron like this:

13 19 * * * /usr/bin/php /var/www/my_directory/myfile.php >> /var/www/my_directory/my_logs_dir/some_log.txt

And cron executed the script and I got errors, so I tried to change cron to execute from directory like this:

13 19 * * * cd /var/www/my_directory; /usr/bin/php myfile.php >> /var/www/my_directory/my_logs_dir/some_log.txt

However this time I don't see that script executes and my log is not created.

Any ideas how to fix my issue so that script is executed and cert files are found?

Upvotes: 0

Views: 57

Answers (1)

user2849202
user2849202

Reputation:

Why not try the full path:

$key="/var/www/my_directory/my_cert_dir/cert_file.pem"

Upvotes: 1

Related Questions