Page 1 of 1

Cannot run php in linux

Posted: Mon May 29, 2006 12:55 am
by wtnyan
Dear PHP guru(s)

I have a problem of running php in linux. I wrote a php program and currently running in the webbrowser. I would like to automate this program using crontab. I configure crontab using root user.

0 23 * * * /var/www/html/modules/autoemail_events.php >/dev/null

Although I can run successfully in webbrowser, it can't run in unix. There a lot of problem occur while running.
So I create another php program, which only has two lines.
<?
$myname="crontab_test";
echo $myname;
?>

error occurs

command not found
./wtnyan.php: line 1: =crontab_test: command not found

I dont know why. I run ./wtnyan.php in the linux shell also the same problem.
Please kindly help me. Thanks

Shell Script php

Posted: Mon May 29, 2006 1:47 am
by wtnyan
Hi all

I managed to find out how to make shell script PHP.

In PHP file
Just add #!/usr/local/bin/php -q

In crontab

0 23 * * * php /var/www/html/modules/satanet/autoemail_events.php >/dev/null

Below is the information site.
http://www.phpbuilder.com/columns/darrell20000319.php3

Thanks all.

Re: Cannot run php in linux

Posted: Mon May 29, 2006 2:27 am
by jmut
wtnyan wrote:Dear PHP guru(s)

I have a problem of running php in linux. I wrote a php program and currently running in the webbrowser. I would like to automate this program using crontab. I configure crontab using root user.

0 23 * * * /var/www/html/modules/autoemail_events.php >/dev/null

Although I can run successfully in webbrowser, it can't run in unix. There a lot of problem occur while running.
So I create another php program, which only has two lines.
<?
$myname="crontab_test";
echo $myname;
?>

error occurs

command not found
./wtnyan.php: line 1: =crontab_test: command not found

I dont know why. I run ./wtnyan.php in the linux shell also the same problem.
Please kindly help me. Thanks

You could also directly run the script using

0 23 * * * /usr/bin/php /var/www/html/modules/autoemail_events.php >/dev/null

without specifying within the script which interpreter to run it.

Re: Cannot run php in linux

Posted: Mon May 29, 2006 4:15 am
by timvw
wtnyan wrote: Although I can run successfully in webbrowser, it can't run in unix. There a lot of problem occur while running.
So I create another php program, which only has two lines.
<?
$myname="crontab_test";
echo $myname;
?>

command not found
./wtnyan.php: line 1: =crontab_test: command not found
Search the web for 'she-bang' lines. If you want to launch a program like this, the first line has to be the path to the program/interpreter you want to use for the file...

Eg:

Code: Select all

#!/usr/bin/php
<?php 
echo 'Hello World';
?>
Or instead of adding this line, type /usr/bin/php /path/to/script.php

If you don't know the actual path to your php interpreter, you can find it with the command 'which php'.

Posted: Mon May 29, 2006 5:08 am
by Chris Corbyn
Make sure you CHMOD the file to make it executable too.