How to update my PHP to latest version by entering through SSH on my server

I need to update my PHP to latest version, but I'm not getting, currently it is in version 5.5.9, I would like to leave it in the latest version, so I can install Laravel.

I tried using Php7 apt-get command but gave error.

  • How do I quit PHP 5.5.9
  • How do I install PHP 7.3 + ?

Note: I'm wanting to update, why according to this video ( https://www.youtube.com/watch?v=iPTxznidNHo&list=PLVSNL1PHDWvR3PeLXz6nvBkDhv1IQk4wP ) it leaves the latest version, but when I get on github of it the installation comes with the old version of PHP.

Edit: I used the command sudo apt install php7.3 and gave this following message:

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php7.3
E: Couldn't find any package by regex 'php7.3'

Then I use the command sudo update-alternatives --set php /usr/bin/php7.2 and the result is:

update-alternatives: error: alternative /usr/bin/php7.2 for php not registered; not setting

I tried restarting Apache2 to check if it was, but to no avail.

Edit2: I ran the command: sudo apt update && apt upgrade and returned:

Hit http://ppa.launchpad.net trusty InRelease
Ign http://archive.ubuntu.com trusty InRelease
Hit http://security.ubuntu.com trusty-security InRelease
Hit http://archive.ubuntu.com trusty-updates InRelease
Hit http://security.ubuntu.com trusty-security/main Sources
Hit http://archive.ubuntu.com trusty-backports InRelease
Hit http://ppa.launchpad.net trusty/main amd64 Packages
Hit http://security.ubuntu.com trusty-security/universe Sources
Hit http://archive.ubuntu.com trusty Release.gpg
Hit http://security.ubuntu.com trusty-security/main amd64 Packages
Hit http://archive.ubuntu.com trusty-updates/main Sources
Hit http://ppa.launchpad.net trusty/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe amd64 Packages
Hit http://archive.ubuntu.com trusty-updates/restricted Sources
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://archive.ubuntu.com trusty-updates/universe Sources
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Hit http://archive.ubuntu.com trusty-updates/multiverse Sources
Hit http://archive.ubuntu.com trusty-updates/main amd64 Packages
Hit http://archive.ubuntu.com trusty-updates/restricted amd64 Packages
Hit http://archive.ubuntu.com trusty-updates/universe amd64 Packages
Hit http://archive.ubuntu.com trusty-updates/multiverse amd64 Packages
Hit http://archive.ubuntu.com trusty-updates/main Translation-en
Hit http://archive.ubuntu.com trusty-updates/multiverse Translation-en
Hit http://archive.ubuntu.com trusty-updates/restricted Translation-en
Hit http://archive.ubuntu.com trusty-updates/universe Translation-en
Hit http://archive.ubuntu.com trusty-backports/main Sources
Hit http://archive.ubuntu.com trusty-backports/restricted Sources
Hit http://archive.ubuntu.com trusty-backports/universe Sources
Hit http://archive.ubuntu.com trusty-backports/multiverse Sources
Hit http://archive.ubuntu.com trusty-backports/main amd64 Packages
Hit http://archive.ubuntu.com trusty-backports/restricted amd64 Packages
Hit http://archive.ubuntu.com trusty-backports/universe amd64 Packages
Hit http://archive.ubuntu.com trusty-backports/multiverse amd64 Packages
Hit http://archive.ubuntu.com trusty-backports/main Translation-en
Hit http://archive.ubuntu.com trusty-backports/multiverse Translation-en
Hit http://archive.ubuntu.com trusty-backports/restricted Translation-en
Hit http://archive.ubuntu.com trusty-backports/universe Translation-en
Hit http://archive.ubuntu.com trusty Release
Hit http://archive.ubuntu.com trusty/main Sources
Hit http://archive.ubuntu.com trusty/restricted Sources
Hit http://archive.ubuntu.com trusty/universe Sources
Hit http://archive.ubuntu.com trusty/multiverse Sources
Hit http://archive.ubuntu.com trusty/main amd64 Packages
Hit http://archive.ubuntu.com trusty/restricted amd64 Packages
Hit http://archive.ubuntu.com trusty/universe amd64 Packages
Hit http://archive.ubuntu.com trusty/multiverse amd64 Packages
Hit http://archive.ubuntu.com trusty/main Translation-en
Hit http://archive.ubuntu.com trusty/multiverse Translation-en
Hit http://archive.ubuntu.com trusty/restricted Translation-en
Hit http://archive.ubuntu.com trusty/universe Translation-en
Ign http://archive.ubuntu.com trusty/main Translation-en_US
Ign http://archive.ubuntu.com trusty/multiverse Translation-en_US
Ign http://archive.ubuntu.com trusty/restricted Translation-en_US
Ign http://archive.ubuntu.com trusty/universe Translation-en_US
Reading package lists... Done
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) // -> Não tenho permissão?!
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

After not having succession I executed the other commands:

Sudo add-apt-repository ppa: ondrej/php

Return:

 Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.

Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa

You can get more information about the packages at https://deb.sury.org

BUGS&FEATURES: This PPA now has a issue tracker:
https://deb.sury.org/#bug-reporting

CAVEATS:
1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
2. If you are using apache2, you are advised to add ppa:ondrej/apache2
3. If you are using nginx, you are advise to add ppa:ondrej/nginx-mainline
   or ppa:ondrej/nginx

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/

WARNING: add-apt-repository is broken with non-UTF-8 locales, see
https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:

# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
 More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmpdyam2xwj/secring.gpg' created
gpg: keyring `/tmp/tmpdyam2xwj/pubring.gpg' created
gpg: requesting key E5267A6C from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpdyam2xwj/trustdb.gpg: trustdb created
gpg: key E5267A6C: public key "Launchpad PPA for Ondřej Surý" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

After all this process, I executed the last remaining Command:

sudo apt install php7.3 php7.3-cli php7.3-common

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php7.3
E: Couldn't find any package by regex 'php7.3'
E: Unable to locate package php7.3-cli
E: Couldn't find any package by regex 'php7.3-cli'
E: Unable to locate package php7.3-common
E: Couldn't find any package by regex 'php7.3-common'

But there was no succession of commands...

Author: Devprogramacao, 2019-05-16

1 answers

I had this same problem when trying to upgrade to version 7.2.

When you run the command sudo update-alternatives --help you have a list of available commands and among them the command --install which has the following syntax:

sudo update-alternatives --install <link> <nome> <caminho> <prioridade>

Where:

  • <link> is a symbolic link that points to/etc/alternatives / <nome>.
  • <nome> is a master name for this link group, in this case php.
  • <caminho> is the location of one of the target files of the alternative, in my case the path is/usr / bin / php7.2.
  • <prioridade> is an integer; options with larger numbers have higher priority in automatic mode.

In my case the command looked like this:

sudo update-alternatives --install /usr/bin/php php /usr/bin/php7.2 72

This last number could be any number, I only chose 72 to match the php version.

After performing these steps, if you run sudo update-alternatives --config php you will see more than one php option installed, and you can choose which option simply by choosing the number referring to the option displayed in the listing.

Example:

  Selecção   Caminho          Prioridade Estado
------------------------------------------------------------
  0            /usr/bin/php7.4   74        modo automático
  1            /usr/bin/php7.1   71        modo manual
* 2            /usr/bin/php7.2   72        modo manual
  3            /usr/bin/php7.4   74        modo manual

Press <enter> to keep the current choice[*], or type selection number: 

Hope I helped!

 0
Author: Josué Barros da Silva, 2020-07-10 02:18:42