- How To Install PHP 8.2 on Debian 11 / Debian 10
- Install PHP 8.2 on Debian 11 / Debian 10
- 1. Add Sury PPA repository
- 2. Install PHP 8.2 packages on Debian 11 / Debian 10
- 3. Install PHP 8.2 extensions on Debian 11 / Debian 10
- 4. Using PHP with Nginx / Apache web server
- Using PHP 8.2 with Nginx
- Using PHP 8.2 with Apache
- 5. Removing Old PHP and extensions
- Conclusion
- Установить php linux debian
- Использование APT
- Контроль конфигурации
- Стандартные проблемы
- User Contributed Notes 6 notes
How To Install PHP 8.2 on Debian 11 / Debian 10
PHP is a language used to develop websites and web-based applications. It is well-suited for creation of interactive web pages which are dynamic in nature and can be embedded directly into HTML code. The execution of PHP code happens in the server while the output is sent to the client’s browser as plain HTML. PHP enjoys a large and active community of developers who have created frameworks and libraries that can be used to quickly and easily create web applications.
- Readonly Classes – When a class is declared as readonly , all of its properties are automatically declared readonly
- Type System Improvements– Added support for true type, and allowing null and false types to be used as stand-alone types, and support for DNF types.
- New random extension– Provides a new OOP API to generate random numbers with a pluggable architecture.
- Constants in Traits – In PHP 8.2, it is now possible to declare constants in traits.
- Sensitive Parameter Value Redaction – Addition of new built-in parameter Attribute named #[\SensitiveParameter] that PHP makes sure to redact the actual value in stack traces and error messages.
- New Functions and Classes – ini_parse_quantity function, curl_upkeep function , openssl_cipher_key_length , memory_reset_peak_usage
- Dynamic Properties Deprecated – PHP 8.2 deprecates class properties that are dynamically declared
- utf8_encode and utf8_decode Functions Deprecated
Install PHP 8.2 on Debian 11 / Debian 10
In this section we will cover installation process of PHP 8.2 on Debian 11 (Bullseye) and Debian 10 (Buster) Linux system.
1. Add Sury PPA repository
We start by adding PPA that contains the latest PHP packages. Install dependency packages for this.
sudo apt update sudo apt install lsb-release apt-transport-https ca-certificates software-properties-common -y
With the tools added let’s import repository GPG key.
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
Then add the repository to your sources list.
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
Update the package list to validate its functionality.
$ sudo apt update Hit:1 http://mirror.hetzner.com/debian/packages bullseye InRelease Hit:2 http://mirror.hetzner.com/debian/packages bullseye-updates InRelease Hit:3 http://mirror.hetzner.com/debian/security bullseye-security InRelease Hit:4 http://deb.debian.org/debian bullseye InRelease Hit:5 http://security.debian.org/debian-security bullseye-security InRelease Hit:6 http://deb.debian.org/debian bullseye-updates InRelease Get:7 https://packages.sury.org/php bullseye InRelease [6,841 B] Get:8 https://packages.sury.org/php bullseye/main amd64 Packages [376 kB] Fetched 383 kB in 2s (245 kB/s) Reading package lists. Done Building dependency tree. Done Reading state information. Done
2. Install PHP 8.2 packages on Debian 11 / Debian 10
Once the repository has been added and confirmed to be working we can now install PHP 8.2 on Debian 11 / Debian 10. Run the commands below to perform the installation.
$ sudo apt install php8.2 Reading package lists. Done Building dependency tree. Done Reading state information. Done The following additional packages will be installed: apache2-bin libapache2-mod-php8.2 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgdbm-compat4 liblua5.3-0 libpcre2-8-0 libperl5.32 libsodium23 perl perl-modules-5.32 php-common php8.2-cli php8.2-common php8.2-opcache php8.2-readline psmisc Suggested packages: apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make libtap-harness-archive-perl Recommended packages: apache2 The following NEW packages will be installed: apache2-bin libapache2-mod-php8.2 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgdbm-compat4 liblua5.3-0 libperl5.32 libsodium23 perl perl-modules-5.32 php-common php8.2 php8.2-cli php8.2-common php8.2-opcache php8.2-readline psmisc The following packages will be upgraded: libpcre2-8-0 1 upgraded, 19 newly installed, 0 to remove and 16 not upgraded. Need to get 14.1 MB of archives. After this operation, 76.0 MB of additional disk space will be used. Do you want to continue? [Y/n] y
Run the following command to check the version of PHP currently installed on your Debian system.
$ php -v PHP 8.2.4 (cli) (built: Mar 16 2023 14:37:38) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.4, Copyright (c) Zend Technologies with Zend OPcache v8.2.4, Copyright (c), by Zend Technologies
3. Install PHP 8.2 extensions on Debian 11 / Debian 10
PHP 8.2 extensions are libraries created to provide extra functionality to the PHP programming language not available natively.
See below example that demonstrates the installation of cli,zip,mysql,bz2,curl,mbstring,intl,common PHP modules.
Any other module can be installed using the command syntax:
Where is replaced with the name of PHP module to be installed.
4. Using PHP with Nginx / Apache web server
You can use PHP with either Nginx or Apache web server to create your dynamic and interactive web pages.
Using PHP 8.2 with Nginx
With Nginx, PHP code is typically executed by a separate process, such as PHP-FPM (FastCGI Process Manager). PHP-FPM is a daemon that listens for incoming PHP requests and runs them in a separate process. Nginx acts as a reverse proxy, forwarding incoming requests to PHP-FPM to be executed.
You’ll need to install both Nginx and PHP-FPM
sudo apt install nginx php8.2-fpm
Once Nginx and FPM extension are installed, you’ll need to configure Nginx to forward incoming requests to PHP-FPM, using the FastCGI protocol. Edit the Nginx configuration file and add the following block inside the http block to configure Nginx to forward PHP requests to PHP-FPM:
$ sudo vim /etc/nginx/nginx.conf server < listen 80; server_name mysite.example.com; root /var/www/mysite; index index.php index.html; location ~ \.php$ < include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; > >
Verify Nginx configuration after making the change:
$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Using PHP 8.2 with Apache
When Apache web server PHP code is typically executed using the mod_php module, which is built into Apache. The mod_php is an Apache module responsible for processing PHP code directly within the Apache process.
Install both Apache and PHP, and any other necessary PHP extensions:
sudo apt install apache2 libapache2-mod-php8.2
Next enable mod_php module which allows Apache to process PHP code:
Restart Apache web server
sudo systemctl restart apache2
5. Removing Old PHP and extensions
You can disable a module and enable a new one. See FPM example below.
sudo a2enconf php8.2-fpm #Enable PHP 8.2 FPM extension sudo a2disconf php8.1-fpm #Disable PHP 8.1 FPM extension
To remove all PHP 8.1 packages after upgrading to PHP 8.2 run the commands below.
Conclusion
We can conclude that PHP 8.2 brings many new features and improvements that aim at making PHP flexible, more powerful, and easy to use for web apps developers. With these new features you can experience a more efficient development process and make your code more readable, maintainable and secure. In this article we discussed how you can install PHP 8.2 on your Debian machine, and necessary configurations to host PHP applications on both Nginx and Apache web server. We hope you enjoyed this content and we look forward to creating more articles for you.
Установить php linux debian
Раздел содержит информацию и подсказки, относящиеся к установке PHP на » Debian GNU/Linux.
Неофициальные сборки от третьих лиц не поддерживаются. О любых ошибках следует сообщать разработчикам Debian, но перед этим стоит проверить, возможно они уже исправлены в новых релизах, которые можно скачать на » странице загрузки.
Хотя и существует универсальная инструкция по установке PHP на Unix/Linux, в этом разделе мы рассмотрим особенности специфичные для Debian, такие как использование команд apt или aptitude . В рамках этого руководства обе эти команды рассматриваются как взаимозаменяемые.
Использование APT
Во первых, обратите внимание на то, что некоторые пакеты связаны: libapache-mod-php нужен для интеграции с Apache 2, и php-pear с PEAR.
Во-вторых, перед установкой убедитесь, что список пакетов находится в актуальном состоянии. Как правило, это делается с помощью команды apt update.
Пример #1 Пример установки Apache 2 на Debian
# apt install php-common libapache2-mod-php php-cli
APT автоматически установит модуль PHP для Apache 2 и все их зависимости и, затем, активирует их. Apache должен быть перезапущен для того, чтобы изменения вступили в силу. Например:
Пример #2 Остановка и запуск Apache после установки PHP
# /etc/init.d/apache2 stop # /etc/init.d/apache2 start
Контроль конфигурации
Изначально, PHP устанавливается только с основными модулями ядра. Если вы хотите установить дополнительные модули, такие как MySQL, cURL, GD и т.д., это также можно сделать с помощью команды apt .
Пример #3 Способы получить список дополнительных пакетов PHP
# apt-cache search php # apt search php | grep -i mysql # aptitude search php
Будет выведен список большого числа пакетов, включая несколько специфичных, таких как php-cgi, php-cli and php-dev. Определите, какие вам нужны и установите с помощью apt-get или aptitude . И, так как Debian производит проверку зависимостей, вам будет выведен запрос на их установку.
Пример #4 Установка PHP с MySQL и cURL
# apt install php-mysql php-curl
APT автоматически добавит необходимые строки в соответствующие php.ini , /etc/php/7.4/php.ini , /etc/php/7.4/conf.d/*.ini , и т.д. В зависимости от модуля, будут внесены записи типа extension=foo.so . В любом случае, чтобы эти изменения вступили в силу, необходимо будет перезапустить сервер веб-сервер.
Стандартные проблемы
- Если скрипты PHP не разбираются веб-сервером, то скорее всего это означает, что PHP не был добавлен в конфигурацию веб-сервера. На Debian это обычно /etc/apache2/apache2.conf или похожий. Смотрите документацию Debian для выяснения подробностей.
- Модуль, по-видимому, установлен, а его функции всё равно не распознаются. В таком случае убедитесь, что соответствующий ini-файл был загружен и/или веб-сервер был перезагружен после установки модуля.
- Для установки пакетов в Debian существуют две основных команды (не считая стандартных вариантов Linux): apt и aptitude . Объяснения их синтаксиса, особенностей и отличий друг от друга выходит за рамки данного руководства.
User Contributed Notes 6 notes
To refresh this document, perhaps it would be worth mentioning more modern methods to serve php content under apache httpd.
Specifically, the preferred method is now fastcgi, using either of those recipes:
While the legacy mod_php approach is still applicable for some older installations, the fastcgi method is much faster, and require much less RAM to operate, based on similar traffic patterns.
Compiling PHP on Ubuntu boxes.
If you would like to compile PHP from source as opposed to relying on package maintainers, here’s a list of packages, and commands you can run
STEP 1:
sudo apt-get install autoconf build-essential curl libtool \
libssl-dev libcurl4-openssl-dev libxml2-dev libreadline7 \
libreadline-dev libzip-dev libzip4 nginx openssl \
pkg-config zlib1g-dev
So you don’t overwrite any existing PHP installs on your system, install PHP in your home directory. Create a directory for the PHP binaries to live
STEP 2:
# download the latest PHP tarball, decompress it, then cd to the new directory.
STEP 3:
Configure PHP. Remove any options you don’t need (like MySQL or Postgres (—with-pdo-pgsql))
./configure —prefix=$HOME/bin/php-latest \
—enable-mysqlnd \
—with-pdo-mysql \
—with-pdo-mysql=mysqlnd \
—with-pdo-pgsql=/usr/bin/pg_config \
—enable-bcmath \
—enable-fpm \
—with-fpm-user=www-data \
—with-fpm-group=www-data \
—enable-mbstring \
—enable-phpdbg \
—enable-shmop \
—enable-sockets \
—enable-sysvmsg \
—enable-sysvsem \
—enable-sysvshm \
—enable-zip \
—with-libzip=/usr/lib/x86_64-linux-gnu \
—with-zlib \
—with-curl \
—with-pear \
—with-openssl \
—enable-pcntl \
—with-readline
STEP 4:
compile the binaries by typing: make
If no errors, install by typing: make install
STEP 5:
Copy the PHP.ini file to the install directory
cp php.ini-development ~/bin/php-latest/lib/
cd ~/bin/php-latest/etc;
mv php-fpm.conf.default php-fpm.conf
mv php-fpm.d/www.conf.default php-fpm.d/www.conf
STEP 7:
create symbolic links for your for your binary files
cd ~/bin
ln -s php-latest/bin/php php
ln -s php-latest/bin/php-cgi php-cgi
ln -s php-latest/bin/php-config php-config
ln -s php-latest/bin/phpize phpize
ln -s php-latest/bin/phar.phar phar
ln -s php-latest/bin/pear pear
ln -s php-latest/bin/phpdbg phpdbg
ln -s php-latest/sbin/php-fpm php-fpm
STEP 8: link your local PHP to the php command. You will need to logout then log back in for php to switch to the local version instead of the installed version
# add this to .bashrc
if [ -d «$HOME/bin» ] ; then
PATH=»$HOME/bin:$PATH»
fi