Включение php на debian

How To Install PHP (8.2, 7.4 & 5.6) on Debian 11

PHP abbreviated as “HyperText Processor”, is the open-source programming language used for Web application development. It is a scripting language, mostly used for the front end with HTML. It can be used to create e-commerce websites, manage databases, and do session monitoring.

It is available for all OS. The latest version of PHP is version 8 and in this article, we will discuss the installation of PHP on the Debian 11 (Bullseye) Linux system.

Prerequisites

First, update all the packages of the system by below-mentioned command:

After updating packages, now install the dependencies required by the below-mentioned command:

sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https 

Step 1 – Enable SURY Repository

The following step is to integrate the SURY repository into our system. SURY is a Debian-based third-party PHP repository that bundles PHP software, run the following command to add SURY repository:

sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' 

Importing the GPG key for the repository by the below-mentioned command:

wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add - 

Step 2 – Installing PHP on Debian 11

Now again update packages for syncing them with the recently added SURY repository before installing php:

Читайте также:  Array rand php примеры

The SURY repository contains PHP 8.2, 8.1, 8.0, 7.4, 7.3, 7.2. 7.1, 7.0 & PHP 5.6. As the latest stable version of PHP is 8.0, but a large number of websites still required PHP 7. You can install any of the required PHP versions on your system.

Replace version 8.2, 7.4 or 5.6 with the required PHP version to install on your Debian system. Even you can install multiple PHP versions on a single Debian system.

Step 3 – Installing PHP Extension

Moreover, we can also add the php extension by below-mentioned syntax:

sudo apt install php8.1-[extension]

Replace [extension] with the extension you want to install, if you want to add multiple extensions then include them in braces, I am going to install “php-mbstring, php-cli, php-xml, php-common, and php-curl” by running the below-mentioned command:

sudo apt install php8.2-cli php8.2-mbstring php8.2-xml php8.2-common php8.2-curl 

Users have installed different PHP version, need to replace 8.2 with required PHP versions.

Step 4 – Checking PHP Version

Now after installation verify that the correct version of PHP is installed by checking the version number by the below-mentioned command:

Output:
PHP 8.2.1 (cli) (built: Jan 13 2023 10:43:08) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.1, Copyright (c) Zend Technologies with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies

Step 5 – Switch Between PHP Versions

You can use update-alternatives command to set the default PHP version. Use this tutorial to read more details about switching PHP version for CLI and Apache.

sudo update-alternatives --config php 
There are 4 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/php8.1 81 auto mode 1 /usr/bin/php5.6 56 manual mode 2 /usr/bin/php7.2 72 manual mode 3 /usr/bin/php7.4 74 manual mode 4 /usr/bin/php8.1 81 manual mode 5 /usr/bin/php8.2 82 manual mode Press to keep the current choice[*], or type selection number: 4

The above output shows all the installed PHP versions on your system. Input a selection number to set default PHP version for command line.

Conclusion

PHP is a free, server-side programming language also used with HTML programming language for creating dynamic websites. It is available for all operating systems but in this article, we discuss its installation on Debian 11 (Linux OS) Bullseye. You will successfully install PHP on Debian 11 after going through this guide.

Источник

Установка PHP и модулей на Ubuntu/Debian

В Debian и Ubuntu есть несколько вариантов работы php: как модуль apache и как php-fpm. Первый вариант удобен тем, кому придется использовать не только сам PHP, но и возможности Apache, такие как .htaccess. Второй же вариат удобен например для Yii или Laravel.

Установка PHP 5 как модуля Apache:

apt-get update apt-get install libapache2-mod-php5 php5-cli php5-memcache php5-memcached php5-mysql php5-pgsql php5-curl php5-gd php5-imagick php5-intl php5-mcrypt

Установка PHP 7 как модуля Apache:

apt-get update apt-get install libapache2-mod-php7.0 php7.0-curl php7.0-cli php-memcache php-memcached php7.0-mysql php7.0-pgsql php7.0-gd php7.0-imagick php7.0-intl php7.0-mcrypt

Установка PHP 5 как PHP-FPM:

apt-get update apt-get install php5-fpm php5-cli php5-memcache php5-memcached php5-mysql php5-pgsql php5-curl php5-gd php5-imagick php5-intl php5-mcrypt

Установка PHP 7 как PHP-FPM

apt-get update apt-get install php7.0-fpm php7.0-curl php7.0-cli php-memcache php-memcached php7.0-mysql php7.0-pgsql php7.0-gd php7.0-imagick php7.0-intl php7.0-mcrypt

В Debian и Ubuntu зачастую установка модулей PHP не требует каких-то сложных манипуляций. Для того, чтобы посмотреть, что Вы можете поставить прямо сейчас, нужно сделать:

