PHP SDK won't run my php-cgi - php

I'm trying get the helloworld example for the Google Appengine PHP SDK working, but I can't seem to get the dev_appserver to even run. This is the command line I use and the error I get:
$ /opt/google-appengine-php/dev_appserver.py --php_executable_path=/usr/bin/php-cgi src
INFO 2013-06-14 02:50:09,070 sdk_update_checker.py:244] Checking for updates to the SDK.
INFO 2013-06-14 02:50:09,331 sdk_update_checker.py:260] Update check failed: HTTP Error 404: Not Found
INFO 2013-06-14 02:50:09,458 api_server.py:138] Starting API server at: http://localhost:39069
INFO 2013-06-14 02:50:09,647 dispatcher.py:164] Starting server "default" running at: http://localhost:8080
INFO 2013-06-14 02:50:09,650 admin_server.py:117] Starting admin server at: http://localhost:8000
ERROR 2013-06-14 02:50:09,717 php_runtime.py:199] The PHP runtime is not available because: No input file specified.
The output from php-cgi -v is:
PHP 5.4.16 (cgi-fcgi) (built: Jun 7 2013 05:55:42)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
The output from whereis php-cgi is:
php-cgi: /usr/bin/php-cgi
I looked at the php_runtime.py file but I can't even find the string No input file specified so I'm stumped!
Anyone have any idea what the problem is?
EDIT: I just tried running fgrep -r 'No input file specified' * in the App Engine directory and nothing shows up!!!
EDIT 2: It seems the message No input file specified comes from the PHP interpreter, no the App Engine SDK. But I still have no idea why?! the app.yaml and helloworld.php files are in the same directory and are copied from the tutorial page.

It seems the problem is the way I installed my system. My /home directory is actually a symbolic-link to /var/home (I have two partitions: / and /var) but PHP has a directive to limit where it loads files from, open_basedir. By default it includes /home but PHP resolves symlinks so all my files were coming from /var/home and /var (or anything below) are not included.
So the solution is to replace /home with /var/home in the open_basedir directive of my /etc/php/php.ini file.
EDIT: Also, since I installed the AppEngine PHP SDK in /opt/google-appengine-php I had to add that directory to open_basedir too.

Related

Local IIS installation doesn't show phpinfo page

