A long ago, I wrote about how to upgrade to 7.0. PHP 7.2 is released. Now, it’s the time again to upgrade to the new version.
The latest version of PHP comes with a couple of changes
- Convert numeric keys in object/array casts
- Counting of non-countable objects
- Object typehint
- HashContext as Object
- Argon2 in password hash
- Improve TLS constants to sane values
- Mcrypt extension removed
- New sodium extension
More details: http://php.net/releases/7_2_0.php
Even it’s your first time, just follow the following steps. First, update your system.
sudo apt-get update
sudo apt-get install python-software-properties
Second, add Ondřej’s PPA to the system’s Apt sources:
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
Update your local package cache again
sudo apt-get update
Now Install PHP 7.2
sudo apt-get install php7.2
In order to version check, run: php -v
You also need to install some modules
sudo apt-get install libapache2-mod-php7.2 php7.2-cgi php7.2-cli php7.2-common php7.2-curl php7.2-gd php7.2-imap php7.2-intl php7.2-json php7.2-ldap php7.2-mbstring php7.2-mysql php7.2-opcache php7.2-pspell php7.2-readline php7.2-soap php7.2-xml php7.2-zip
One more module for Nginx server
sudo apt-get install php7.2-fpm
Attention:
You can ignore the following steps if you install PHP 7.2 for first time.
For Nginx Server
Update the unix socket path at default configuration as well as other configurations.
/var/run/php/php7.2-fpm.sock
estart the Nginx server
sudo service nginx restart
For Apache server
You need to disable the old version on Apache and tell Apache to use PHP 7.2.
sudo a2dismod php7.0
sudo a2enmod php7.2
Restart the Apache server
sudo /etc/init.d/apache2 restart
Now, you can remove the old version.
sudo apt-get install ppa-purge
sudo apt-get purge php7.0-common
Happy hacking 🙂