PHP-CGI not loading PATH in windows - php

I have a windows webserver running lighttpd and using PHP with CGI. Previously I was using Apache without CGI and I noticed something.
When using the php exec() command, it used to load everything from the Windows %PATH% environment variable. However, now that doesn't appear to be the case with my new setup.
Let me give an example.
Under the old setup, I could call exec("ping google.com"); and that would work just fine.
However now that doesn't work, but if I call exec("C:\windows\system32\ping google.com"); that does work.
Any ideas?

Related

PHP version supposedly wrong, but seems to be correct

I am trying to make a bash script on my server to clear the Grav cache. When I run it from the server, it works fine. But when I run it from my local machine, over SSH, I get an error: You are running PHP 5.6.36, but Grav needs at least PHP 7.1.3 to run. However, php -v on my server returns PHP 7.2.11 (cli) and on my local machine returns PHP 7.1.23 (cli). I do not begin to understand what the problem might be.
In the end, I could not resolve the issue of the different PHP versions, but solved the problem by including the path to the correct PHP version in the server script. So, locally I have ssh jeremygrav#ps589716.dreamhostps.com "bash ./clear.sh" and on the server, the script contains /usr/local/php73/bin/php bin/grav cache --all.
That works fine, although I realise it avoids the problem rather than solving it.

PHP Set Process Title in Apache

Is there a way to set the process title for a PHP script running under Apache (mod_php)? Typically, if I look at the output of top, I just see a bunch of copies of apache2, which is not usefull. I am using Ubuntu Linux in case that matters.
I have found the PECL proctitle extension, but it seems that it doesn't work very well. Plus, it's an extension, meaning I would have to get it installed, etc. I would prefer another way.
I also found the cli_set_process_title function, which seems to do what I want, but it only works in CLI mode. Is there an Apache version of this function?

How can I to run php script from powershell-commandline?

How can i setup my powershell to run php scripts in like a commandcall like this
php test.php
I'm able to do this on a server at work which I connect to by putty, but would be nice if I was able to execute those scripts directly from my own without having some server running.
I also know about Xaml, which I don't like since its require you to refresh some browser.
You can do all the stuff suggested above or ...
Go to php.net and download the php file stack for windows.
Copy the file stack into say c:\php or if you want multiple versions, say c:\php5 or c:\php7 etc.
Open powershell and type c:\php\php.exe -h, you will get the php help output. Yay you are up and running, whoot.
(Note: you may need to rename php.ini.development -> php.ini
Advanced instructions:-
Type env into os search (cortana) and select environmental variables.
Add your php location to path (c:\php) and create a variable php (or php5 etc) pointing to c:\php\php.exe
Now you can run php in powershell with php (php -h to test).
Note: while not the question, this also works in the git bash shell.
I'm assuming windows since you said powershell. You can just install php on windows but that means also installing apache or enabling IIS.
Or there's apparently a built-in webserver for command-line functionality that might minimize the amount of headache involved in configuring that stuff.
This might help get you going also:
http://php.net/manual/en/install.windows.legacy.index.php#install.windows.legacy.commandline

PHP script echoes its own content when run via Ajax on Lion

I'm having what to me is a weird problem, and I'm wondering if you can help me figure out the shamefully obvious mistake I'm making.
I have a javascript app that runs a bunch of php scripts via ajax, all running locally on my Mac, using the built-in apache server. It's been working for years, but on my new Lion Mac, the php scripts no longer return the files they're supposed to be reading. They return the php script itself.
The php scripts work fine if I run them from the command line. They work fine if I run them directly from the command line. They work fine run from Ajax on a Snow Leopard computer. They do not work if Ajax runs them on my Lion Mac.
Things I have tried :
I have adjusted httpd.conf so that the php module loads, and I have restarted my Mac.
Apache is definitely running: 127.0.0.1/~myname/ gets the "it works" msg.
I have tried running the ajax using jquery and using the old-fashioned longhand ways. Same problem. (I have made sure that jquery is in fact loading.)
I am not using the short code "<?" in my php scripts
The php file is in the same directory as the html and javascript files. The permissions are the same as the permissions on the Snow Leopard computer where it all works fine
I've tried googling for this up and down, but I'm stumped. Any suggestions? Thanks!
The problem seems to have been that php 5.3.1 was installed on my Lion machine. When I updated to php5.4, it began working again.
To update to php5.4, I followed the instructions here: http://php-osx.liip.ch/ Thanks for your help, Stackoverflow!
Is php enabled and configured properly?
Edit your /etc/apache2/httpd.conf and make sure the line: LoadModule php5_module libexec/apache2/libphp5.so exists, then re-start Apache: sudo apachectl restart
Is the correct/expected php.ini being loaded?
On Lion-upgrade the php.ini file will be renamed to /etc/php.ini-5.2-previous and a new sample PHP configuration file, /etc/php.ini.default is put in place!!!
Hence you probably might want to reconfig your php.ini file.
Extensions previously installed under /usr/lib/php/extensions/.../ had been removed.
So, if you have extensions that you wish to still use with 5.3, they will need to be re-built.
Can you now load a phpinfo.php file containing <?php phpinfo();?>.
Now check the phpinfo for the mySQL directives (and other locals) if you use it.
Apple has included the Suhosin patch and extension.
Suhosin is part of the Hardened-PHP project which aims to protect PHP applications against buffer-overflow and format string vulnerabilities. Compare Suhosin's feature-list to your php-scripts.
Might there be deprecated php statements being used (that worked in a older version of php)?
Does it work now?

Executing java from CLI via exec() under Windows

I have a PHP-script originally developed on Ubuntu, which now has to run on a Windows machine, executing a java program like this:
exec("java -jar {$filename}");
// Process output
This does not work as expected on Windows. I already found out, that although I can use java -version from the command prompt I can't use it in exec(), i.e. the problem is java can not be found.
I have a workaround in place, pointing to java.exe using the complete path to C:\Program Files\Java\...\java.exe if the script runs on Windows. Unfortunately though this is hardcoded to the path on the current machine, which might change or vary on a different system, e.g. when installing Java to a different location or a different version (JRE/JDK/6/7) is installed.
How do I call Java on Windows without having to refer to the exact location of java.exe?
You need to set enviroment variable on windows, to be able access java without path
http://www.java.com/en/download/help/path.xml
Even if this Question is a little older, I ran into the same problem and I found a pretty neat solution for it without the PATH requirement.
There is a symlinks to all java executabled located in this folder:
C:\ProgramData\Oracle\Java\javapath
for example: just call
C:\ProgramData\Oracle\Java\javapath\java.exe -jar XYZ.jar

Categories