Topic on Project:Support desk

Jump to navigation Jump to search

Starting with 1.31. I get "This script must be run from the command line" when I run a php-scripts via ssh

9
Summary by MarkAHershberger
Michael.seitz (talkcontribs)

Hallo,

This is my setting:

Software     Version

MediaWiki     1.31.1

PHP     7.2.10 (cgi-fcgi)

MySQL     5.6.42-log

ICU     49.1.2

My webhoster is Strato. I use putty for the ssh access.

Up to Mediawiki 1.30 it is no problem to run php-scripts like runJobs.php from the command line with ssh/putty. Starting with Mediawiki 1.31 I get the error message "This script must be run from the command line".

I compared Maintenance.php from 1.30 and 1.31 and noticed that the code has changed:

1.30 line 642 - 645:

       # Abort if called from a web server

       if ( isset( $_SERVER ) && isset( $_SERVER['REQUEST_METHOD'] ) ) {

           $this->error( 'This script must be run from the command line', true );

       }

       

1.31 line line 690 - 694:

       # Abort if called from a web server

       # wfIsCLI() is not available yet

       if ( PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ) {

           $this->fatalError( 'This script must be run from the command line' );

       }

       

I disabled this part of the code in the 1.31 version of Maintenance.php and everything works fine. The php-scripts run as expected.

This is a temporary solution, but how can it be solved without disabling this part of the code?

MarkAHershberger (talkcontribs)
Michael.seitz (talkcontribs)

Thank's a lot.!

As far as I understand your reply developers will work on this issue.

If there is a patch I can test, I am quite willing to do it.

Legoktm (talkcontribs)

Can you run eval.php and tell us what the value of PHP_SAPI is (echo PHP_SAPI;)?

That would help a lot in figuring out what's wrong.

Michael.seitz (talkcontribs)

I used my Maintenance.php without the code on lines 690 - 694 (otherwise I would get "This script must be run from the command line").

In the maintenance directory I typed "php eval.php" on the command line -> the cursor moved to a new line. No prompt etc. was visible.

I typed "echo PHP_SAPI;" and I didn't see anything on the screen, but when I pressed enter, I got the following result:

X-Powered-By: PHP/7.2.10

Content-type: text/html

cgi-fcgi

I had to press CTRL-C to abort the script.

Legoktm (talkcontribs)

Thanks. So for some reason it seems that running php is actually starting up the fcgi version of PHP, which is pretty wrong. Does php-cli whateverscript.php work? I found https://github.com/owncloud/core/issues/15054 which is on the same hosting provider as yours. I would also suggest filing a support ticket with your hoster asking how they want you to run command-line PHP scripts.

Michael.seitz (talkcontribs)

Sorry, I was quite busy and I couldn't answer earlier.

I tried php-cli showJobs.php and php-cli runJobs.php and got the message "php-cli: Command not found." Does this give any further information concerning what I should write to my provider?

MarkAHershberger (talkcontribs)

It looks like there is no php-cli command. Have you contacted your hosting provider yet?

Michael.seitz (talkcontribs)

Not yet. I am rather busy right now. I hope I get a chance in the middle of next week..

Reply to "Starting with 1.31. I get "This script must be run from the command line" when I run a php-scripts via ssh"