Plesk CRON permission

I have a page that adds items to a DB table and creates a new txt file with those items. It works fine when I run it manually but when it runs as a CRON in Plesk I get

PHP Warning: fopen(file.txt): failed to open stream: Permission denied
PHP Warning: fwrite(): supplied argument is not a valid stream resource

the cron is running under the domain in Plesk, not the Server and the syntax is:

/usr/bin/php -f /var/www/vhosts/*.com/subdomains/dev/httpdocs/crons/file.php

When the cron runs and gets the errors it still adds the items to the DB table but, obviously, doesn't creates the txt file.

I added the cron to a site using cpanel and it worked fine. Could it be a plesk user problem? I tried running the cron under apache in plesk and still get the same error. Tried running it as user root in SSH and still nothing.

Also, the file and folder are set to 777
phperAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
phperConnect With a Mentor Author Commented:
But adding:
chdir(dirname(__FILE__));
to the top of file.phph did work!
0
 
hernst42Connect With a Mentor Commented:
try adding a
chdir(basename(__FILE__));
in file.php

When script are run via cli the directory is not changed to where the script is layed and thus file.txt would be created in another directory and not in /var/www/vhosts/*.com/subdomains/dev/httpdocs/crons/
0
 
phperAuthor Commented:
I added:
chdir(basename(__FILE__));

exactly like that and the CRON report returns:
PHP Warning:  chdir(): No such file or directory (errno 2)

as well as the original error.
0
 
firehazrdCommented:
Can you try executing it with lynx or wget?
0
All Courses

From novice to tech pro — start learning today.