Cannot run php from command line when use environment variable - php

I have windows 8, and whenever I run php from the installed directory, then it works without a problem, but whenever I set the environment variable to that directory, and run php --version, then a win-8 bar appears:
This app can't run on your PC To find a version for your PC,
check with the software publisher
Has anyone encountered a similar issue or found a solution for this?
Attached below are the commands that i ran:
K:\Users\username>php
Access is denied.
K:\Users\username>php
Access is denied.
K:\Users\username>php --version
Access is denied.
K:\Users\username>F:/
'F:/' is not recognized as an internal or external command,
operable program or batch file.
K:\Users\username>F:
F:\>php
Access is denied.
F:\>cd Program
F:\Program>cd php-5.5.6-x86
F:\Program\php-5.5.6-x86>ls
dev iculx51.dll libpq.dll php.gif
ext icutest51.dll libsasl.dll php.ini-development
extras icutu51.dll license.txt php.ini-production
glib-2.dll icuuc51.dll news.txt php5.dll
gmodule-2.dll install.txt phar.phar.bat readme-redist-bins.txt
icudt51.dll libeay32.dll pharcommand.phar snapshot.txt
icuin51.dll libenchant.dll php-cgi.exe ssleay32.dll
icuio51.dll libenchant_ispell.dll php-win.exe
icule51.dll libenchant_myspell.dll php.exe
F:\Program\php-5.5.6-x86>php --version
PHP 5.5.6 (cli) (built: Nov 12 2013 11:33:16)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
F:\Program\php-5.5.6-x86>
By the way the same thing occurs in wampserver php, so it probably dont have anything to do with 86 bit install or 5.5.6 unstable.
I also tried run as admin not working either, same output.

You might have two PHP executables, one of them (F:\Program\php-5.5.6-x86\php.exe) is working, one of them (which is on your path) is not. Check the directories in your PATH for the broken one.

I have same issue before and tried several things, one of the things that works for me that the php.exe file has been changed by some program and it's size was 0 kb, I reverted back by bringing the php.exe file from backup folder I have.
may be it is not solution for all people, but just check the php file hasn't been changed.

Related

Should I install additional php when XAMPP has default php package in it?

