Uninstall php 7 in ubuntu 18.04

社会主义新天地 提交于 2021-02-06 09:05:53

问题


I have a server that has an application that runs with PHP 5.6. But I upgraded the server from Ubuntu 14.04 to 18.04 and in the process I also upgraded PHP to 7.2. Now I'm trying to uninstall it but I'm finding difficult.

I have run the command:

sudo apt-get remove php

and

sudo apt-get remove --purge php

Its says that PHP it's not installed, but running php --version I'm still seeing the version 7 of PHP.

PHP 7.2.19-0ubuntu0.18.04.2 (cli) (built: Aug 12 2019 19:34:28) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.19-0ubuntu0.18.04.2, Copyright (c) 1999-2018, by Zend Technologies


回答1:


This will remove all php7 versions, be it php 7.0 or php 7.1 etc..

sudo apt-get purge php7.*
sudo apt-get autoclean
sudo apt-get autoremove
  • apt/apt-get autoclean → cleans obsolete deb-packages, less than clean
  • apt/apt-get autoremove → removes orphaned packages which are not longer needed from the system, but not purges them, use the --purge option together with the command for that.

**To Install PHP again **

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

if php7.0

sudo apt-get install php7.0

if php7.1

sudo apt-get install php7.1

if php7.2

sudo apt-get install php7.2

To switch that to the newer 7.1,7.2,7.3,7.4 version, first disable older PHP version:

user@test:~# sudo a2dismod php7.0

Then enable PHP 7.2:

user@test:~# sudo a2enmod php7.2
sudo service apache2 restart



回答2:


Firstly you need to restart the apache to take all in effect and also You can install mutliple php version using this post or just using

sudo apt update
sudo apt-add-repository ppa:ondrej/php
sudo apt update
sudo apt install -y php5.6 php5.6-cli php5.6-common

disable php7.2:

sudo a2dismod php7.2

enable php 5.6:

sudo a2enmod php5.6

After all restart the apache again to take into affect

service apache2 restart



回答3:


This is work on my server:

sudo apt purge php5.6 php5.6-common
sudo apt purge php7.x php7.x-common



回答4:


This will remove PHP

sudo apt-get purge `dpkg -l | grep php7.2| awk '{print $2}' |tr "\n" " "`
sudo apt-get purge php7.*
sudo apt-get autoremove --purge
whereis php
sudo rm -rf /etc/php


来源:https://stackoverflow.com/questions/58045685/uninstall-php-7-in-ubuntu-18-04

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!