New Linux user. I accidentally overwrote my /usr/bin/php file. The php command no longer works.

What's the best way to recover that file?

Using bash and Linux Mint distro.

  • reinstall php again run sudo apt-get install php5 libapache2-mod-php5 if it shows it exits remove php and install it again – harish.venkat Jan 18 '12 at 16:49
  • Thanks. So my problem was that I was reinstalling php5 and not php5-cli. – ksindi Jan 18 '12 at 16:50
sudo apt-get remove php5-cli
sudo apt-get install php5-cli

And the one liner,

sudo apt-get install --reinstall php5-cli
  • 2
    Why not only sudo apt-get install --reinstall php5-cli? – manatwork Jan 18 '12 at 16:52
  • @manatwork Thanks. I have added. In fact I didn't know it. – Shiplu Mokaddim Jan 18 '12 at 16:56

The easiest way is to reinstall the package containing the file you accidentally deleted. I'll explain how to do this from the command line, on distributions using Debian packaging tools (Debian, Ubuntu, Mint, …). If you use a package management GUI, it may have equivalent commands. All the commands mentioned here, except for the ones that only display information and don't modify the system, must be executed as root (i.e. put sudo in front or run them in a root shell).

First, find out which package contains the file. You can use the command dpkg -S /usr/bin/php5 for that. Here, the (relevant) result is php5-cli. There's a subtlety here: this package contains /usr/bin/php5, not /usr/bin/php; the package creates a symbolic link /usr/bin/php which points indirectly to /usr/bin/php5 upon installation.

If you're missing /usr/bin/php5, reinstall the php5-cli package. On the command line, use apt-get --reinstall install or aptitude reinstall to force a reinstallation even if the package is marked as up-to-date.

If you're missing /usr/bin/php, recreate the symbolic link. You can do this manually: ln -s /etc/alternatives/php /usr/bin/php. If you reinstall the package as above, this will recreate the symbolic link.

If you're missing /etc/alternatives/php, run update-alternatives --auto php (or run update-alternatives --config php and select php5 in the list).


dpkg -S /usr/bin/php
sudo apt-get --reinstall reinstall php5-cli
sudo update-alternatives --auto php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.