You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 23.04环境下PHP7.2安装方法及安装报错解决求助

Ubuntu 23.04环境下PHP7.2安装方法及安装报错解决求助

Hey there, I totally get the frustration when you try installing PHP 7.2 on Ubuntu 23.04 and hit those "Unable to locate package" errors—let’s figure out what’s going on and how to fix it.

Why the error happens?

Ubuntu 23.04’s default software repositories don’t include PHP 7.2 anymore. That’s because PHP 7.2 reached its end-of-life (EOL) back in November 2020, meaning it no longer gets security updates or official support from the PHP team. For security reasons, Ubuntu removes EOL software from its default sources.

Step-by-step installation fix

If you really need PHP 7.2 (for an old project or testing purposes—note: not recommended for production!), you can use a third-party PPA that maintains legacy PHP versions:

  • First, install the tools needed to add new repositories:

    sudo apt update && sudo apt install software-properties-common
    
  • Add the popular Ondřej Surý PHP PPA (this repo keeps older PHP versions available for newer Ubuntu releases):

    sudo add-apt-repository ppa:ondrej/php
    

    You’ll see a prompt about the PPA details—just press Enter to confirm adding it.

  • Update your package list again to include the new PPA’s packages:

    sudo apt update
    
  • Now you can install PHP 7.2, along with common extensions you might need (adjust based on your requirements):

    sudo apt install php7.2 php7.2-cli php7.2-fpm php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php7.2-xml php7.2-zip
    
  • Verify the installation worked by checking the PHP version:

    php -v
    

Alternative: Use Docker (safer for production/testing)

Since PHP 7.2 is unmaintained, running it directly on your Ubuntu 23.04 system carries security risks. A better option is to use Docker to run PHP 7.2 in an isolated container:

  • Install Docker if you haven’t already, then run:
    docker run -d -p 8080:80 php:7.2-apache
    
    This will start an Apache server with PHP 7.2, accessible at http://localhost:8080.

Important note

Never use PHP 7.2 in a production environment—it’s no longer receiving security patches, which leaves your system vulnerable to exploits. Only use it for legacy projects that you’re actively planning to upgrade.

备注:内容来源于stack exchange,提问作者Md.Tanjeeb Ahsan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 16:19:53