Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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. – capitalistpug Jan 18 '12 at 16:50
up vote 6 down vote accepted
sudo apt-get remove php5-cli
sudo apt-get install php5-cli

And the one liner,

sudo apt-get install --reinstall php5-cli
share|improve this answer
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 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
share|improve this answer
+1 Thanks for the edit and helpful response. – capitalistpug Jan 18 '12 at 17:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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