最近趁着优惠活动购入了几个 VPS ,想着手头有空闲资源了将一些站点迁移一下,这次特意不使用其他面板使用纯命令行的方式于是在复现之前的文章时发现了当时的一些疏忽。
之前的安装中虽然安装了php-fpm
后面再安装了libapache2-mod-php
模块,可能就是因为如此这般才会Server API就是之前的 Apache 2.0 Handler。
1、安装 PHP 相关:
这次在安装 PHP 8.4 时虽然指定了版本且安装完成后版本也是预想的
PHP 8.4.1 (cli) (built: Nov 25 2024 18:23:27) (NTS) Copyright (c) The PHP Group Zend Engine v4.4.1, Copyright (c) Zend Technologies with Zend OPcache v8.4.1, Copyright (c), by Zend Technologies
但是在安装 Apache 的 PHP 模块时没有指定版本而是直接执行 libapache2-mod-php
进行安装,这将给我再安装一套 PHP 8.3 且phpinfo();
查看到的也是 8.3.14
。
后来我再次执行apt install libapache2-mod-php8.4
才是安装到8.4的模块但是没有启用,需要执行下面命令禁用8.3的模块启用8.4的模块:
a2dismod php8.3 a2enmod php8.4
将模块切换到8.4的后在phpinfo();
查看到的8.4.1
了。
存储库现有的libapache2-mod-php
版本:
apt-cache search libapache2-mod-php libapache2-mod-php8.2 - server-side, HTML-embedded scripting language (Apache 2 module) php8.2-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) libapache2-mod-php - server-side, HTML-embedded scripting language (Apache 2 module) (default) libapache2-mod-php5.6 - server-side, HTML-embedded scripting language (Apache 2 module) libapache2-mod-php5.6-dbgsym - debug symbols for libapache2-mod-php5.6 libapache2-mod-php7.0 - server-side, HTML-embedded scripting language (Apache 2 module) libapache2-mod-php7.0-dbgsym - debug symbols for libapache2-mod-php7.0 libapache2-mod-php7.1 - server-side, HTML-embedded scripting language (Apache 2 module) libapache2-mod-php7.1-dbgsym - debug symbols for libapache2-mod-php7.1 libapache2-mod-php7.2 - server-side, HTML-embedded scripting language (Apache 2 module) libapache2-mod-php7.2-dbgsym - debug symbols for libapache2-mod-php7.2 libapache2-mod-php7.3 - server-side, HTML-embedded scripting language (Apache 2 module) libapache2-mod-php7.3-dbgsym - debug symbols for libapache2-mod-php7.3 libapache2-mod-php7.4 - server-side, HTML-embedded scripting language (Apache 2 module) libapache2-mod-php7.4-dbgsym - debug symbols for libapache2-mod-php7.4 libapache2-mod-php8.0 - server-side, HTML-embedded scripting language (Apache 2 module) libapache2-mod-php8.0-dbgsym - debug symbols for libapache2-mod-php8.0 libapache2-mod-php8.1 - server-side, HTML-embedded scripting language (Apache 2 module) libapache2-mod-php8.1-dbgsym - debug symbols for libapache2-mod-php8.1 libapache2-mod-php8.2-dbgsym - debug symbols for libapache2-mod-php8.2 libapache2-mod-php8.3 - server-side, HTML-embedded scripting language (Apache 2 module) libapache2-mod-php8.3-dbgsym - debug symbols for libapache2-mod-php8.3 libapache2-mod-php8.4 - server-side, HTML-embedded scripting language (Apache 2 module) libapache2-mod-php8.4-dbgsym - debug symbols for libapache2-mod-php8.4 php5.6-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php7.0-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php7.1-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php7.2-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php7.3-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php7.4-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php8.0-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php8.1-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php8.3-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php8.4-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
不指定的话将会有默认的版本。
2、删除旧版本的 PHP,毕竟这是新环境且暂时不需要其他版本:
apt purge '^php8.3.*'
3、如果使用PHP-FPM的方式则需要执行:
a2enconf php8.4-fpm
4、安装了多个版本后的 PHP 链接的版本:
update-alternatives --config php
输入对应的版本需要,或者是
update-alternatives --set php /usr/bin/php8.4
最后被繁琐的操作给劝退还是老实的使用面板比较便利……
ChiuYut
2024年12月03日