1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Command line to run php script?

Discussion in 'Linux and Unix' started by colin72, Mar 27, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. colin72

    colin72 Thread Starter

    Joined:
    Sep 9, 2004
    Messages:
    72
    I need to run PHP script from command line.

    Problem: I have no idea what command line is. I need a step by step, easy to understand, walkthrough to do this. If you can help, assume I know nothing (because you would be correct).

    The beginning instructions for the script are:
    "This script can only be run in command line (PHP CLI- not web based) so you must have shell access to a linux server."

    I am told I have "jailed shell access" (my server space is with Hostgator). Is that ok to run this script with?

    Thanks
    colin72
     
  2. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Hi colin72,

    Login to your shell account on the server (wrt Hostgator). Give your username and password.

    That should bring you to a prompt which I will assume is $ below.
    Let's say your script.php is located at: /home/colin72/bin/script.php
    Then all you would need to type in after the prompt to run your script.php would be:

    $ php -q /home/colin72/bin/script.php<Enter>
    where <Enter> means hit the Enter key.

    -- Tom
     
  3. colin72

    colin72 Thread Starter

    Joined:
    Sep 9, 2004
    Messages:
    72

    Hey Tom

    I can not get the script you were helping me with in the other thread to work. No matter how I try and set up the folders, etc, nothing works. So while I am still trying to get that script to work, I was given a different script (which, of course, I have no idea hwo to get it to work).

    This new one involves executing the PHP script from command line (which you had mention ed pin the other thread).

    I have no idea how to log into my shell account with Hostgator. I don't know where the log in is. When I signed up with Hostgator, they gave me acccess to my account with Cpanel (which I've never heard of before).

    This screenshot shows where I log into Cpanel:
    http://img220.imageshack.us/my.php?image=cpanelloginnn0.jpg

    These two screenshots show Cpanel after I've logged in:
    http://img231.imageshack.us/my.php?image=cpanel1jk9.jpg
    http://img231.imageshack.us/my.php?image=cpanel2ga3.jpg

    So I have no idea where the "command line" is to get access to the shell. All of these terms are completely new to me.

    Thanks
     
  4. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Hi colin72,

    Hostgator does not give you a command line interface, instead, they give you a GUI interface, not a command line interface.

    Have you clicked on the Getting Started and Video Tutorial icons (images) in the first screen shot? If not, that is how you will learn about what you have to do.

    In the second screen shot, I see that there are icons for FTP Manager and File Manager. Use the File Manager to navigate and probably mkdir or whatever functionality they give you to create a folder/directory and file. Use the FTP Manager to upload your script to a folder/directory and remember the path name /.../.../.../script.php where you uploaded your script.php. Then, if the script.php is executable, just double-click on the script.php to execute it.

    Also, I see in the 3rd screen shot there is a Cron Jobs icon (image). Looks like you have to use that to setup a cron job for wherever you place (upload) your script.php.

    With the limited environment they gave you - trust me - they are protecting you from yourself in terms of - if you had a command line interface and don't know what you are doing - the your could cause lots of problems. So, get used to using and learning the interfaces they have given you by experimenting with them. Write a little script that says "Hello, World!" and exits. Upload it to a folder/directory path you create in your account. Execute it by double-clicking on it after making it executable, or entering the command: php -q <pathtoscript>/script.php where <pathtoscript> is the set of folders from the top, i.e. /, to the script through the subfolders, e.g. /home/colin72/bin, or wherever you have access to and can place your script.

    -- Tom
     
  5. colin72

    colin72 Thread Starter

    Joined:
    Sep 9, 2004
    Messages:
    72
    As I said in my first post...

    The beginning instructions for the script are:
    "This script can only be run in command line (PHP CLI- not web based) so you must have shell access to a linux server."

    Unlike the script I asked about in the other thread. This one can only be run from command line.

    I'm probably close to giving up on both of these scripts. I've been trying to set one or the other up for over a week. I think it's impossible.
     
  6. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Ask for help at work - it never hurts to ask questions.

    If you have never before worked in a command line environment, whomever is tasking you to do that without adequate training is clueless. Ask for training in Unix/Linux Command Line tutorial to do the work you need to do.

    Google for: Linux +Unix +command line +tutorial
    and teach yourself by doing the reading and asking questions like you have here, or ask them for the training or someone experienced where you work to train you.

    -- Tom
     
  7. colin72

    colin72 Thread Starter

    Joined:
    Sep 9, 2004
    Messages:
    72
    Unfortunately, I am at work... at home... by myself. So in a sense, you're my work help Tom!



    I actually think I have the command line figured out. I didn't realize I needed software to access the shell. I downloaded and set up "Putty". I entered my IP, port, then my Hostgator username and password and connected to the server.

    I have three php files to put on my server and then I'm given these instructions...
    Type:
    php -n turboregister3.php [domainname] [delay in microseconds, 1000000 = 1 second]


    The instructions give an example...
    To catch domain.com with 0.5 sec delay, type :
    screen -A -m -d -S domain.com php -n turboregister3.php domain.com 500000


    The instructions for the script then says:
    You must create a new screen instance for another domain name, if you want to catch more than 1 domain


    So, can you tell me how to I create a new screen instance in Putty for another domain (since I will want to catch more than one domain at a time)?
     
  8. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Refer to Domain Name for domain name information.

    You simply have to bring up another pUTTY session in another Terminal window.

    What OS are you using?

    -- Tom
     
  9. colin72

    colin72 Thread Starter

    Joined:
    Sep 9, 2004
    Messages:
    72
    I have a Dell Desktop running Windows XP.


    In the example instructions above, what does this first part mean "screen -A -m -d -S"
     
  10. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Follow the instruction!

    The instructions for the script then says: what it means.

    -- Tom
     
  11. colin72

    colin72 Thread Starter

    Joined:
    Sep 9, 2004
    Messages:
    72
    The reason I asked what is means is because the instructions say...

    Type:
    php -n turboregister3.php [domainname] [delay in microseconds, 1000000 = 1 second]

    And then the instructions gives this example which, to me, is different from the above...

    To catch domain.com with 0.5 sec delay, type :
    screen -A -m -d -S domain.com php -n turboregister3.php domain.com 500000

    So why does it first tell me to type one thing and then gives an example where it tells me to add "screen -A -m -d -S doamain.com" to the beginning of the command?

    For example...

    If I wanted to the script to catch tom.com, the first instructions say to type:
    php -n turboregister3.php tom.com 1000000

    But then in the example it says to type:
    screen -A -m -d -S tom.com php -n turboregister3.php tom.com 500000
     
  12. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Try to follow the example.

    -- Tom
     
  13. colin72

    colin72 Thread Starter

    Joined:
    Sep 9, 2004
    Messages:
    72

    Yes, I did. I didn't work. That is why I'm asking.

    So I assume you don't know what the code says or why the first instructions differ from the example? Maybe I need to ask someone that understands php.
     
  14. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Good point! Try the Web and Design & Development Forum.

    Good luck,

    -- Tom
     
  15. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/697594

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice