Cannot run php in linux

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wtnyan
Forum Newbie
Posts: 2
Joined: Mon May 29, 2006 12:37 am

Cannot run php in linux

Post 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
wtnyan
Forum Newbie
Posts: 2
Joined: Mon May 29, 2006 12:37 am

Shell Script php

Post 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.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: Cannot run php in linux

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: Cannot run php in linux

Post 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'.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Make sure you CHMOD the file to make it executable too.
Post Reply