![在 Ubuntu 18.04 上安装 php7.3 时遇到问题“无法替换已删除的配置文件 /etc/php/7.3/apache2/php.ini”,](https://linux22.com/image/1177010/%E5%9C%A8%20Ubuntu%2018.04%20%E4%B8%8A%E5%AE%89%E8%A3%85%20php7.3%20%E6%97%B6%E9%81%87%E5%88%B0%E9%97%AE%E9%A2%98%E2%80%9C%E6%97%A0%E6%B3%95%E6%9B%BF%E6%8D%A2%E5%B7%B2%E5%88%A0%E9%99%A4%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%20%2Fetc%2Fphp%2F7.3%2Fapache2%2Fphp.ini%E2%80%9D%EF%BC%8C.png)
我正在尝试在 Ubuntu 18.4 上安装 Php7.3,我使用的是 Apache Server(2.4)。我的 php.ini 文件未在位置 /etc/php/7.3/apache2/php.ini 处设置。我按照php.ini 不存在但它对我不起作用。
我使用下面提到的命令
Sudo apt-get install php7.3 安装了它。
我甚至尝试重新安装 php。sudo
apt-get remove –purge php*
sudo apt-get purge php*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get remove dbconfig-php sudo apt-get dist-upgrade
sudo apt-get install php7.3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:libapache2-mod-php7.3 libpcre2-8-0 php-common php7.3-cli php7.3-common php7.3-json php7.3-opcache php7.3-readline
Suggested packages:
php-pear
The following NEW packages will be installed:
libapache2-mod-php7.3 libpcre2-8-0 php-common php7.3 php7.3-cli php7.3-common php7.3-json php7.3-opcache php7.3-readline
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/4,131 kB of archives.
After this operation, 17.8 MB of additional disk space will be used.
N: Ignoring file 'google-chrome' in directory '/etc/apt/sources.list.d/' as it has no filename extension
Do you want to continue? [Y/n] Y
N: Ignoring file 'google-chrome' in directory '/etc/apt/sources.list.d/' as it has no filename extension
(Reading database ... 176461 files and directories currently installed.)
Preparing to unpack .../0-php-common_2%3a76+ubuntu18.04.1+deb.sury.org+9_all.deb ...
Unpacking php-common (2:76+ubuntu18.04.1+deb.sury.org+9) ...
Preparing to unpack .../1-php7.3-common_7.3.22-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php7.3-common (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Preparing to unpack .../2-php7.3-json_7.3.22-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php7.3-json (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Preparing to unpack .../3-php7.3-opcache_7.3.22-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php7.3-opcache (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Preparing to unpack .../4-php7.3-readline_7.3.22-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php7.3-readline (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package libpcre2-8-0:amd64.
Preparing to unpack .../5-libpcre2-8-0_10.35-4+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking libpcre2-8-0:amd64 (10.35-4+ubuntu18.04.1+deb.sury.org+1) ...
Preparing to unpack .../6-php7.3-cli_7.3.22-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php7.3-cli (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Preparing to unpack .../7-libapache2-mod-php7.3_7.3.22-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking libapache2-mod-php7.3 (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package php7.3.
Preparing to unpack .../8-php7.3_7.3.22-1+ubuntu18.04.1+deb.sury.org+1_all.deb ...
Unpacking php7.3 (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Setting up php-common (2:76+ubuntu18.04.1+deb.sury.org+9) ...
Setting up libpcre2-8-0:amd64 (10.35-4+ubuntu18.04.1+deb.sury.org+1) ...
Setting up php7.3-common (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Not replacing deleted config file /etc/php/7.3/mods-available/calendar.ini
WARNING: Module calendar ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module calendar ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/ctype.ini
WARNING: Module ctype ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module ctype ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/exif.ini
WARNING: Module exif ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module exif ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/fileinfo.ini
WARNING: Module fileinfo ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module fileinfo ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/ftp.ini
WARNING: Module ftp ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module ftp ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/gettext.ini
WARNING: Module gettext ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module gettext ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/iconv.ini
WARNING: Module iconv ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module iconv ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/pdo.ini
WARNING: Module pdo ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module pdo ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/phar.ini
WARNING: Module phar ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module phar ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/posix.ini
WARNING: Module posix ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module posix ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/shmop.ini
WARNING: Module shmop ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module shmop ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/sockets.ini
WARNING: Module sockets ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module sockets ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/sysvmsg.ini
WARNING: Module sysvmsg ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module sysvmsg ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/sysvsem.ini
WARNING: Module sysvsem ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module sysvsem ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/sysvshm.ini
WARNING: Module sysvshm ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module sysvshm ini file doesn't exist under /etc/php/7.3/mods-available
Not replacing deleted config file /etc/php/7.3/mods-available/tokenizer.ini
WARNING: Module tokenizer ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module tokenizer ini file doesn't exist under /etc/php/7.3/mods-available
Setting up php7.3-opcache (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Not replacing deleted config file /etc/php/7.3/mods-available/opcache.ini
WARNING: Module opcache ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module opcache ini file doesn't exist under /etc/php/7.3/mods-available
Setting up php7.3-readline (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Not replacing deleted config file /etc/php/7.3/mods-available/readline.ini
WARNING: Module readline ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module readline ini file doesn't exist under /etc/php/7.3/mods-available
Setting up php7.3-json (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Not replacing deleted config file /etc/php/7.3/mods-available/json.ini
WARNING: Module json ini file doesn't exist under /etc/php/7.3/mods-available
WARNING: Module json ini file doesn't exist under /etc/php/7.3/mods-available
Setting up php7.3-cli (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
update-alternatives: using /usr/bin/php7.3 to provide /usr/bin/php (php) in auto mode
update-alternatives: using /usr/bin/phar7.3 to provide /usr/bin/phar (phar) in auto mode
update-alternatives: using /usr/bin/phar.phar7.3 to provide /usr/bin/phar.phar (phar.phar) in auto mode
Not replacing deleted config file /etc/php/7.3/cli/php.ini
Setting up libapache2-mod-php7.3 (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Not replacing deleted config file /etc/php/7.3/apache2/php.ini
apache2_invoke: Enable module php7.3
Setting up php7.3 (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.2) ...
Processing triggers for php7.3-cli (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
Processing triggers for libapache2-mod-php7.3 (7.3.22-1+ubuntu18.04.1+deb.sury.org+1) ...
答案1
Ubuntu 18.04 附带 PHP 7.2,因此您的版本 7.3 来自附加 PPA,您的日志中表明您正在使用 sury.org 版本。
libapache2-mod-php7.3 是连接 PHP 和 Apache 的软件包,如果两者都安装了,您会自动获得它。但您可以独立于 ubuntu 卸载和清除它,这样它就会忘记安装时的状态。重点是 APT 试图不干扰用户的操作,这有时很好,有时很烦人
apt remove libapache2-mod-php7.3
apt purge libapache2-mod-php7.3
apt install libapache2-mod-php7.3
您可能可以将这些步骤合并为一个命令,但我更喜欢原子操作,这样我就可以理解每个状态。您现在应该看到一行说明
Creating config file /etc/php/7.3/apache2/php.ini with new version
Ubuntu 20.04 是一个较新的 LTS 版本,默认搭载 PHP 7.4。dist-upgrade 命令用于升级版本,但我认为现在不再是这样了。apt-get 已被 apt 取代
答案2
(与我的另一个答案重复:https://askubuntu.com/a/1364688/720219)
清除软件包是不够的:(ucf
更新配置文件)保护文件。避免这种情况的一种方法是强制执行默认操作。我在选项中ucf
运气不佳,所以我阅读了文档。confmiss
dpkg
ucf
- 覆盖默认
ucf
操作,如果配置不存在则创建配置:
export UCF_FORCE_CONFFMISS=1
- 清除包:
apt-get purge libapache2-mod-php7.3
- 重新安装包:
apt-get install libapache2-mod-php7.3
- 恢复
ucf
默认操作:
export UCF_FORCE_CONFFMISS=
请注意,对于 PHP 包,您有两个包:一个带有版本 ( php7.3-zip
),一个不带有版本 ( php-zip
)。您应该安装不带版本 ( php-zip
) 的包,以便将来升级。但如果您需要替换配置文件(如这里提出的主要问题),您应该清除两个包,然后仅安装不带版本的包。
旁注:您可以使用UCF_FORCE_CONFFNEW=1
它来删除您的配置文件,但请谨慎使用。