change php cli version

Как изменить версию php в консоли

Если у вас установлено несколько версий php в системе, то при вызове команды php в консоли, будет использоваться одна из них. Иногда необходимо для каких-то скриптов или сервисов управлять версией php в консоли. Я расскажу, как ее изменить.

Посмотрим, где располагается сам бинарник php:

Оказывается, что /usr/bin/php является символьной ссылкой. Посмотрим, куда она ведет:

Это еще одна символьная ссылка. Смотрим, куда ведет она:

На седьмую версию php. Заменим ее на 5.6, которая у меня установлена по адресу /usr/local/bin/php. Редактируем символьную ссылку:

Проверяем текущую версию php в консоли:

Все получилось. Теперь в консоли по-умолчанию будет использоваться нужная версия php. Можно проверять скрипты, не указывая полный путь к нужной версии.

Директории проверяются в том порядке, как они перечислены. Где будет найдено первое совпадение, тот файл и будет использоваться. В моем случае директория /usr/bin, где жила символьная ссылка на php7.0 стоит раньше, чем /usr/local/bin, где расположена php5.6. Можно было просто поменять местами эти директории в PATH и версия по-умолчанию станет 5.6, так как ее бинарник php будет найден раньше.

Более гибко управлять версиями php в системе можно с помощью программы update-alternatives. Она может делать в том числе и то, что мы сейчас проделали, только автоматически, в зависимости от своих настроек. С ее помощью можно более гибко управлять версиями, задавать приоритеты использования той или иной версии, быстро их переключать в полуавтоматическом режиме.

Источник

Change php cli version

WampServer PHP CLI Version Changer

WampServer PHP CLI Version Changer is a Microsoft Windows batch script that allows you to easily change between installed WampServer PHP CLI versions using the users environment ‘path’ variable.

The following are required for the CLI Changer script to function correctly.

No installation is required.

At just over 13KB the CLI Changer script is small enough to be saved anywhere in your file system.

Tip: Once you have save the CLI Changer script, create a desktop shortcut to it for quick and easy access.

No configuration is necessary if your installed WampServer in its default directory.

The default installation directories are:

If you installed WampServer in a custom directory, then follow the steps below:

Example: A customised WampServer install path.

IMPORTANT: Do not add quotation marks around your custom installation path, even if the path contains spaces.

There are two ways you can use the CLI Changer script.

Text Based User Interface (TUI)

Upon running the CLI Changer script you will be presented with a numbered list of installed PHP versions that you can select from.

The exact list of installed PHP CLI versions is dependent on what you currently have in your WampServer PHP addon folder.

If a PHP version has previously been set, it will display in the list as «Current».

To select a PHP version:

The CLI Changer script will display the newly set PHP version number and prompt you to press any key to exit.

Note: The newly selected PHP version will only be available to new command line windows. Existing windows will still reference the previously set PHP version.

Читайте также:  ростелеком город пугачев номер телефона

To exit the CLI Changer script without making any changes just press the ENTER key.

Should you make an invalid selection or should the selection be the same as the currently selected version then you will receive feedback indicating so.

Command Line Interface (CLI)

To update the PHP CLI version number directly from the command line, you can pass in the desired PHP version via the scripts first argument. This will bypass the selection screen and go straight to setting the desired version number.

From a Bash or Powershell prompt:

Note 1: You will need to enclose the CLI Changer script path in quotes if the path contains any spaces.

Note 2: You will need to know the available PHP CLI version(s) in advance prior to using this command.

Following execution, an exit code will be given:

Tip: Calling scripts via the command line is common during (automated) development, testing and deployment. EG: Incorporate it into your build files.

From a Bash or Powershell prompt:

Note: Enclosing the script path in quotes if it contains spaces and knowing the available PHP CLI version(s) in advance is still required.

Following execution, an exit code will be given:

What are environment path variables and how do they work?

Environment ‘path’ variables allow the user (and system) to call an executable without the need to use the executables absolute (full) path. Windows parses the path variables from left to right, with the ‘user’ path being appended to the ‘system’ path. (IE: path = system.path + user.path)

Based on this information and pursuant to the successful selection of a PHP version number, this script scans and then removes any and all reference to any php executable path(s) found within the environment ‘user’ path (or the cmd window ‘session’ path) prior to appending the selected PHP version path.

Access the environment ‘user’ and ‘system’ paths by:

How do I remove the error at the bottom of the WampServer right-click menu?

Clicking on this error will open a command window displaying the below message.

Why would you want to suppress this error?

Because currently, WampServer does not have the ability to change the CLI version of PHP should your script(s) require a specific version.

No, it doesn’t. This selection currently changes the CLI version that the WampServer’s scripts use, not what your scripts use when called from the command line.

So can I safely use this script?

Currently, yes (but this may change if WampServer decides in the future to begin using either or both of your systems environment path variables).

How do I add more PHP versions?

To add more PHP versions to your WampServer v3 installation visit SourceForge.

About

