1

I have a PHP file that sends email.

Now what I need is for this PHP file to send email every hour. I tried Cron with Linux (Ubuntu).

I have the line:

0 * * * * /var/etc/apache2/php(source of the php.ini file) /var/www/name_of_folder/mailer.php

But it is not working.

Can anyone help me? I'm new with Cron jobs.

2 Answers 2

2

You need to use the php binary, not a configuration file. The default location of the PHP command line binary on ubuntu is /usr/bin/php, so try this:

0 * * * * /usr/bin/php /var/www/name_of_folder/mailer.php

If you don't have a PHP binary (you can find out the location with which php) you may have to install the CLI package

sudo apt-get install php5-cli
Sign up to request clarification or add additional context in comments.

9 Comments

I'm tryin it tough i didn't see any php binary in the /usr/bin :(
I think PHP should be in the PATH on ubuntu, so unless you've compiled a specific version of php to run with this script, i think you could just use 0 * * * * php /var/www/name_of_folder/mailer.php
@RaggaMuffin-420 never assume that the cron daemon has the same PATH (or other environment variables) as your user.
But the ubuntu server can already run php files. do i still need to install another one?
If you want to run PHP scripts from the command line, as crond does, you need the command line interface. You can't use the apache module for this.
|
0

Providing this script is only for CLI/cron purposes

Find out where your PHP binary is using which php

copy the output.

At the start of your mailer.php script add a shebang: #!/path/to/php

chmod your mailer.php to 755

then you don't need to use the php binary in the crontab, just the path to the mailer.php script:

0 * * * * /var/www/name_of_folder/mailer.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.