Can't update from php 5.5.12 - Ubuntu 16.04 - php

I'm trying to update php. When I check my php version, it returns:
php -v
PHP 5.5.12 (cli) (built: Mar 10 2017 16:27:17)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
So I added ondrej's repository
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.0
But STILL:
php -v
PHP 5.5.12 (cli) (built: Mar 10 2017 16:27:17)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
I don't know what to do anymore... Already tried purge, everything... this php doesn't upgrade, it remains this version. Any ideas?

If you have this problem while upgrading from PHP5 to PHP7 on Ubuntu 16.04
with Apache, here's what helped me (credit goes here):
Disable PHP5 module on Apache:
sudo a2dismod php5
Now enable PHP7:
sudo a2enmod php7.1
To reflect changes Apache restart is required:
sudo systemctl restart apache2
By the way run phpinfo() in your script take a look which version is this running. Command line php is a complete separate system

Try to run First :
sudo apt-get upgrade
And then : For PHP 5.5, PHP 5.6 and PHP 7.0:
sudo apt-add-repository ppa:ondrej/php
You have flipped "apt" and "add". Please take a look at your command.
Then the other steps that you made.

Related

How do I change the default PHP base-version on shell?

I have Centos 7 and Virtualmin installed, with the tipycal php-fpm 5.4, 7.0, 7.1 that you can choice between the versions you prefer on every virtualhost via Virtualmin control panel, and everything works well.
But when I access to the server via SSH and check php -v I get this:
PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
How can I select another php default/base version for the shell system?
When you issue the php command on the shell it uses the default php version on the server which in your case is php-5.4.16
To use another php version, you have to check where the binaries for those php versions are and invoke them with their full path rather than just typing php.
For example, on CentOS, for PHP 7.2 for example, the full path of the php binary is: /opt/rh/rh-php72/root/usr/bin/php
root#virtualmin /root
» /opt/rh/rh-php72/root/usr/bin/php -v
PHP 7.2.24 (cli) (built: Nov 4 2019 10:23:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend Technologies
Install versions of PHP in centos 7
Setup Yum Repository
First of all, you need to enable Remi and EPEL yum repositories on your system. Use the following command to install EPEL repository on your CentOS and Red Hat 7/6 systems
Use this command to install EPEL yum repository on your system
sudo yum install epel-release
and now execute one of the following commands as per your operating system version to install the Remi repository.
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Install PHP 7 on CentOS
Your system is prepared for the PHP installation from yum repositories. Use one of the following commands to install PHP 7.4 or PHP 7.3 or PHP 7.2 or PHP 7.1 on your system based on your requirements.
Install PHP 7.4
yum --enablerepo=remi-php74 install php
Install PHP 7.3
yum --enablerepo=remi-php73 install php
Install PHP 7.2
yum --enablerepo=remi-php72 install php
.
Check version PHP install
php -v
.
PHP 7.4.1 (cli) (built: Dec 17 2019 16:35:58) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Install PHP Modules
You may also need to install additional PHP modules based on your application requirements. The below command will install some more useful PHP modules.
For PHP 7.4
yum --enablerepo=remi-php74 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
For PHP 7.3
yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
For PHP 7.2
yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

Update PHP from 5.5.7 to 7. on CentOS7

I tried many times to update PHP from 5.5 to 7 on CentOS 7 but always unsuccessful. The installation seems always going well but when I checked php-v it is always:
PHP 5.5.7 (cli) (built: Jul 5 2017 12:03:23)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
Any idea how can I update?
Base repository of CentOS has no php7 packages.
You can use remi repo to install php7 on your CentOS 7.
Why Remi?
PHP package installed from remi repo will work as drop-in replacement for your current php5 binaries.
Remi repo is managed by one of PHP internals
Why not?
To install the Remi repository, we need to enable the EPEL repository first.
sudo yum install epel-release yum-utils
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Then Enable php 7.0 (You can use php 7.1+ too)
sudo yum-config-manager --enable remi-php70
Now it's time to install php7
yum install php php-common php-cli php-mysql
Great!!!
Now you have php7 on your system. You can confirm with :
php -v
Details Instruction on how to setup php on different OS : https://rpms.remirepo.net/wizard/

Xdebug Ubuntu 18.04 and PHP 7.2

I just updated Ubuntu to version 18.04 and I have version 7.2 of PHP, if I execute the command "php -v" I get this result
root#laptop1:/etc/apache2/sites-enabled# php -v
PHP 7.2.3-1ubuntu1 (cli) (built: Mar 14 2018 22:03:58) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.3-1ubuntu1, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
root#laptop1:/etc/apache2/sites-enabled#
However, if I run the phpinfo() command inside a php file through a web browser I get the following: it tells me that I have version 7.1 of PHP and that I do not have the Xdebug activated.
For this reason Xdebug does not work with my PhpStorm IDE; I do not know if the best option is to delete all the PHP versions installed and leave one that is not as recent as 7.0 or 7.1.
There is a difference between what version of PHP you use in your terminal and what version your web-server (in example apache2) is using. If you have apache2, you can change the version of PHP to 7.2 with the following commands:
Dissable PHP 7.1:
sudo a2dismod php7.1
Enable PHP 7.2:
sudo a2enmod php7.2
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.2-fpm
After that restart apache2:
sudo service apache2 restart

PHP 5 Upgrade On Ubuntu Not Working With Magento

I had an outdated version of PHP on my system, so attempted to upgrade from 5.5.9 to 5.6.
I followed the following steps on my Digital Ocean Ubuntu droplet:
I installed Ondřej Surý's PPA and selected 5.6 as well as other packages related to the main one, like the XML package.
When I do php -v on my server, it says
PHP 5.6.29-1+deb.sury.org~trusty+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
This indicated to me that the update went through.
But when I restart my apache server and check the error logs, it says
Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.20 configured -- resuming normal operations
I believe the latest version of Magento on my server is giving me this error (HTTP 500) because it is using the wrong version of PHP...
How do I fix this? Thank you.
The digital ocean community site here offered a couple of extra commands:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6 php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml
sudo a2dismod php5
sudo a2enmod php5.6
sudo service apache2 restart
Note the a2dismod and a2enmod steps. The post says:
Without the a2dismod/a2ensmod steps, Apache will continue to see your older version of PHP, even if command line is seeing the new version.

Vagrantfile PHP v5.6 specified but v5.5 installed

I have a Vaprobash VagrantFile building a Ubuntu Nginx stack.
In it I specify PHP v5.6:
php_version = "5.6" //Options: 5.5 | 5.6
However, I run
$ vagrant up
when I ssh into the box and do
$ php -v
it shows PHP 5.5.9-1ubuntu4.20 (cli) (built: Oct 3 2016 13:00:37).
Why wasn't 5.6 installed?
I am not sure this repo has been updated for php after the ppa has been migrated (see https://github.com/oerdnj/deb.sury.org/wiki/PPA-migration-to-ppa:ondrej-php)
basically in scripts/php.sh you need to replace ppa by
sudo add-apt-repository ppa:ondrej/php
(make sure to run sudo apt-get update if you're running this command directly from the VM after the initial provisioning) -
and to install php5.6 you need to run
sudo apt-get install -qq libapache2-mod-php5.6
with this change, you now get
vagrant#vaprobash:~$ php -v
PHP 5.6.28-1+deb.sury.org~trusty+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
If you need additional php modules, make sure to replace the installation by specifying 5.6 in your php version such as
sudo apt-get install -qq php5.6-fpm

Categories