# Command line to run php script?



## colin72

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


----------



## lotuseclat79

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


----------



## colin72

lotuseclat79 said:


> 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


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


----------



## lotuseclat79

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


----------



## colin72

lotuseclat79 said:


> 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


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.


----------



## lotuseclat79

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


----------



## colin72

lotuseclat79 said:


> Ask for help at work - it never hurts to ask questions.


Unfortunately, I am at work... at home... by myself. So in a sense, you're my work help Tom!



lotuseclat79 said:


> 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


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)?


----------



## lotuseclat79

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


----------



## colin72

lotuseclat79 said:


> 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


I have a Dell Desktop running Windows XP.

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


----------



## lotuseclat79

Follow the instruction!

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

-- Tom


----------



## colin72

lotuseclat79 said:


> Follow the instruction!
> 
> The instructions for the script then says: what it means.
> 
> -- Tom


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


----------



## lotuseclat79

Try to follow the example.

-- Tom


----------



## colin72

lotuseclat79 said:


> Try to follow the example.
> 
> -- Tom


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.


----------



## lotuseclat79

Good point! Try the Web and Design & Development Forum.

Good luck,

-- Tom


----------