I'm a begginer in Laravel and I installed XAMPP as local server. I noticed that my XAMPP already install php 7.4 as it's dependency. But when I tried php -v in www dir in php it shown.
'php' is not recognized as an internal or external command, operable
program or batch file.
But in php directory is shown
PHP 7.4.15 (cli) (built: Feb 2 2021 20:47:45) ( ZTS Visual C++ 2017
x64 ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c)
Zend Technologies
So, should I install additional php in my system for development? Should the version of the php matche with XAMPP php 7.4?
php -v will only tell you if you have PHP installed as a command line interface (PHP-CLI) which would enable you to run php code in cmd.exe or powershell. You'd normally not need this, but for reference here's how to enable it: https://stackoverflow.com/a/10753133 (mind the comment on Windows 10).
To check if PHP runs in your webserver environment (which is by default available in xampp), create a file test.php in your www folder with the following content:
<?php
phpinfo();
?>
Call this file in a browser, you will get an overview of all php features available. Delete the file before you go productive, because it will also give hackers a lot of information (which you don't want).
Try to add XAMPP PHP to Environment Variables
here is an instructions for Windows 10

Apache won't load Zend Guard Loader

I'm using Ubuntu 15.04 - 64 Bit with the following setup:
Apache
Server version: Apache/2.4.10 (Ubuntu),
Server built: Jul 24 2015 17:25:18
PHP
PHP 5.6.4-4ubuntu6.2 (cli) (built: Jul 2 2015 15:29:28) Copyright,
(c) 1997-2014 The PHP Group Zend Engine v2.6.0, Copyright (c),
1998-2014 Zend Technologies with Zend OPcache v7.0.4-dev, Copyright,
(c) 1999-2014, by Zend Technologies
My php.ini (The last 5 lines)
; Local Variables:
; tab-width: 4
; End
zend.loader=1
zend_extension="/var/www/extensions/ZendGuardLoader_56.so"
And yeah, ZendGuardLoader won't be loaded (it's not mentioned in "php -v" and also not in "phpinfo()").
Thread safety is disabled! If you need other options, let me know.
What i've tried so far:
removed the "zend.loader=1" option,
Tried "zend_loader.enabled = 1" instead "zend.loader"
included an older version from ZendGuardLoader (5.5 instead 5.6)
Changed the owner and group from both files to my account (instead www-data)
Changed the permissions to 777, 775, 755
Also nice to know:
My Apache Error Log is also "clean". If i rename the .so file, my Apache logs that exception. But on the current setup, the file is readable.. Don't get me wrong, but i expect a message like "ZendGuardLoader can't be loaded because "..
Update1
After a few hours, i'm pretty scared! I've installed vagrant incl. "Debian 7.8" as well, started everything and so on. On my box i've installed PHP (5.4) and Apache, created the www folder to the same destination, and downloaded the 5.4 ZendGuard Loader. In my box setup i did the same, as on my main system like -> php.ini, last entry: "zend_extension=/vagrant/ZendGuardLoader.so"
The file exists, is readable as well, and so on. After creating a new "info.php" ("phpinfo()"), it's still without ZendGuardLoader Extension. The command php -v says mostly same, as main system (differences on version..).
Solution for php -v
Okay guys, my mind was broken - but it's not fixed! I told you, by checking php -v the output is pretty default (no ZendGuardLoader). BUT(!): php -v gets executed by commandline (cli) - so i've added the "zend_extension" inside php5\cli\php.ini -> works like a charm!
PHP 5.4.41-0+deb7u1 (cli) (built: May 22 2015 12:49:18)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies
That's what i've wanted. So i've called the phpinfo file by using commandline - and save the output into a separated file. And as i can see, the ZendGuardLoader is given, too!
But there is still the Apache Problem. The zend_extension line matches exactly between apache2\php.ini and cli\php.ini.
So it's not a permission problem, because CLI has no problem. I think, apache is broken, because it won't load that less special extension..
A new day - new ideas
Okay guys, yesterday we got the point, why it won't work on CLI, but that's less the major problem. So i've integrated ioncube on CLI and also on apache. CLI works like a charm. Apache won't load ioncube, too. So what is wrong with this apache..?
I tried to provoke some errors by creating a new file in the php5\apache2\conf.d\ directory. The new file contains the same "zend_extension=/vagrant/ZendGuardLoader.so" snippet, as my php5\apache2\php.ini - so apache2 would try to load the .so twice, and throws the expected error:
PHP Fatal error: [Zend Guard Loader] Extension "Zend Guard Loader" cannot be loaded twice in Unknown on line 0
Apache tries to load both extensions. So i might be right, if i'm gonna say, apache2 load the extension, if it's only one! But it seems, that apache can't work with the extension. Remember - php cli ("php -v" / "php -m" ) can!
For all those people, who wanna to know the solution:
After debugging Apache for a while, i've found, that the include per apache2\php.ini won't work correctly for me. So i've created a new file inside apache2\conf.d\ - and deleted the entry inside apache2\php.ini.
After reloading apache2 nothing changed, but phpinfo() says, the extensions was loaded. I've reloaded again - and, finally!, everything works. I am not sure, what happens to me or apache2.
The curios thing at all: I've to reload apache2 twice after restarting VM. But after that process, everything works perfect. So guys..
TL;DR;
Create new file in apache2\conf.d\ and use same "zend_extension=/path"
Restart apache2 twice.
Profit

installing composer on a shared host

