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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hernst42Commented:
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
phperAuthor Commented:
But adding:
chdir(dirname(__FILE__));
to the top of file.phph did work!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java App Servers

From novice to tech pro — start learning today.