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
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

phperConnect With a Mentor Author Commented:
But adding:
to the top of file.phph did work!
hernst42Connect With a Mentor Commented:
try adding a
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/
phperAuthor Commented:
I added:

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

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

From novice to tech pro — start learning today.