I am trying to install composer on my shared host for the first time.
When I run curl -sS https://getcomposer.org/installer | php
I am getting a Composer successfully installed
User it: php composer.phar
when I run php composer.phar i am getting this warring error:
Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI
any ideas on how to fix this ? and why i am getting this error ? :(
when I run php -v i get this back
PHP 5.4.39 (cgi-fcgi) (built: Mar 25 2015 14:20:20)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies
Do I need to run this using CLI version if so how would i do this ?
Any help would be nice thank you.
I resolved this by explicitly calling the version of PHP it asked for. Keep in mind that on a shared server environment there is often multiple versions of PHP running and even though you may have set up your default in your cPanel config, bash commands often resolve to another (lower) version.
First, I created a bin directory and moved composer.phar into it. Then, I added this alias to my .bash_profile and it worked like a charm:
alias composer="/usr/php/54/usr/bin/php-cli ~/bin/composer.phar"
Hope this helps!
As Composer is now available via WHM you can use this to find it:
which composer
This returned path "/opt/cpanel/composer/bin/composer" for me. If this returns nothing then disregard the rest of this answer, as Composer is not available to you at system level.
You can now use php-cli to call this with Composer's absolute path:
php-cli /opt/cpanel/composer/bin/composer install
php-cli /opt/cpanel/composer/bin/composer update
php-cli /opt/cpanel/composer/bin/composer require whatever/example
You may however need to alias php-cli if your system claims this isn't found. It very much depends how PHP has been deployed on the WHM server. You can do this by adding a user alias to the end of your ".bashrc" file as follows:
alias php-cli=/opt/cpanel/ea-php72/root/usr/bin/php
Replace ea-php72 with the release of PHP you want to use. Submit this as a command in the shell to make it available immediately, otherwise it'll become available when you open your next Bash session.
If you want to make this available with just composer alone you could create this alias again in ".bashrc":
alias composer=/opt/cpanel/ea-php72/root/usr/bin/php /opt/cpanel/composer/bin/composer
Or
php-cli $(which composer) ...
The location of the php versions installed will vary from host to host. Try finding them with:
locate /bin/php
For me this lists all php versions and I can then replace php with, for example:
/usr/bin/php71-cli
To access the command line interface version rather than the default cgi one. Then as stated by #Diggery you can create an alias.
alias composer='/usr/bin/php71-cli bin/composer.phar'
There are many suggestions on StackOverflow on how to test for a cli installation but the above is the only one that worked for me.
I have made a script to handle changes in composer/vendor. The script works with ftp-only servers, sends/removes only the changed files. Maybe someone will find it useful.
https://github.com/psad73/tune-composer

Fix Cygwin Emacs flycheck-mode errors finding /tmp and phpcs in win7 running xampp php

Issue with Errors
Have been using Emacs for a couple years. Recently decided to try the Prelude version (link to prelude). Install went smoothly (on Win7 with Cygwin), but have been unable to use php error checking for a couple days. I want to get php error checking to work with Flycheck. It is non-functioning for me right now.
Currently, when I break a php script, flycheck.el (#ln2551) returns 2 errors:
Checker php returned non-zero exit code 1, but no errors from output:
Could not open input file: /tmp/flycheck4728Btc/myPhpFile.php
Checker definition probably flawed.
Checker php-phpcs returned non-zero exit code 1, but no errors from output:
Could not open input file: /cygdrive/c/xampp/php/phpcs
Checker definition probably flawed.
Debug Info
1). Flycheck writes a buffer copy in Cygwin root /tmp directory. See flycheck.el (#ln800)):
This file exists and is a confirmed readable buffer copy; there is no a problem with its file permissions (same error whether chmod 777 or 700).
2). Phpcs is located at c:/xampp/php/phpcs and can be called from the command line (cmd.exe and cygwin bash) with or without the c:/ path; but does not work with the cygdrive path. [This does NOT work $/cydrive/c/xampp/php/phpcs -h (with or without the .bat extension).] I have also confirmed good installation of phpcs (and it works from command line), and that there is not a file permission issue here. I have set the flychech-phpcs-standard variable to c:/xampp/php/phpcs as per flycheck.el #ln2895-2903 but have not found the condition that throws throws the error.
[Note: This error did go away when I tried renaming the phpcs file and specifying the phpcs.bat, but I am not sure sure whether the checker was found or not since the write to tmp file error still thwarted any results. Also, that broke my commandline usage of the phpcs command.]
Just to be sure, here is my php -v:
$ php -v
PHP 5.4.7 (cli) (built: Sep 12 2012 23:48:31)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
Here is my phpcs version:
$ phpcs --version
PHP_CodeSniffer version 1.3.3 (stable) by Squiz Pty Ltd. (http://www.squiz.net)
And have this alias in my .bash_profile:
alias phpcs="c:/xampp/php/phpcs"
And c:\xampp\php on my PATH
Research
I been going through the phpcs, cygwin, and the flycheck.el, including the instructions to customize the flycheck-phpcs-standard lines and have not made any progress on this issue.
I am unsure whether this has something to do with the comments on flycheck.el#800-824 (defun flycheck-temp-file-system (filename prefix) or not. Those are comments about hacking around a compression bug with Emacs. Anyway,
How to fix this?
Any comments or ideas to test this further? Anyone have flycheck working on win7 with Cygwin? Is it an operating systemn compile issue? Directory paths in scripts somewhere?
This is not an error with flycheck!
[Thanks to the repository owner for giving me a clear answer on that].
flycheck-phpcs-standard does not take a path to phpcs. I had that wrong. Once I learned that, the context of the documentation made more sense.
What was happening is that Cygwin environmental path mounting is not what is running when flycheck is used. Phpcs itself is given a unix type path tmp/flycheck23423.buffer-copy and cannot run it. Stink me!
In response to that new, I was trying to see if I could make windows read those paths. And the good news is you can, ofcourse! This superuser QA was helpful.
This is how you fix it:
1) download the windows junction tool to a windows folder from which you will run it in cmd.exe. EDIT: see comment, should use mklink in win7.
2) C:\your\cmd\path> junction \cygdrive\c \
... this will output ...
Created: C:\cygdrive\c
Targetted at: C:\
3) C:\your\cmd\path> junction \tmp C:\cygwin\tmp
... this will output ...
Created: C:\tmp
Targetted at: C:\cygwin\tmp
Now, open a php script in emacs and break it. It works!
It is phpcs is able to find the /tmp/.. . check it, and return the error messages. Cool.

