Localhost vs CMD Line

All,

I have php working in the browser and localhost but cannot get it working on the cmdline.

I’m not finding much help or HOWTOs on this as all resources I’m finding assume that if browser and localhost are working then the cmd line should also be working!

All help appreciated!

Cheers!

TBNK

What do you mean “command” line? PHP is a server system. PHP is not designed to run in the command line. You can run PHP programs, but they are not easy since they need to create output such as sending to a database or output file. But, you can do it like this:

php /path/to/script/index.php

If you are using Wamp it would be " php /wamp64/www/yourfolder/yourfile.php "

Couple of questions.

What OS are you running?

What doe you get on the command line from the following command?

php --version

skawid,

Only run Kubuntu Linux LTS versions. Have 14.04, 16.04 and 18.04 installed. Current issue is on the 18,04 server.

All the other commenters showed their ignorance by not knowing PHP was only designed to run on Linux and was originally only command line executable. Adaption to browsers, via Apache and MS Windows (WAMP etc.) came later as PHP’s versatility became obvious and is now the predominate web language, especially since it is the only “LEGAL” processing language on the internet.

All y’all thinking you know something, need to check your facts first!

TBNK

TNNK, without knowing your system setup, we have no idea how to help you. And, PHP is an open source system and it is ALL legal no matter which version. Check your facts!

Now that we know you are on a Linux system, here is a simple tutorial on how to run PHP from the command line: https://www.tecmint.com/run-php-codes-from-linux-commandline/

What are you referring to?

EA,

You are the one lacking and not checking facts! The IISC controls 100% of all electronic exchange, including the internet and they outlawed all other languages for the internet, with PHP only getting approval because it is 100% server side processing.

OpenSource does not get a pass at all!

Know your facts before you “Open mout and insert foot!”

And do not ever make this a discussion about legalities!

If you have Qs for the IISC email them at:

[email protected]

Cheers!

TBNK

Sorry, TBotNik, you are talking about India only. That does not have anything to do with the world.
You are ranting over something that we were NOT discussing. This thread has nothing to do with
IISC. ( Which is not world wide and nothing to do with this site! ) It was about running a command line command.

EA,

Thanks! But the link you sent is one I have already used and like I stated assumes PHP cmd line is working if the interpretation in the browser is working.

PHP is installed and is version:

PHP 7.2.24-0ubuntu0.18.04.7 (cli)

notice it says “(cli)” which is “command line interface”.

but always errors with:

Could not open input file:

So the right HOWTO will show this exact error and how to correct it!

The HOWTO at:

That I’m currently reading seems to be the closest to actually addressing and possibly fixing the problem.

I’m sure the lack of information on this is due to the base install working well enough for this problem being quite rare!

Cheers!

TBNK

Well, for Ubuntu, it says to run from the command line, you do this:

You just follow the steps to run PHP program using command line.

  1. Open terminal or command line window.
  2. Goto the specified folder or directory where php files are present.
  3. Then we can run php code using the following command: php file_name.php.

I would think it should work if you have a standard installation of Ubuntu and PHP

EA,

Not working at all, even tried the php-cgi cmd and still erroring. Also did a re-intall and edited the php.ini file, but no change!

Gonna see if any of the gurus on freenode dot net #php have any ideas on this!

TBNK

EA,

No + reply from the freenode gurus, so guess my only option is to purge the entire LAMP stack, including PfSQL and then re-install.

Guessing this scenario is so rare that is why there are no actual HOWTOs on this issue!

I’ll try posting on other PHP help forums first before doing the drastic!

Cheers!

Okay, but, if you open a command prompt and move it to the folder where the PHP program is.
Then, enter PHP program-name.php You get an error. What is the exact error that is displayed?

Another question, is your Ubuntu CLI server started? PHP -S ???

What happens if you try and run PHP without specifying an input file? You can use:

php --version

to just get version information, or:

php -a

to open an interactive prompt. What output do these commands give?

Um, IISC doesn’t control 100% of anything first off. Second off, a GMAIL account, really? So they must be at the top of the IT spectrum!!!

Anyway, PHP has different config files that are used for browser and CLI. You haven’t really given any information as to what you are trying to fix or what you have issues with. Code? Errors? Anything that you want to provide that people can actually help with?

EA,

What I;ve recently found is Ubuntu is at fault. Don’t know why yet, but a recent update they sent canceled PHP cmd line on all my machine, so will be posting on their board to find the fix. Will post the fix here once I have it!

TBNK

EA,

There are people that totally disagree with you point of view that say PHP is designed to only run from the command line, and if you are certifying on PHP you will fail this question in the Level 1 of 6 cert levels, Need to fully understand PHP before making such comments.

Oh Level 6 is certifying in “Compiled PHP” which from your comment sure you did not realized PHP is compilable!

Cheers!

TBNK

Kubuntu 18.04 LTS with server extensions.

php --version:
PHP 7.2.24-0ubuntu0.18.04.10 (cli) (built: Oct 25 2021 17:47:59) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.24-0ubuntu0.18.04.10, Copyright (c) 1999-2018, by Zend Technologies

Cheers!

TBNK

EA,

So since your exposure to PHP is on Windows instead of a “Real Operating System” you are developing without phpseclib installed so all your code is not secure.

Cheers!

TBNK

Sponsor our Newsletter | Privacy Policy | Terms of Service