WampServer PHP CLI version changer is a Microsoft Windows batch script that allows you to easily add and then change between available WampServer PHP CLI versions using the users environment ‘path’ variable.

Читайте также:  причины микроангиопатии головного мозга сосудов

Источник

How can I change php-cli version on Ubuntu 14.04?

I am new to using Linux and I broke some php settings while tampering.

I want to have both versions match.
How can i fix my command line PATH to also use php 5.6?

7 Answers 7

From PHP 7.1 => PHP 5.6

From PHP 5.6 => PHP 7.1

You can change the versions as you want.

You can check this tutorial

This explanation is based on Ubuntu 16.04 but is expected to work for other versions too

Most answers here manipulate the php-version by using the command

While the command is quite useful it’s never explained what it does exactly. Here comes the explanation, including backup and some options:

Get the Information

Finally we still want to know which php-versions we can link. The following command shows a list of the currently available php-versions in /usr/bin/ :

Backup the information

if you like you still can add the result of the command ls like shown above:

. and the available PHP-versions:

Change the PHP-version for commandline

Control

Checking the change:

The change was accepted and the used version is an older one now.

This means the PHP-version is consistent with the man-page and the command man php returns the right descriptions for the current php-version and no manual adjustments concerning the man-page have been required.

Here is more interactive way:

You’ll see the list of all available versions and select one of them

You can try setting the path to the correct php version on the terminal command line:

Modify the path to match your own path to PHP 5.6 (ie. if it was installed first, it might be something like «/usr/bin/php»).

The «$PATH» at the end appends the current path value, so don’t forget to use it.

check what you have before changing

change everything to php 7.2

Plesk

Just to say, if your server is managed using Plesk (like mine is at the time of searching through this question) then you may not have later PHP versions in /usr/bin

In this case, your PHP versions will be located in /opt/plesk/php so you can instead use the following command as a super user (run su first if you’re not a super user) to set your PHP CLI version (to 7.3 in this example):

Источник

Changing default PHP CLI version

Access server

Eg. To run a script using the default version of PHP,

Eg. To execute a script using a specific version of PHP,

Domain group

The PHP version for a domain group is set via the Stacks page on https://my.sonassi.com, you can review which version is in use by either,

Checking the version by command line,

! Please note you will need the Stacks role in order to manage domain-groups and PHP Versions.

Displaying access server default PHP

You can view the default version by using the update-alternatives command,

Where you can see the current selected version,

Читайте также:  Vkdj что это такое

The final line shows which version is currently set as the default, in this case, it is PHP 5.4

Selecting access server default PHP

You can change the default PHP version by running,

From the dialog that appears, you can then go on to select the version of PHP that you would like to use by default,

You can see from the example above that PHP 5.4 is currently selected. To change to another version, just type the selection ID (left column) and press enter.

Eg. To change to PHP 5.5

You can now verify that the default PHP version is as selected,

! Please note that this will only change the version of PHP used when using the php command, if you need to change a domain-group’s PHP version then you can do this via the Stacks page on https://my.sonassi.com

Auto selecting PHP version based on domain-group

We have an article on how to implement an alias to automatically point to a domain-groups specific PHP version available: Here

Источник

Switch php versions on commandline ubuntu 16.04

I have installed php 5.6 and and php 7.1 on my Ubuntu 16.04

I know with Apache as my web server, I can do

When I disable php7.1 in Apache modules and enable php 5.6, Apache recognizes the change and uses php 5.6 interpreter as expected.

But when I run internal php web server from the commandline:

18 Answers 18

Interactive switching mode

Manual Switching

From PHP 5.6 => PHP 7.1

Default PHP 5.6 is set on your system and you need to switch to PHP 7.1.

From PHP 7.1 => PHP 5.6

Default PHP 7.1 is set on your system and you need to switch to PHP 5.6.

should work for all ubuntu versions after 16.04 (18.04 and 20.04)

This is what you should see as a response

Choose the appropriate version

To list all available versions and choose from them :

I think you should try this

From php5.6 to php7.1

From php7.1 to php5.6

You can create a script to switch from versions: sudo nano switch_php then type this:

exit and save make it executable: sudo chmod +x switch_php

That’s it you can now easily switch form PHP7 to PHP 5.6!

In that case you can switch between the PHP versions to suit your requirements.

Switch From PHP 5.6 => PHP 7.2

And vice-versa, Switch From PHP 7.2 => PHP 5.6

in ubuntu 20.04 switching between PHP 8.0 and PHP 7.4 version:

DOWNGRADE PHP 8.0 to PHP 7.4

UPGRADE PHP 7.4 to PHP 8.0

PHP 8.0.3 (cli) (built: Mar 5 2021 07:54:13) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.3, Copyright (c) Zend Technologies with Zend OPcache v8.0.3, Copyright (c), by Zend Technologies

PHP 7.4.16 (cli) (built: Mar 5 2021 07:54:38) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.16, Copyright (c), by Zend Technologies

Источник

Образовательный портал