Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vernancheta25's avatar

How to run node script using task scheduler

Hello! I'm trying to use the task scheduler to run a node script that creates the sitemap of the site:

$schedule->exec('/usr/bin/node /home/site/site/current/create-sitemap.js')->daily('06:35');

The only problem is that it doesn't seem to be getting called. Though I can execute it manually when I login via ssh.

Is this a problem with the www-data user not having permission to execute node? how can I solve it? I also checked php.ini and I haven't excluded the exec function. Node was installed via Ubuntu PPA.

I know that the task scheduler works because I tried with a test command which logs something into the logger and it worked:

$schedule->command('test:command')->dailyAt('07:02');

I also tried other variants:

$schedule->exec('node create-sitemap.js')->daily('07:02');
$schedule->exec('/usr/bin/node create-sitemap.js')->daily('07:02');

but none of them seems to work. Any ideas what I could be missing? Thanks in advance.

0 likes
1 reply
Sinnbeck's avatar

You can try running the command as the www-data user on the server manually to see if it works

sudo -u www-data /usr/bin/node /home/site/site/current/create-sitemap.js

Please or to participate in this conversation.