您的瀏覽器不支援JavaScript功能,若網頁功能無法正常使用時,請開啟瀏覽器JavaScript狀態
Antfire 的生活雜記
Skip
    banner

    Connection Timeout Error During Ubuntu 20.04 to 22.04 Upgrade and fix broken apache2 and php

    Connection Timeout Error During Ubuntu 20.04 to 22.04 Upgrade and fix broken apache2 and php

    問題

    During the upgrade from Ubuntu 20.04 to 22.04, a “Connection timeout” error occurred.

    sudo apt update -y && sudo apt upgrade -y
    img-Pasted image 20250304151809.png img-Pasted image 20250304150619.png

    是過了以下各種解決方案

    修改source.list 檔

    sudo vim /etc/apt/sources.list

    將無法連線的網址 從tw.替換成 us.

    關閉IPV6

    sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
    sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
    sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1

    暫時移除第三方儲存庫 (Repository)

    sudo mv -r /etc/apt/sources.list.d/ /etc/apt/sources.list.d_

    最後是暫時移除第三方儲存庫這個方案對我有幫助,移除後再次使用以下指令,作業完成後,再自己決定要不要改回去。

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

    輸入指令後,出現以下錯誤訊息

    img-Pasted image 20250304153824.png

    於是我根據訊息中下了 sudo apt --fix-broken install後,我的Apache 2 跟 PHP 都掛了,但是 apt update 以及 upgrade 的指令能成功執行完。
    於是先略過Apache2 跟 PHP的問題,繼續往下走。

    sudo apt dist-upgrade

    移除用不到的套件

    sudo apt autoremove

    安裝更新管理器

    sudo apt install update-manager-core

    重開機

    sudo reboot

    開始升級

    sudo do-release-upgrade

    升級的過程中會出現一連串的確認項目,我都是用預設選項繼續下去
    升級時間約1小時內可以結束

    更新完後,繼續以下指令

    sudo apt --purge autoremove
    sudo apt autoclean

    問題1 Apache2.service is masked

    sudo systemctl unmask apache2
    sudo service apache2 restart

    問題2 PHP沒有解除安裝乾淨,無法重新安裝PHP

    sudo apt-get purge php8.*
    sudo apt-get autoclean
    sudo apt-get autoremove

    移除完畢後,再重新安裝 PHP

    sudo apt-get install php8.1

    參考資料

    https://www.kwchang0831.dev/dev-env/ubuntu/upgrade-from-20.04-to-22.04
    https://askubuntu.com/questions/959723/apache2-service-is-masked
    https://stackoverflow.com/questions/58045685/uninstall-php-7-in-ubuntu-18-04

     Comments