I've installed PHP on my windows 10 computer, and started IIS.
But when I browse to http://localhost/phpinfo.hml the page is completely blank.
And if I look at the file view in IIS, it seems that it's not aware that the file exists.
I've verified that the phpinfo.html file is in the right place:
ls -l C:\inetpub\wwwroot\phpinfo.html
Directory: C:\inetpub\wwwroot
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 7/16/2020 8:54 AM 72 phpinfo.html
And has the right contents:
PS C:\inetpub\wwwroot> cat .\phpinfo.html
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>
PHP is installed:
php --version
PHP 7.4.1 (cli) (built: Dec 17 2019 19:23:59) ( NTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
I gave my windows user full access to that directory. What am I doing wrong? How can I get this working?
If you want to show phpinfo page, you need to change phpinfo.html to phpinfo.php.
And you also need to handle PHP requests by using IIS Manager, you can set this in Handler Mappings.
More information about how to configure IIS to Handle PHP Requests you can refer to this link: Configure IIS to Handle PHP Requests

how to change the php from the default folder to the php 71 folder

this my /usr/local/ folder
this my php version showing`
PHP -v
PHP 5.5.38 (cli) (built: Mar 30 2017 12:11:07)
Copyright (c) 1997-2015 The PHP Group Zend Engine v2.5.0,
Copyright (c) 1998-2015 Zend Technologies`
this is my PATH
echo $PATH
/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
What i want to do is switch to my php72 folder so when i type php -v to show me php 7.2
I have searched a lot and tryed many solutions but it is not working.
any help would be appreciated
Go in the Finder and press ⌘⌥P to turn on the display of the path at the bottom of the screen - no idea why Apple leaves this turned off (rant over).
Now navigate to /usr/local/php5-7.2ORC.... and navigate around in there till you find the executable called php. Note the path at the bottom of the screen when you have that file selected. Remove the word php from the right end of that path, now set your PATH like this:
export PATH=<WHATEVER-YOU_GOT_ABOVE>:$PATH
In essence, you will end up doing something like:
export PATH=/usr/local/php5-7.20ORC.../bin:$PATH

Can't execute a php script without using "php" command before

I need to use a php script without "php" command.
For example:
$ ./test.php
Permissions are sets to 755.
This is the script
#!/usr/bin/php -q
<?php
echo "hello world";
?>
/usr/bin/php -v (so path exists)
returns
PHP 7.0.15-1+deb.sury.org~xenial+1 (cli) (built: Jan 20 2017 08:53:13) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.15-1+deb.sury.org~xenial+1, Copyright (c) 1999-2017, by Zend Technologies
This is the error I'll get everytime:
Exception: Zend Extension ./test.php does not exist
Also calling script with fullpath I'll get same error.
Calling this it works properly
$ php ./test.php
Any idea?
NOTE: The author found the solution and put it up in the comments but never posted an actual answer, so this answer is just clarifying what the author already said above so as to make the answer more obvious.
I was also getting the Exception: Zend Extension does not exist when I was trying to pipe an email via cpanel forwarder into a php script.
I opened the file in my editor (Komodo Edit on Windows) and went to EDIT > CURRENT FILE PREFERENCES and noticed that LINE ENCODINGS was set to DOS/Windows (\r\n)
I changed the LINE ENCODING to UNIX (\n) and saved it and re-uploded it and the error went away and all is good now.
Obviously the steps will vary depending on what editor you use, but the solution is to make sure your Line Encodings are UNIX and not DOS/Windows.
Just run dos2unix on the file
# ./database.php
Exception: Zend Extension ./database.php does not exist
# apt install dos2unix
# dos2unix database.php
dos2unix: converting file database.php to Unix format...
# ./database.php
Yeah!!! It work's!!!!

Troubleshoot Codeigniter CLI stopped

I have been using the CLI interface to send out cron jobs from my codeigniter page. It worked fine until I updated Wordpress yesterday. I do not know how this effected Codeigniter but that is when the trouble started. I also installed cURL at about the same time. I am not sure if that could have made a difference.
SYMPTOMS:
None of my codeigniter CLI scripts work. I have two scripts that send out email reminders, and another that synchronizes my database and none function.
ERRORS:
I had some errors come up when I tried to run my scripts such as:
Use of undefined constant __DIR__ - assumed '__DIR__'
This was never a problem before. But for now I change that to
dirname(__FILE__)
and that seemed to help. At least that error stopped.
Next another error notice appeared regarding code in my scripts that I was not getting before: "Can't use method return value in write context in . . ."
This error was in reference to this line of code:
if (!empty($this->get_available_hours($date, $provider_id))) {
I modified this to
$availabehours=$this->get_available_hours($date, $provider_id);
if (!empty($availabehours)) {
And the error stopped. But the script usually sends out email regarding availability and no email is sent.
Now I have no errors. I run the scripts and I get no results. If I purposefully mess with the code and do things wrong, I get the appropriate error messages. So, at some level it is reading the file.
I tried just running a simple "hello world file" as discribed here
https://ellislab.com/codeigniter/user-guide/general/cli.html
And nothing was returned.
I tried a simple email script that would send out an email without accessing my database and it did not send anything to me.
It appeares to me like something has caused my code to be interpreted in an older version of php. So I looked at the version currently running:
When logged into the terminal in PuTTY I get:
PHP 5.2.17 (cli) (built: Feb 23 2012 10:42:34)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
Out of date ...
But when I look in the terminal within WinSCP I get:
PHP 5.5.28 (cli) (built: Sep 4 2015 12:07:49)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
This looks up to date.
Running this works: php -r 'echo "Hello World!\n";'
MY QUESTIONS:
1) What tests can I run to find out what is blocking things with my CLI?
Any tips would be appreciated.
2) Why am I seeing two different versions of PHP depending on the terminal I am running and could this be the cause of my problem?

PHP fopen() returns NULL, always

I'm attempting to open a file for parsing (a binary file), however no matter what fopen() is always returning NULL.
I've ruled out nearly everything to the point where I have a test script with simply:
<?php
$idx = fopen('/usr/home/username/web/appname/dev/www/debug/18194001.idx','r');
trigger_error(var_export($idx,true));
exit();
The output from trigger_error(var_export()); is:
[31-Mar-2013 16:30:34 UTC] PHP Notice: NULL in /usr/home/username/web/appname/dev/www/debug/ajax.idx.php on line 3
No matter what flags I specify for the second fopen() option, I get the same result.
Now, the obvious question is whether or not the file exists, and do I have permissions to read it? The answer to both of those is yes. I've used the relative path and absolute path, both read the file correct. file_get_contents() also reads the file with no issues.
is_readable() and file_exists() both return true
The output of ls -lah for that file is:
-rwxrwxrwx 1 username username 2.0K Mar 30 15:02 18194001.idx
Where 'username' matches the username the web server process and PHP (lighttpd and php-fpm) are running under. The parent directory also has read/read/read rights for user/group/all.
I've tried other files, and I've noticed pretty much anything I throw at fopen is returning a NULL value.
Help?
PHP info:
PHP 5.4.6 (cli) (built: Oct 10 2012 10:43:19)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with XCache v2.0.1, Copyright (c) 2005-2012, by mOo
Lighttpd info:
lighttpd/1.4.31 (ssl) - a light and fast webserver
Build-Date: Sep 7 2012 15:38:20
OS:
FreeBSD hostname.hostname.hostname 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Thu Feb 17 02:41:51 UTC 2011 root#mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
You cannot meaningfully var_export a fopened resource, you can however var_dump it:
$ php -r 'var_export(fopen("/tmp/a","w+"));'
NULL
$ php -r 'var_dump(fopen("/tmp/a","w+"));'
resource(5) of type (stream)
... because var_export() is meant to 'restore' a variable in PHP script, and resources require more setup then possible in instantiating a simple variable. If you want to know whether the fopen succeeded, just check it is not false.
$ php -r 'var_export(fopen("/this/does/not/exist","w+"));'
... some errors...
false
In other words, the fact you get NULL from a var_export means the fopen actually was successful.

Categories