Problem of different PHP versions reported

I have upgraded to PHP 5.3 on a development machine (Windows 7 box).
php-v shows
PHP 5.3.3 (cli) (built: Jul 21 2010 20:36:55)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
However, phpinfo.php shows that the version on the machine is: 5.2.14 as shown
The loaded configuration file rightly loads the correct php.ini file for 5.3
The configuration file (php.ini) Path wrongly reads: C:\Windows - I don't install PHP on the said path. I have however done a recursive search of PHP folders and files within that file but the search turned up nothing.
Applications seem to use the settings reported by the phpinfo and not by php -v or php -m or php -i (or else).
Apart from deleting the PHP folder and starting from scratch (which I have done), and ensuring that Apache points to the right PHP dir using PHPINIDir, what could I possibly do to solve this? Thanks.
Hello
You should also update apache php
module
#soju - that fixed it, thanks, but I thought I'd make this a little clearer for others.
Apache requires the php module to serve php files. On Windows it comes as a .dll file. This would be called: php5apache2_2.dll - located within your php folder. Strangely though, during upgrading the php folder with a newer version, you may find out that apache still uses the old php module file. So while php -v correctly reports the new version, Apache still looks at the old php module (reported by phpinfo). To find out what module version you have, you could: right-click on the .dll file > select properties -> view the details tab. Or just hover on the file.
If this version is not what you want, you might want to hunt for a newer version and replace it. Good idea to back up first. Also, the php5apache.dll file works with and requires the file: php5ts.dll - so ensure these files are the same versions.
With your httpd.conf file with the directive:
LoadModule php5_module "\path to\php5apache2_2.dll"
You may restart apache and smile!
Your command line (CLI) php is an other version than the one used for Apache. Check also that both use the same php.ini. When you call on your Windows machine
c:\path\to\php\php.exe -v
or
c:\path\to\php\php-win.exe -v
and
c:\path\to\php\php-cli.exe -v
They all can return different versions. Often this happens when upgrading to a new WAMP version and forgetting to delete the old versions. I'm sure you will find the executable PHP binary which matches the same version. It is also save to use the php.exe or php-win.exe instead the php-cli.exe on Windows.

Categories