在 CentOS 下切換 PHP 版本,你可以使用以下步驟:
yum list installed | grep php
yum install php-<version>
將 <version>
替換為你想要安裝的 PHP 版本,例如:
yum install php-7.2
對于 Apache:
/etc/httpd/conf/httpd.conf
或 /etc/apache2/apache2.conf
)。LoadModule
指令加載了正確的 PHP 模塊。例如,對于 PHP 7.2,你應該看到以下行:LoadModule php7_module modules/libphp7.so
<Directory>
或 <Location>
配置塊中,設置 SetHandler
指令以使用 PHP 處理器。例如:SetHandler application/x-httpd-php
systemctl restart httpd
對于 Nginx:
/etc/nginx/nginx.conf
或 /etc/nginx/sites-available/default
)。server
塊中,找到 location ~ \.php$
配置塊。fastcgi_pass
指令以使用正確的 PHP-FPM 版本。例如,對于 PHP 7.2,你應該看到以下行:fastcgi_pass unix:/run/php-fpm/php-fpm7.2.sock;
systemctl restart nginx
php -v
命令驗證 PHP 版本已成功切換。請注意,這些步驟可能因 CentOS 版本和 PHP 版本而異。如果你遇到問題,請查閱 CentOS 和 PHP 的官方文檔以獲取更多詳細信息。