如何在Debian 10/Debian 9上安装PHP 7.4

时间:2020-02-23 14:32:46  来源:igfitidea点击:

如何在Debian 10(Buster)/Debian 9上安装PHP 7.4(延伸)?
PHP是创建动态网页的最广泛使用的服务器端脚本语言。
PHP应用程序通常与HTML合作,与关系数据库管理系统进行交互。
随着每种释放PHP,有多种新功能。

PHP 7.4在Debian 10/Debian 9上的安装可用于生产使用。
GA发布于2019年11月28日公开。
不建议在生产中运行Beta发布。
它应该用于测试PHP 7.4中的新功能并准备弃用功能。

在Debian 10/Debian 9上安装PHP 7.4

按照下面涵盖的步骤在Debian 10和Debian 9 Linux发行版上安装PHP 7.4.
Sury PHP PPA存储库提供了Debian的最新版本。
我们将添加存储库作为准备工作,然后从Debian 10/Debian 9上安装PHP 7.4.

第1步:更新系统

确保系统更新:

sudo apt update
sudo apt upgrade -y && sudo reboot

第2步:添加Sury PHP PPA存储库

在Debian Server /桌面上的文件中下载并存储PPA存储库。
但首先,下载GPG键。

sudo apt -y install lsb-release apt-transport-https 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

第3步:在Debian 10/Debian 9上安装PHP 7.4

最后一步是在Debian 10/Debian 9上安装PHP 7.4 9.在安装之前,请在添加的存储库上更新系统包列表。

sudo apt update

然后在Debian 10/Debian 9上安装PHP 7.4:

sudo apt -y install php7.4

在Debian 10/Debian 9 Linux系统上提示完成PHP 7.4时,请回答是。

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php7.4 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1
  libcurl4 libgdbm-compat4 libgdbm6 libjansson4 libldap-2.4-2 libldap-common liblua5.2-0 libnghttp2-14 libpcre2-8-0 libperl5.28 librtmp1
  libsasl2-2 libsasl2-modules libsasl2-modules-db libsodium23 libssh2-1 perl perl-modules-5.28 php-common php7.4-cli php7.4-common php7.4-json
  php7.4-opcache php7.4-readline psmisc ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear libsasl2-modules-gssapi-mit | libsasl2-modules-gssapi-heimdal
  libsasl2-modules-ldap libsasl2-modules-otp libsasl2-modules-sql perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make
  libb-debug-perl liblocale-codes-perl openssl-blacklist
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php7.4 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1
  libcurl4 libgdbm-compat4 libgdbm6 libjansson4 libldap-2.4-2 libldap-common liblua5.2-0 libnghttp2-14 libperl5.28 librtmp1 libsasl2-2
  libsasl2-modules libsasl2-modules-db libsodium23 libssh2-1 perl perl-modules-5.28 php-common php7.4 php7.4-cli php7.4-common php7.4-json
  php7.4-opcache php7.4-readline psmisc ssl-cert
The following packages will be upgraded:
  libpcre2-8-0
1 upgraded, 36 newly installed, 0 to remove and 7 not upgraded.
Need to get 15.0 MB of archives.
After this operation, 76.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

使用下一个命令安装其他包:

sudo apt-get install php7.4-xxx

例子:

sudo apt-get install php7.4-{bcmath,bz2,intl,gd,mbstring,mysql,zip}

与Apache相关的PHP配置存储在/etc/php/7.4/apache2/php.ini中

使用Nginx使用PHP:

Debian上的PHP安装配置Apache。
对于有兴趣运行nginx和PHP的用户,我们需要停止和禁用Apache服务。

sudo systemctl disable --now apache2

然后安装FPM扩展和nginx包。

sudo apt-get install nginx php7.4-fpm

PHP FPM配置文件位于目录中:/etc/php/7.4/fpm/

应该运行nginx和php-fpm服务。

$systemctl status php7.4-fpm nginx
● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-09-19 17:32:26 UTC; 14s ago
     Docs: man:php-fpm7.4(8)
 Main PID: 12151 (php-fpm7.4)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 3 (limit: 2377)
   Memory: 14.7M
   CGroup: /system.slice/php7.4-fpm.service
           ├─12151 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
           ├─12152 php-fpm: pool www
           └─12153 php-fpm: pool www
Sep 19 17:32:26 deb10 systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
Sep 19 17:32:26 deb10 systemd[1]: Started The PHP 7.4 FastCGI Process Manager.
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-09-19 17:32:27 UTC; 12s ago
     Docs: man:nginx(8)
 Main PID: 12362 (nginx)
    Tasks: 2 (limit: 2377)
   Memory: 3.2M
   CGroup: /system.slice/nginx.service
           ├─12362 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           └─12363 nginx: worker process
Sep 19 17:32:27 deb10 systemd[1]: Starting A high performance web server and a reverse proxy server...
Sep 19 17:32:27 deb10 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Sep 19 17:32:27 deb10 systemd[1]: Started A high performance web server and a reverse proxy server.