Установка различных нетиповых версий PHP

PHP 5.6 on Ubuntu 16.04 (EN)

Remove all the stock php packages

List installed php packages with dpkg -l | grep php| awk '{print $2}' |tr "n" " " then remove unneeded packages with sudo aptitude purge your_packages_here or if you want to directly remove them all use :

sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "n" " "`

Add the PPA

sudo add-apt-repository ppa:ondrej/php

If you get add-apt-repository: command not found run the following command first :

sudo apt-get install software-properties-common

Install your PHP Version

sudo apt-get update
sudo apt-get install php5.6

You can install php5.6 modules too for example

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

Verify your version

If you have installed php5.6-cli

sudo php -v

If you don't have php5.6-cli, put this on a .php file


PHP 7.2 на Debian 9.4

sudo apt-get install apt-transport-https lsb-release ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt-get update
sudo apt-get install php7.2-cli

PHP 7.4 on Ubuntu 18.04/16.04 (EN)

For the other editions of Ubuntu, use the process below:

Step 1: Add PHP PPA Repository

We’ll add ppa:ondrej/php PPA repository which has the latest build packages of PHP.

sudo apt-get update
sudo apt -y install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

Step 2: Install PHP 7.4 on Ubuntu 18.04/19.04/16.04

Install PHP 7.4 on Ubuntu 18.04/19.04/16.04 using the command:

sudo apt -y install php7.4

PHP 7.4 на CentOS 7 (EN)


This is a short guide on how to Install PHP 7.4 on CentOS 7 Linux system. The PHP Version 7.4.0 has been released in stabilization phase for the developers, and for users to test. This is not recommended to be run in Production, until the stable version of PHP 7.4 is made available to the general public. The expected official release date is November 28, 2019.

For RHEL 8 / CentOS 8: How To Install PHP 7.4 on CentOS 8 / RHEL 8

PHP 7.4 comes with a remarkable amount of new features. This version is RPM are available in the remi-php74 repository for Fedora29 and Enterprise Linux7 (RHEL, CentOS) and as Software Collection in the remi-safe repository (or remi for Fedora).

Step 1: Add EPEL and REMI Repository

Run the commands below to add required repositories.

sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

Step 2: Install PHP 7.4

We can now enable PHP 7.4 Remi repository and install PHP 7.4 on CentOS 7.

sudo yum -y install yum-utils
sudo yum-config-manager --enable remi-php74

Install PHP 7.4 on CentOS 7.

sudo yum update
sudo yum install php php-cli

Accept installation prompt.

Dependencies Resolved
Total                                       1.1 MB/s |  34 MB  00:31     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Importing GPG key 0x00F97F56:
 Userid     : "Remi Collet <RPMS@FamilleCollet.com>"
 Fingerprint: 1ee0 4cce 88a4 ae4a a29a 5df5 004e 6f47 00f9 7f56
 Package    : remi-release-7.7-1.el7.remi.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Is this ok [y/N]: y

Use the next command to install additional packages:

sudo yum install php-xxx


sudo yum install php  php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json

The current PHP version should be 7.4.

$ php -v
PHP 7.4.0 (cli) (built: Nov 26 2019 20:13:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

To view enabled modules, run:

$ php --modules

You have successfully installed PHP 7.4 on CentOS 7.

PHP 7.4 на Centos 7 (RU)

Подключаем репозиторий EPEL:

sudo yum install epel-release

Установим программу wget. Она нужна нам для скачивания репозитория Remi.

sudo yum install wget

Теперь установим репозиторий Remi

wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Устанавливаем репозиторий:

sudo rpm -Uvh remi-release-7*.rpm

Так же установим yum-utils, что бы мы могли воспользоваться yum-config-manager.

sudo yum install yum-utils

Так как в репозитории много версий php нужно указать конкретную версию.

sudo yum-config-manager --enable remi-php74

Устанавливаем Php:

sudo yum install php74

Вот и все, но обычно для сайтов нужны еще дополнительные пакеты, для работы с другими программами или функциями сайта.

Приведу пример основных пакетов:

sudo yum install php-intl php-mcrypt php-json php-cli php-mysql php-gd php-ldap php-odbc php-pdo php-pecl-memcache php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap php-zip

Если вы используете только nginx, то для него нужет еще пакет php-fpm

sudo yum install php-fpm

php-fpm нужно запускать. Для этого прописываем:

sudo systemctl start php-fpm 

Для того, что бы php-fpm сам запускался после перезагрузки прописываем:

sudo systemctl enable php-fpm