How to downgrade PHP

Using an example, I will downgrade PHP in Ubuntu 18.04, in which version 7.2 is installed by default. I do not recommend downgrading PHP, since newer versions are more productive and close vulnerabilities, but there are times when you need to run an old script or engine that does not work on newer versions of PHP, and it is very difficult to fix the code due to the fact that there are a lot of files.

Continue reading “How to downgrade PHP”

Solution PHP Notice: Use of undefined constant x — assumed ‘x’

I once noticed the following notification when writing a PHP script:

PHP Notice:  Use of undefined constant uid - assumed 'uid' in /scripts/file.php on line 31
PHP Notice:  Use of undefined constant value - assumed 'value' in /scripts/file.php on line 32

Continue reading “Solution PHP Notice: Use of undefined constant x — assumed ‘x’”

Upgrading PHP Version on Ubuntu 14.04

Once it was necessary to upgrade the version of PHP 5.5.9 to 5.6 on Ubuntu Server 14.04 LTS, the usual update of the system components did not help:

sudo apt-get update
sudo apt-get upgrade

You can try to upgrade the system to 16.04 or higher as I described in the article Updating Ubuntu 14.04 to 16.04. Together with the system will be updated and PHP.

If the system update fails, you can add a third-party source with PHP:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

And install the correct version from it, for example PHP 5.6:

sudo apt-get install php5.6 php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml

Since there are several installed versions, disable the old version and activate the installed one:

sudo a2dismod php5
sudo a2enmod php5.6
sudo service apache2 restart

Similarly, you can install PHP 7.2:

sudo apt-get install php7.2
sudo a2dismod php5.6
sudo a2enmod php7.2
sudo service apache2 restart

Or PHP 7.0:

sudo apt-get install php7.0
sudo a2dismod php7.2
sudo a2enmod php7.0
sudo service apache2 restart