12

I was learning server installation by creating a web server in VMware, I don’t know what changes I made to httpd.conf.

Is there any way to reset all the configuration for httpd.conf to default?

Command used:

  1. vi /etc/httpd/conf/httpd.conf
  2. Updated ServerName to localhost
  3. service httpd restart
  4. chkconfig httpd on
  5. service httpd restart
Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
KodeCeeper
  • 123
  • 1
  • 1
  • 5
  • Restore from the backup copy you made before editing? – DavidPostill Apr 04 '15 at 20:27
  • 1
    It sounds like might not have a back up. What you could do is copy the `httpd.conf` that you have now and back it up. Delete the original and run `sudo apt-get reinstall httpd`. Go back and see if it created a new `.conf`, if so then it should be fixed. – xR34P3Rx Apr 04 '15 at 20:41
  • @DavidPostill Why worry about restoring a default file from backup? Just reinstall from the RPM and all should be good. Fuller answer posted. – Giacomo1968 Apr 04 '15 at 21:28

2 Answers2

25

Shorter answer:

You could simply erase or move the httpd.conf file you adjusted and then run the following command and it will be reinstalled:

yum reinstall httpd

Longer answer:

But if you want to be a bit more methodical about it, you could follow the ideas and concepts shown on this page.

First, check what package installed httpd.conf by running this command:

rpm -qf /etc/httpd/conf/httpd.conf

Of course that would show you that the httpd package installed it, but it will also give you additional version info. So now you can verify what was changed between the initial install from the RPM to when you adjusted it by verifying it with RPM like this:

rpm -V httpd

Output would most likely show you /etc/httpd/conf/httpd.conf preceded by some verification info which should look like this:

S.5....T.  c /etc/httpd/conf/httpd.conf

That can be translated as the Size was changed, the MD5 checksum is different and the Time is different. More details on what those one letter codes mean are below:

S file Size differs
M Mode differs (includes permissions and file type)
5 MD5 sum differs
D Device major/minor number mismatch
L readLink(2) path mismatch
U User ownership differs
G Group ownership differs
T mTime differs
P caPabilities differ

But the long and short of it is you will be able to see exactly what files from the httpd package had changed and for what reason. Which could be useful to know if you happened to add or changed any file other than httpd.conf and it slipped your mind.

Now you might want to remove the current httpd.conf like this:

sudo rm /etc/httpd/conf/httpd.conf

But I would recommend keeping a copy of it for reference like this:

sudo mv /etc/httpd/conf/httpd.conf ~/httpd.conf.modified

That would move httpd.conf to your home directory and rename it httpd.conf.modified.

Finally, you can reinstall httpd like this:

yum reinstall httpd

And your Apache httpd.conf config file should be back to it’s original, untouched RPM state.

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
4

@Giacomo1968's answer is great but to be more explicit:

yum reinstall httpd will only restore missing files, not the changed configs. By moving/removing the old configuration file first, that allowed yum reinstall to restore the file.

Alternatively, you could use the method shown here: How to force `yum reinstall` to overwrite changed files in a `/var` sub-directory?

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212