3

I've accidentially deleted a virtual hosts file 010-foo.conf. The Apache2.4 is still running without reload or restart so far. Is there a way to see actual config of the file which isn't there any more (maybe via apachectl command or whatever)?

2
  • 3
    It's easiest to restore your backup. – Michael Hampton Oct 13 '15 at 16:48
  • This file was written and deleted before backup :( - but sure, you're right! – colidyre Oct 13 '15 at 16:49
5

If you don't have mod_info installed, you can use gcore to dump the parent Apache process (the one owned by pid 1) memory to a file, then search it for "VirtualHost" or something. I just tested it on my system and it works. You'll have to mess around with something like grep to cut out what you want and replace the config file.

gcore <pid>
less core.<pid>

EDIT (from OP):

If you don't have gcore, you can install it via apt-get install gdb (Ubuntu). The pid file is typically located under /var/run/apache2/apache2.pid. Then you can do the commands mentioned above and search the binary files, e.g. with grep -obUaP "text to search" <dump file>, see here for more information about using grep for binary files.

1
  • Oh, ok. I fixed the problem, already. But I tried a test with your solution and it gives me a huge dump file with the wanted information in it. I will edit your very helpful answer. Thanks a lot for pointing that out. It will surely help other people with the same problem. It could be time-consuming getting all the information, but they are present there! That's really good. – colidyre Oct 14 '15 at 9:05
2

If you installed mod_info, you can use that to print your server configuration. In my case, I can see the entire configuration as Apache sees it, including all VirtualHosts.

If you don't have mod_info installed and working already, this information may not be available to you.

You can also see some VirtualHost information on the commandline by using httpd -S. It's not complete, but it's better then nothing:

-S
Show the settings as parsed from the config file (currently only shows the virtualhost settings).
8
  • Thanks. This was helpful. But it seems that not all information are sent. There was also a path to a wsgi file which I can't see in the output of apachectl -S command (ok, you mentioned it). – colidyre Oct 13 '15 at 17:20
  • You would think that a program running in memory would be able to show you it's configuration as it currently stands. – Stefan Lasiewski Oct 13 '15 at 17:27
  • Oh, I have to correct myself: it seems that apachectl -S looks at the file in sites-enabled (which links to sites-available). Yes, something like this. Showing program's config out of memory or from temporary written file or whatever. I know the chances aren't good for that. – colidyre Oct 13 '15 at 17:27
  • Technically, apachectl first checks in the global system configuration files (On RHEL, this would normally be /etc/sysconfig/httpd). From there, it should receive the correct ServerRoot setting. On my setting, /etc/sysconfig/httpd says OPTIONS='-d /etc/httpd', and therefore httpd is called as httpd -d /etc/httpd. /etc/httpd would need to include the sites-enabled directory somewhere. – Stefan Lasiewski Oct 13 '15 at 17:42
  • 1
    I agree. If you don't have mod_info installed already, you probably cannot retrieve the configuration for that one VirtualHost. – Stefan Lasiewski Oct 13 '15 at 22:07

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.