3

I followed an online article to remove my Apache from my system.
I removed Apache through these commands

sudo apt-get purge apache2 apache2-utils
sudo rm -rf /etc/apache2-bin
sudo apt-get autoremove

Then in the article they mentioned to remove the files and directories of the results of whereis apache2.

After running the command whereis apache2 I found

/usr/sbin/apache2/usr/share/apache2
/usr/lib/apache2
/usr/share/man/man8/apache2.8.gz
/etc/apache2

I removed the above directories and files through command sudo rm -rf file_or_directory_name.

Then I tried

sudo apt-get install apache2

I clicked 'y' when the system asked do you want to continue?.

Then the error came:

Setting up apache2 (2.4.7-1ubuntu4.4) ...
cp: cannot stat ‘/usr/share/apache2/default-site/index.html’: No such file or directory
dpkg: error processing package apache2 (--configure): subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:  apache2 E: Sub-process /usr/bin/dpkg returned an error code (1)

I tried sudo apt-get install apache2 again after running the sudo apt-get update command, but still got the same error results.

3
  • you can use apt-file to search for which package contains which file like so: apt-file search /usr/share/apache2/default-site/index.html. faqforge.com/linux/…
    – mchid
    Mar 14 '15 at 19:16
  • 1
    Don't follow online tutorials blindly. Do not remove system files using rm -rf. That is what the packaging system is for. Mar 18 '15 at 3:50
  • yes , i realized that , Mar 18 '15 at 4:29
5

To recover /usr/share/apache2/default-site/index.html you need to re-install apache2-data. Given your current situation, try

sudo apt-get purge apache2-data
sudo apt-get install apache2

Presumably your system ended up in that state because apt-get autoremove didn't uninstall apache2-data, but your rm -rf removed the files it contained. Then apt-get install apache2 would reckon that apache2-data was still installed and didn't need to be re-installed, but its files were gone...

0
sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common

sudo apt-get --purge remove apache2

sudo apt-get autoremove --purge

sudo apt-get purge apache2-data

install

sudo apt-get install apache2
1
  • 1
    Welcome to the site, and thank you for your contribution. Note, however, that it is not quite obvious how your answer is to be applied to solve the OPs problem; you may want to edit it to provide more explanation. Also, it would seem that essentially the steps you propose are the same as in @StephenKitt's answer; perhaps you could explain how your approach is different.
    – AdminBee
    Jun 16 '20 at 11:24

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.