0

My Problem is that I cannot get my PHP Script to run from the command line. In this example I am trying to run Script allinone.php

I am relatively new to programming and have set up a Virtual Server. I have WHM, CPANEL . It is a Centos 6.5

I have saved my PHP Script in the CPANEL under home/higheryieldco/public_html/allinone.php

I can run the Script through the browser.

I can also (through the CRON CPANEL Icon) run this as a CRON job. The path is as below:-

/usr/bin/php -q/home/higheryieldco/public_html/allinone.php

I have gone into the command line for user higheryieldco through PUTTY.

When I type whereis PHP into the command line I get .....

PHP :/usr/bin/php /usr/lib/php.ini /usr/local/bin/php /usr/local/lib/php.ini etc

At the prompt have tried typing:-

   php allinone.php

But all I get is .........Could not open input file : allinone.php

If I type the following:

   #!/usr/bin/php
   <?php echo"hello world"; ?>

I get................- bash : syntax error near unexpected token 'newline'

My aim is to run allinone.php from the command line but I can't make it work. Have I got the script saved in the wrong place for a command line activation? How and where would I save it?

Thanks for any help

I have been trying to follow this answer to no result: Where to start with running a command line in PHP with CPanel hosting

Community
  • 1
  • 1
user2635961
  • 379
  • 3
  • 19
  • Have you tried sudo php .... – EternalHour Aug 11 '14 at 06:20
  • 1
    Okay, let's get down to complete basics and build up from there. Get to your command-line. Type `php --version` and hit return. Do you get a response telling your your PHP version? Now try `/usr/bin/php --version`. Do you get the same thing? – Matt Gibson Aug 11 '14 at 06:24
  • Hi Matt - php --version gives PHP 5.4.31 (cli) with built and copyright info. /usr/bin/php --version gives PHP 5.4.31 (cgi-fcgi) – user2635961 Aug 11 '14 at 06:29
  • Hi Eternal Hour - when I type sudo php it asks me for a password and then says that my user is not in the sudoers file – user2635961 Aug 11 '14 at 06:52
  • Hi Matt - My virtual server is 64 bit and I wonder if the PHP version currently loaded is only 32 bit. Is there a way of checking release versions of PHP? – user2635961 Aug 11 '14 at 07:01
  • 1
    Let's not worry about that yet. You have a working version of PHP, at least. Now try `/usr/bin/php /home/higheryieldco/public_html/allinone.php` from the command line, and see if it seems to successfully run your script. If it works, try `/usr/bin/php -q /home/higheryieldco/public_html/allinone.php`. Note the difference between the version in your post: there's a space between the `-q` and the path to the script. – Matt Gibson Aug 11 '14 at 07:17
  • Hi Matt. Sorry for the delay in coming back to you. When I try the first one it just comes back as **-bash /usr/bin......etc : Not a Directory** – user2635961 Aug 11 '14 at 18:27
  • Hi Matt - just tried the second way you suggested with the -q and that works!! Thats fantastic. Is there any way of making that a smaller path? Thanks for your help – user2635961 Aug 11 '14 at 18:38
  • PS Matt. Is there any where I can give you a tick up for your assistance? – user2635961 Aug 12 '14 at 06:37

0 Answers0