lynx@lnxdsk:~$ apt-cache search php7.0 php-amqp - AMQP extension for PHP php-apcu - APC User Cache for PHP php-all-dev - package depending on all supported PHP development packages php-gearman - PHP wrapper to libgearman php-geoip - GeoIP module for PHP php-gmagick - Provides a wrapper to the GraphicsMagick library php-gnupg - PHP wrapper around the gpgme library php-igbinary - igbinary PHP serializer php-imagick - Provides a wrapper to the ImageMagick library php-libsodium - PHP wrapper for the Sodium cryptographic library php-mailparse - Email message manipulation for PHP php-memcache - memcache extension module for PHP php-memcached - memcached extension module for PHP, uses libmemcached php-mongodb - MongoDB driver for PHP php-msgpack - PHP extension for interfacing with MessagePack php-oauth - OAuth 1.0 consumer and provider extension php-http - PECL HTTP module for PHP Extended HTTP Support php-pinba - Pinba module for PHP php-propro - propro module for PHP php-radius - radius client library for PHP php-raphf - raphf module for PHP php-redis - PHP extension for interfacing with Redis php-rrd - PHP bindings to rrd tool system php-smbclient - PHP wrapper for libsmbclient php-solr - PHP extension for communicating with Apache Solr server php-ssh2 - Bindings for the libssh2 library php-stomp - Streaming Text Oriented Messaging Protocol (STOMP) client module for PHP php-uploadprogress - file upload progress tracking extension for PHP php-uuid - PHP UUID extension php-yac - YAC (Yet Another Cache) for PHP php-yaml - YAML-1.1 parser and emitter for PHP php-zmq - ZeroMQ messaging bindings for PHP php7.0 - server-side, HTML-embedded scripting language (metapackage) php7.0-bcmath - Bcmath module for PHP php7.0-bz2 - bzip2 module for PHP php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary) php7.0-cli - command-line interpreter for the PHP scripting language php7.0-common - documentation, examples and common module for PHP php7.0-curl - CURL module for PHP php7.0-dba - DBA module for PHP php7.0-dev - Files for PHP7.0 module development php7.0-enchant - Enchant module for PHP php7.0-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php7.0-gd - GD module for PHP php7.0-gmp - GMP module for PHP php7.0-imap - IMAP module for PHP php7.0-interbase - Interbase module for PHP php7.0-intl - Internationalisation module for PHP php7.0-json - JSON module for PHP php7.0-ldap - LDAP module for PHP php7.0-mbstring - MBSTRING module for PHP php7.0-mcrypt - libmcrypt module for PHP php7.0-mysql - MySQL module for PHP php7.0-odbc - ODBC module for PHP php7.0-opcache - Zend OpCache module for PHP php7.0-pgsql - PostgreSQL module for PHP php7.0-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary) php7.0-pspell - pspell module for PHP php7.0-readline - readline module for PHP php7.0-recode - recode module for PHP php7.0-snmp - SNMP module for PHP php7.0-soap - SOAP module for PHP php7.0-sqlite3 - SQLite3 module for PHP php7.0-sybase - Sybase module for PHP php7.0-tidy - tidy module for PHP php7.0-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP php7.0-xmlrpc - XMLRPC-EPI module for PHP php7.0-xsl - XSL module for PHP (dummy) php7.0-zip - Zip module for PHP

Давайте для примера установим GD для работы с изображениями:

lynx@lnxdsk:~$ sudo apt-get install php7.0-gd Чтение списков пакетов… Готово Построение дерева зависимостей Чтение информации о состоянии… Готово Заметьте, вместо «php7.0-gd» выбирается «php-gd» НОВЫЕ пакеты, которые будут установлены: php-gd обновлено 0, установлено 1 новых пакетов, для удаления отмечено 0 пакетов, и 148 пакетов не обновлено. Необходимо скачать 350 kБ архивов. После данной операции, объём занятого дискового пространства возрастёт на 1 493 kB. Пол:1 http://mirror.mephi.ru/debian stretch/main amd64 php-gd amd64 2.5.0-1 [350 kB] Получено 350 kБ за 0с (2 266 kБ/c) Выбор ранее не выбранного пакета php-gd. (Чтение базы данных … на данный момент установлено 61175 файлов и каталогов.) Подготовка к распаковке …/php-gd_2.5.0-1_amd64.deb … Распаковывается php-xdebug (2.5.0-1) … Настраивается пакет php-xdebug (2.5.0-1) … После установки нам нужно перезапустить apache (эти примеры я показываю от пользователя root):
root@lnxdsk:~# service apache2 restart

Либо php-fpm, смотря, что используете Вы:

root@lnxdsk:~# service php7.0-fpm restart

Чтобы посмотреть список модулей php, который прямо сейчас подключен, можно запустить:

lynx@lnxdsk:~$ php -m [PHP Modules] bcmath bz2 calendar Core ctype curl date dba dom ereg exif fileinfo filter ftp gd gettext hash iconv intl json libxml mbstring mhash mysql mysqli openssl pcntl pcre PDO pdo_mysql pdo_pgsql pgsql Phar posix readline Reflection session shmop SimpleXML soap sockets SPL standard sysvmsg sysvsem sysvshm tokenizer wddx xdebug xml xmlreader xmlwriter Zend OPcache zip zlib [Zend Modules] Xdebug Zend OPcache

Nginx, Php-Fpm и что это вообще?

Что такое php-fpm и зачем он нужен более-менее посещаемым проектам? Какие неприятности несет в себе переход с apache на fpm? Какие проблемы решает реально, а какие — надуманно?

Почему timeout для curl в php необходим

Использование cURL в PHP имеет свою не очень приятную особенность — вечная блокировка процесса

Угадайте самый медленный фреймворк. И это не Laravel

Есть распространенное мнение, что Laravel почти самый медленный фреймворк, что даже его название нужно читать медленно и только одним пользователем на 1 ядро CPU. Но к счастью, это не так

Curl в PHP

Curl — это библиотека для работы с URL. Она интегрирована во множество языков, в том числе и в PHP.

Сессии в PHP — часть первая для Чайников

Вводная статья о том, как использовать сессии в PHP

Источник

Оцените статью