25

I'm trying to move my Project to a linux redhat server that uses Apache but the problem I'm facing there is that this Server has 2 different PHP versions installed.

Symfony (2.5.12) seems to look for the php executable at /usr/bin/php by default but there is a 5.2 version installed, which is needed for other projects.

At /opt/rh/php55/root/usr/bin/php is an installed 5.5 version of PHP that I want to use for symfony.

So how can I configure Symfony to use the php version that is installed at the custom path?

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Mayak
  • 533
  • 1
  • 5
  • 17
  • I assume you're talking about the symfony command line tool is using `/usr/bin/php`? – Kevin Nagurski Sep 09 '15 at 14:50
  • You can invoke command line files such as the console using the full path of the PHP executable such as: `/opt/rh/php55/root/usr/bin/php app/console namespace:command` – Mihai Stancu Sep 09 '15 at 14:51
  • First question to ask: Why does the box have two PHP versions installed. Remove the 5.2 version, and make sure that when `php` is invoked at the command-line, it runs 5.5. – Simba Sep 09 '15 at 14:54
  • As an aside, to determine which PHP executable is being executed, type `which php` into the terminal. – Kevin Nagurski Sep 09 '15 at 15:32

6 Answers6

70

I know this is old, but I had the same issue of Symfony using an older PHP version (7.1 in my case, the default with OSX Mojave) than I had installed. My $PATH variable pointed to the newer 7.2 version and php -v showed 7.2 and still Symfony used 7.1.

It looks like this was solved when I ran:

symfony local:php:list

It listed all the PHP versions on my system and it had 7.2 marked as default. After running this and executing symfony server:start it was on 7.2.

The php:list command also give useful instructions on setting a specific PHP version for a project:

To control the version used in a directory, create a .php-version file that contains the version number (e.g. 7.2 or 7.2.15). If you're using SymfonyCloud, the version can also be specified in the .symfony.cloud.yaml file.

Ewout
  • 2,348
  • 1
  • 20
  • 24
  • This was the solution for me, under Windows 10. Multiple PHP CGI exes installed and Symfony defaulted to the wrong one until I ran symfony local:php:list, which seemed to default it to the correct version. – Izazael May 11 '19 at 00:50
  • 6
    Just to add, somehow running `symfony local:php:refresh` fixed the issue, then I could run `symfony server:start` as usual. – Marlon Barcarol Nov 14 '19 at 23:55
  • I did `symfony local:php:list` but it doesn't show all the php versions on my system, only the ones of wamp64 and xampp whereas I have other versions in C:/php/ . I also did the refresh command but it doesn't fix it. Any idea ? – Eve Sep 07 '22 at 14:52
  • @Eve You have to have all of them in your environment path. That is how they get auto-discovered. – informatik-handwerk.de Jan 08 '23 at 15:21
  • Thank you @informatik-handwerk.de , I didn't test that. – Eve Jan 09 '23 at 16:37
7

I had the same problem when I did symfony serve.

First I ran symfony local:php:list to know which version of php my project used.

Then I ran echo 7.4.9 > .php-version (7.4.9 is the latest php version I downloaded) to switch the php version of my project.

It works fine for me.

Oliv
  • 71
  • 2
  • 4
5

If it's your web application that's using the wrong version of PHP, this is an Apache configuration issue. If it's the command line, this is actually a pretty easy thing to fix, you just need to make sure that /opt/rh/php55/root/usr/bin/ is in your $PATH before /usr/bin.

You can do this in your ~/.bashrc or ~/.bash_profile with this:

export PATH=/opt/rh/php55/root/usr/bin:$PATH

Just put that at the end, log out and in again. You can also just pop that in your command line directly, but it'll only apply for the current session, so the ~/.bashrc or ~/.bash_profile options are better.

Kevin Nagurski
  • 1,889
  • 11
  • 24
  • 1
    Your answer is correct. My question is nonsense because I thought it's posible to configure such things in symfony but it was just an apache configuration issue. However, I thought my current symfony exception where caused by an outdated php version but it seems it isn't. – Mayak Sep 09 '15 at 15:25
  • @MayaK Bummer. Good luck tracking the issue. Feel free to post another question if you need help. *If you're happy with any of the answers you've seen, click the tick beside the answer* – Kevin Nagurski Sep 09 '15 at 15:28
2

Go into the command line interface and type below command if you want to upgrade into PHP 8.1.6 from 7.4.22

echo 8.1.6 > .php-version

it will create a .php-version file that contains the version number (8.1.6)

then try to run

symfony local:php:refresh

this is it then

Ravi Mane
  • 1,468
  • 2
  • 18
  • 24
1

After installing PHP 7.4.16, when trying to start my server:

symfony server:start

I was getting the following error:

exec: "/usr/local/bin/php": stat /usr/local/bin/php: no such file or directory

After running

symfony local:php:list

found that:

┌─────────┬────────────┬────────────┬─────────┬─────────┬─────────┬─────────┐
│ Version │ Directory  │  PHP CLI   │ PHP FPM │ PHP CGI │ Server  │ System? │
├─────────┼────────────┼────────────┼─────────┼─────────┼─────────┼─────────┤
│ 7.4.14  │ /usr/local │ bin/php    │         │         │ PHP CLI │ *       │
│ 7.4.16  │ /usr       │ bin/php7.4 │         │         │ PHP CLI │         │
└─────────┴────────────┴────────────┴─────────┴─────────┴─────────┴─────────┘

As it turns out I had some leftover files from a previous installation of PHP 7.4.14 and Symfony was trying to still use that version, which was already removed. After removing php-config, phpize and phpdbg files at /usr/local/bin I could run my server without problems.

cbakos
  • 323
  • 2
  • 9
0

go to your project create a .php-version file that contains the version number (8.1.0)