follow us on google+ follow us feedburner

FORUM

Go to Topic: PreviousNext
Go to: Message ListNew TopicSearchLog InPrint View

How to run php from Command line?



Posted by: jrsrinu
November 15, 2012 03:16AM
Hi Guys,

I'm new to easyphp and so far it's been incredible to use it. I'm on Windows 8.

I'm using Easyphp 12.1 with Php 5.4.8. Everything is working fine with in the broswer. So when I started using command line, it is getting me frustrated so far.

I've installed Easyphp 12.1 in G:\ drive.
Initially php.exe is located in G:\Easyphp-12.1\php\php548120001230\php.exe,
later I've changes the it to G:\Easyphp-12.1\php\php548\php.exe. Just renamed the folder of 'php548120001230' to 'php548' and edited corresponding text in php.ini(at both places 'G:\EasyPHP-12.1\conf_files\php.ini' and 'G:\EasyPHP-12.1\php\php548\php.ini').

Finally, I'm getting this error : please see this image at [imgit.me] , only when I type "G:\Easyphp-12.1\php\php548\php.exe -v" into the command prompt of Windows.

Basically it is saying " PHP Startup: Unable to load dynamic library 'C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\php\php548\ext\php_bz2.dll' - The specified module could not be found." When I click OK, a lot more warnings are being popped up with some different dlls. All those files are placed correctly in those folders. After several warnings, I get the final result like this at [imgit.me] .


This is not an issue with setting up a PATH variable in windows, since I gave the whole path in CMD, it should show up with no warnings.

I think the problem is with ${path} variable, where is it defined and how do I edit/change it? I'm guessing, well someone with more knowledge could help me.

For two days I've been working with issue and got nowhere. HELP is appreciated.
Thanks.
Options: ReplyQuote
Posted by: _Thierry_
November 15, 2012 09:34AM
Add php extension folder to path.
Options: ReplyQuote
Posted by: Russell
November 15, 2012 02:37PM
The ${path} is just looking up environment variables, so the only way to alter this is to alter your environment variables. You could use ${tmp} to get temp folder, ${windir} to get windows root folder, etc.

Adding a folder to path won't work as the ${path} variable is being substituted with the entire path string, therefore it will look for your files in a directory that can't possibly exist. That's what is happening for me in any case when I tried that. I'm not sure how apache is handling this, I would have thought it would do exactly the same thing but there is clearly a difference in the way PHP is instantiated between apache and CLI. maybe someone with more PHP knowledge can explain it.

I got it to work by modifying the php.ini in the php548x[date_time] folder. Leave the php.ini in the conf_files directory so apache can do its own thing. (whatever that may be):
Backup your php.ini in case you need it in the future/make things worse.
Edit php.ini and do a find and replace for ${path} to become ${PHPRC}.
Declare a new Environmnet variable called PHPRC and set it to be the install directory of EasyPHP (e.g. C:\Program Files (x86)\EasyPHP12.1).
Restart your command prompt/powershell instance to re-read you Environment variables.

This will leave you with only one problem php_yaz.dll can't be found. If you have a quick look in the ext directory of your PHP install you will notice php_yaz.dll is version 5.4.3 whereas all the others are 5.4.8 like the version of PHP itself. I'll be honest and say I have no idea what yaz does. If its not overly important you could just remove the reference to it if you aren't using it. With this method, I got PHP to run from the command line.

I'm guessing that this will break the ability to switch between versions of PHP through the EasyPHP homepage (as I'm guessing the conf_files directory is populated with the PHP install's php.ini).

Its not a perfect solution, its more half-a*sed ;-)
Options: ReplyQuote
Posted by: jrsrinu
November 15, 2012 07:41PM
Russell Wrote:
-------------------------------------------------------
> The ${path} is just looking up environment
> variables, so the only way to alter this is to
> alter your environment variables. You could use
> ${tmp} to get temp folder, ${windir} to get
> windows root folder, etc.

So my question, how do I alter my environment variable in PHP/Easyphp,${path} not sure where it is defined?

> Adding a folder to path won't work as the ${path}
> variable is being substituted with the entire path
> string, therefore it will look for your files in a
> directory that can't possibly exist. That's what
> is happening for me in any case when I tried that.
> I'm not sure how apache is handling this, I would
> have thought it would do exactly the same thing
> but there is clearly a difference in the way PHP
> is instantiated between apache and CLI. maybe
> someone with more PHP knowledge can explain it.

Yes you are right Russell, EasyPHP rewrites the PATH variable inside windows environment, and makes it as php\php548\php\php548\ext\.. adds PHP inside PHP. Which is obviously wouldn't exist for sure.

>Declare a new Environmnet variable called PHPRC

Please assist me in declaring a new environment variable, I guess this a variable inside of EasyPHP.

After reading your whole post, I don't want to make things more difficult with the browser side of EasyPHP, at least for now it is really great for me. After all, it seems that I've to settle with WAMPserver.


Finally, two questions:
1. How do I report a bug or issue to EasyPHP developers?
2. Since EasyPHP official forum is not populated yet, where do I get help on this issue with a final FIX not work around?

