Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you run a php file from ssh?

Tags:

linux

php

ssh

I'm using from ssh:

php filename.php

and works great, but when I do this:

php filename.php?id=2

I get a "could not open input file" error.

any ideas?

like image 455
user962449 Avatar asked Dec 04 '12 17:12

user962449


People also ask

How do you execute a PHP file?

php” file is placed inside the “htdocs” folder. If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.

How do I run a PHP script in putty?

You can use the PHP CLI to run the script. You can write like php filename. php. If the php don't work then check for the actual path of the php.

How do I run PHP on a server?

To run PHP for the web, you need to install a Web Server like Apache and you also need a database server like MySQL. There are various web servers for running PHP programs like WAMP & XAMPP. WAMP server is supported in windows and XAMP is supported in both Windows and Linux.


2 Answers

You can't pass GET variables via the command line!! If you need to pass a variable to your script you can use php filename.php your_variable and use $argv and $argc in your PHP code.

  • http://php.net/manual/es/reserved.variables.argc.php
  • http://php.net/manual/es/reserved.variables.argv.php
like image 187
m4t1t0 Avatar answered Oct 19 '22 12:10

m4t1t0


PHP file's that were written as a website will only be of limited use on CLI.

You could write a wrapper script, that prepares the superglobals and include's the webscript.

I recommend reading about the CLI interface to understand what it does.

like image 1
Cobra_Fast Avatar answered Oct 19 '22 12:10

Cobra_Fast