PHP 5.4 in x11, but 5.3 in terminal - php

I tried to install php 5.4 yesterday but it doenst quite work. If i do php -v in Terminal i get 5.3, but if I do php -v in X11 it says that I have 5.4 and i can even start local server and it works just fine. Why doesnt it work in Terminal?
Someone said something about change things in my PATH, maybe thats correct, but how do I do that?

It seems that you have 2 versions of PHP installed but that the 5.4 is not the "default" PHP that is reachable from your PATH (an environment variable telling your system where to look for finding the program you're calling in your command line).
To find where the PHP 5.3 executable is, you could use the which ( http://ss64.com/osx/which.html ) command, on my computer it looks like this :
➤ which php
/usr/local/bin/php
On my system /usr/local/bin/php is just a link pointing to the PHP executable I want to use (I keep several versions of PHP installed on my system in /usr/local/php/<version>/)
You could check what the which command return and if the given result is a symbolic link like mine. If yes, changing the link to make it point to you 5.4 executable should do the trick.

Related

Setting up Symfony2 with PHPStorm 7.1.3 not working

I am trying to setup Symfony2 with PHPStorm 7.1.3 using these instructions but I am running into an error when i execute php app/console server:run.
The error I see is
[InvalidArgumentException]
There are no commands defined in the "server" namespace.
This is what my development machine has
WAMP: 2.5
PHP : 5.5.12
OS : Windows 7
So after getting this error I went to google to do some search and saw many people who had similar problem were using PHP 5.3 and the command line was built for PHP5.4 on wards. I then installed a new version of WAMP which came with PHP 5.5.12 assuming and hoping the error to go away and let me move on to development but then I got the same error again. Now something tells me may be I did not configure something right so I went to see the PHP settings and all seems fine to me.
I am not sure what else to do to get it to work, I will really appreciate if anyone can guide me in setting up Symfony2 with PHPStorm.
UPDATE:
I ran a command php -v to double the php version and it says PHP 5.3.13
You are clearly using Terminal and not Command Line Tools (CLT). The manual you are referring to was made for older version where terminal was not yet available and it refers to CLT (which you are NOT using).
Since you are using Terminal, make sure that your system-wide PHP is actually v5.5. You can verify this by executing php -v command.
Terminal and "Command Line Tool Support" plugin are two different things. First is the same as your real console/terminal (e.g. cmd.exe on Windows) .. while second is some custom emulator (don't know better word/term) which can use PHP Interpreter from PhpStorm settings if configured accordingly (as per manual).
If you want to use Command Line Tools:
It is located at Tools | Run Command... .
Make sure that you have created php alias (as per that manual) so it refers to currently select PHP Interpreter from IDE settings. Otherwise php command may fail. Aliases can be configured at Settings | Command Line Tool Support.
If you want to use Terminal:
You have 2 choices here:
Use FULL path to correct php.exe instead of just php
Make php v5.5 default system-wide. For this you have to:
Alter your PATH environment variable (My Computer | Right click | Properties | Advanced System Settings | Advanced | Environment variables...) and place folder where correct PHP 5.5 is located in front of the list
Restart IDE (most likely will be required) so it picks up these changes to environment variables.

Apache and Command Prompt running two different version of PHP on windows

Yesterday, I installed Pear. During installation it asked me installation path of php. But, i mistakely entered different path. So, Pear installed different php version in that Path.
Problem
Now, my apache runs php v5.5 as always. But, from yesterday, command prompt runs v5.3!
How can I make changes so that command prompt runs same version as apache i.e. v5.5.??
I am using windows.
Edit your path variable, replacing the path to v5.3 with the path to v5.5. This guide provides some good info on how to edit the system path.

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 Interpreter for Windows

Trying to mess around with PHP, but I don't want to install IIS or Apache and was hoping for a small interpreter that I can pass the scripts to and have them run in like a console or something. Much like Lua does. Does this exist? When I go to download PHP it seems to only talk about running it on IIS or Apache.
PHP can be used on the command line. Just download and extract the executable.
Running can be done 3 ways: a file, supplied code or in an interactive shell
php file.php
php -r "echo 'hello';"
php -a
You can also install a pre-packaged server (e.g. XAMPP) or run your code online on various places (e.g. phpfiddle.org)
With PHP 5.1+ you have an interactive shell too:
launch php with -a parameter
php.exe -a
http://php.net/manual/en/features.commandline.interactive.php
I believe that PHP v5.4 comes with its own webserver built-in. Install that version and you should be fine. Though I really would like to know why you have problem with installing Apache (IIS sucks though).
EDIT:
As a few others have said, you can run PHP from the command line.
check out easyphp, a server for php development
http://php.net/cli
Alternatively, you can write your PHP scripts as you would normally (with some limitations),
And use the following command line:
C:\php.exe -f "D:\phpFile.php"
dtech's answer seems most fitting for the simple script-running things you're looking for. If you decide you want an actual web-server, with as little setup as possible, look at "XAMPP".

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