Thanks Russell, for your prompt response, at least you acknowledged the issue that I'm facing with.
Options: ReplyQuote
Posted by: Russell
November 16, 2012 10:00AM
Hi jrsrinu,

The environment variable is a windows thing.

For Windows 8, hit Win+X then choose System from the menu provided.

In the System control panel app, click on Advanced system settings (located in the upper left part of the window)

In the System Properties window click on "Environment Variables..."

Now just click on one of the "New..." buttons. If you choose the User variables section your new ENV variable will only work for your user account, if you choose the System variables then it will work for all accounts.


By doing the mod I said, as long as you don't change your PHP version to an older/new one then try to change it back to 548 using the EasyPHP admin functionality, your web stuff will still work as it runs off a different copy of php.ini (the one that's copied to the apache directory from the conf_files directory).

I don't know the answer to your last 2 questions, sorry.
Options: ReplyQuote
Posted by: jrsrinu
November 16, 2012 04:03PM
If PATH variable is a windows thing, how come easyphp alters that?

I understand your point of doing the mod, php version will get updates regularly right? so I tend to use latest versions.

Thanks for your reply though.
Options: ReplyQuote
Posted by: Russell
November 16, 2012 05:00PM
PHP doesn't modify it, it just uses it, which is why its outputting the whole thing.
Options: ReplyQuote
Posted by: _Thierry_
November 16, 2012 03:33PM
yaz extension got a dependency to yaz.dll that exists in apache directory.
to run from command line:

set PATH=%PATH%;C:\Program Files (x86)\EasyPHP-12.1\php\php546x121024135611
set PATH=%PATH%;C:\Program Files (x86)\EasyPHP-12.1\apache\bin

php -c "C:\Program Files (x86)\EasyPHP-12.1\apache\php.ini"
Options: ReplyQuote
Posted by: jrsrinu
November 16, 2012 03:57PM
_Thierry_ Wrote:
-------------------------------------------------------
> yaz extension got a dependency to yaz.dll that
> exists in apache directory.
> to run from command line:
>
> set PATH=%PATH%;C:\Program Files
> (x86)\EasyPHP-12.1\php\php546x121024135611
> set PATH=%PATH%;C:\Program Files
> (x86)\EasyPHP-12.1\apache\bin
>
> php -c "C:\Program Files
> (x86)\EasyPHP-12.1\apache\php.ini"

As you sure,Thierry, by setting this will solve the warning issues of my first opening post of this topic?

Any way I set the path variable in windows, easyphp ${path} variable rewrites the whole path to non-existent folder in php. How do I get away with that?
Options: ReplyQuote
Posted by: Russell
November 16, 2012 05:03PM
Just tested this and it definitely works!

I also understand now how Apache's PHP works, EasyPHP processes the php.ini file from the php install and hardcodes the path to the EasyPHP install folder. Its not magic after all...

Thanks Thierry!
Options: ReplyQuote
Posted by: _Thierry_
November 16, 2012 05:27PM
Yes, ${path} is just a marker, in conf_files files, replaced by installation path in final configuration file. That allows to transfer all the directory to a usb key and it still working.
Options: ReplyQuote
Posted by: Thierry
November 16, 2012 08:31PM
Just enter your php script.
Options: ReplyQuote
Posted by: jrsrinu
November 17, 2012 07:18AM
I'm Still unable to do it, can you help??
[imgit.me]
Options: ReplyQuote
Posted by: jrsrinu
November 18, 2012 08:59PM
Ok, Thierry, i got it working fine, with the help of Russell.

So this is finally a work around, not the perfect solution right?
I mean I just enter "php -v" and it should return version number with no warnings.

Anyway, coming to your little hack, I don't want to type the whole string in CMD every time, is there any short cut for that too?

I hope it will get solved in future updates of Easyphp.
Options: ReplyQuote
Posted by: _Thierry_
November 19, 2012 10:22AM
Just create a batch file with:
@echo off

set PATH=%PATH%;C:\Program Files (x86)\EasyPHP-12.1\php\php546x121024135611
set PATH=%PATH%;C:\Program Files (x86)\EasyPHP-12.1\apache\bin

"C:\Program Files (x86)\EasyPHP-12.1\php\php546x121024135611"\php -c "C:\Program Files (x86)\EasyPHP-12.1\apache\php.ini" %1

echo.
pause

You also may associate your PHP files with it:
- select a PHP file
- right clik / Open with
- browse to your .bat file.

Then a doubeclick on your file will call PHP interpreter.
Options: ReplyQuote
Posted by: lol
November 20, 2012 09:07PM
But why isn't EasyPHP able to fix this issue? We shouldn't need to do this mambo jambo, the name of the package is Easy PHP not HardPHP lol
Options: ReplyQuote
Posted by: jrsrinu
November 21, 2012 07:58AM
@_Thierry_ that's hell lot of thing to manage with, I better go look for wamp or xampp, at least for command line. That being said, I still like web-browser side of easyphp.

@lol, apparently they ignored PHP for command line. That's why this hack. Not sure whether they are interested to fix this.

lol Wrote:
-------------------------------------------------------
> But why isn't EasyPHP able to fix this issue? We
> shouldn't need to do this mambo jambo, the name of
> the package is Easy PHP not HardPHP lol
Options: ReplyQuote
Posted by: Thierry
November 21, 2012 10:42PM
It's not a issue but a "not feature".
Options: ReplyQuote
Posted by: hansfn
November 23, 2012 12:48AM
It's a bug ;-) They just shouldn't use such a general variable name as "path" (that even clashes with the Windows PATH variable). I suggest, and hope, that developers replace it with "easyphppath" in the next release.

I'm fine with EasyPHP not being a command line tool, but they shouldn't make it unnecessarily hard for us that need to use it from the command line too. An example: Everyone that use Drush to develop and maintain their Drupal sites.

And finally; jrsrinu asked "How do I report a bug or issue to EasyPHP developers?". I can't see that anyone answered that. I didn't find a bug tracker here on easyphp.org or on sourceforge.net/projects/quickeasyphp/

Except for this slightly annoying issue when using PHP on the command line, EasyPHP is great and I love the vhost manager.
Options: ReplyQuote
Posted by: _Thierry_
November 23, 2012 03:27PM
hansfn Wrote:
-------------------------------------------------------
> It's a bug ;-) They just shouldn't use such a
> general variable name as "path" (that even clashes
> with the Windows PATH variable).

There's no clash because it's not at all the same purpose.
Path is a generic term. And that's the first time that the name choice of an identifier is a bug :-)


> I suggest, and
> hope, that developers replace it with
> "easyphppath" in the next release.

???
- We name the things as we want
- ${path} have nothing to do with running PHP in command line...
Options: ReplyQuote
Posted by: Russell
November 23, 2012 05:09PM
I have to disagree with you there Thierry, PHP will use environment variables if a variable hasn't been set using the ${} syntax so there definitely is a clash. An unintentional one that arises from people using your program in ways you have not intended but it does exist as can be seen from some of the posts in this topic.

Changing the name as hansfn suggests would stop this but would just bring about more questions as to why PHP seems to work on command line but exhibits a strange behaviour so its not quite as easy as just renaming that variable. Its almost the same as calling php -n to stop php loading an .ini file. On the whole it would make it slightly easier to modify the host system as all they would have to do is add an environment variable and set it to the EasyPHP install path then command line access would work.

Is it not worthy of even considering?
Options: ReplyQuote
Posted by: jrsrinu
November 24, 2012 09:44PM
Yes, hansfn, I've been wondering the same, no bugtracker? Indeed I liked vhost manager very much.

hansfn Wrote:
-------------------------------------------------------
> And finally; jrsrinu asked "How do I report a bug
> or issue to EasyPHP developers?". I can't see that
> anyone answered that. I didn't find a bug tracker
> here on easyphp.org or on
> sourceforge.net/projects/quickeasyphp/
>
> Except for this slightly annoying issue when using
> PHP on the command line, EasyPHP is great and I
> love the vhost manager.



And Russell, thanks for still looking out this issue. I really ask the same question, is it not worthy of even considering?


Russell Wrote:
-------------------------------------------------------
> Is it not worthy of even considering?
Options: ReplyQuote
Posted by: _Thierry_
November 26, 2012 11:17AM
For the last time: ${path} is used for EP insternal stuff only.
And its used for template configuration files. Conf files used by PHP /A pachec does not see this tag.

You can use PHP in command line without changing any env variable, just use the batch posted upper.
Options: ReplyQuote
Posted by: hansfn
November 27, 2012 01:52AM
OK, I got it. The php.ini file in the Apache dir is expanded so we can use that file. I still think it is strange that calling the php executable directly on the command line causes fatal errors. Couldn't the non-expanded php.ini be stored elsewhere?

PS! Your batch script was incomplete - only one argument was passed. In addition you only need to add the Apache bin directory to the path (since the paths in the ini file is expanded). The following worked nicely for me:

--- Start easyphp-php.bat ---
@echo off
set EASYPHPDIR=C:\Development\EasyPHP
set PATH=%EASYPHPDIR%\apache\bin;%PATH%
%EASYPHPDIR%\php\php546x121127010306\php.exe -c %EASYPHPDIR%\apache\php.ini %1 %2 %3 %4 %5 %6 %7 %8 %9
--- End easyphp-php.bat ---

Maybe you could add such a bat script to EasyPHP if you can't move the non-expanded php.ini file out of the way?
Options: ReplyQuote
Posted by: Clubnite
January 16, 2013 12:06AM
@hansfn

using your batch file how would i use PHP then? I called the .bat from the commandline and typed php -v afterwards, but there happened to be no output.

And what do the parameters in the last line substitute?



Edited 1 time(s). Last edit at 01/16/2013 12:08AM by Clubnite.
Options: ReplyQuote


Go to: Message ListSearchLog In
Your Name: 
Your Email: 
Subject: 
Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.