3

I have an apache configuration file which works fine when it's placed directly in /etc/httpd/conf.d/foo.conf. However, when I move the same file somewhere else (for example, move it to /tmp/foo.conf) and then create a symlink with ln -s /tmp/foo.conf /etc/httpd/conf.d then apache fails on startup with:

httpd: could not open document config file /etc/httpd/conf.d/foo.conf

I've tried making the file and the symlink mode 777, and tried changing them to be owned by the apache user.

It seems like apache is failing to load the file purely on the basis of it being a symlink, but I'm sure I've used symlinks successfully on other machines. Is there something I'm missing? Does apache have an option for refusing to load config files if they're symlinks?

The operating system is CentOS 4.4, apache version 2.0.52.

kdt
  • 1,360
  • 3
  • 22
  • 34
  • 1
    Interesting to note that if you search for "symlink httpd config OR conf.d" without quotes on google, this is already the number one result. – Kevin M Apr 23 '10 at 16:28

3 Answers3

4

Is SELinux enabled on this server? I wonder if this is stopping apache from loading this symlink correctly?

AliGibbs
  • 2,303
  • 20
  • 34
  • Precisely the thought I had, but note that it worked when the file was in the conf.d directory, but not when it's outside the directory with a symlink to it. – Kevin M Apr 23 '10 at 15:51
  • @kdt Disabling selinux is an easy fix but far from a good fix. SElinux can be rather daunting, but there are some great guides and tutorials on how to use it correctly! Here's a very well done talk that is easy enough to follow: https://www.youtube.com/watch?v=MxjenQ31b70 – TheGrandPackard Nov 20 '15 at 21:06
0

The permissions for the apache user shouldn't matter as in general apache is run starting as root and then in launches webserver as the apache user (or whatever the user directive is). I believe this would have to be after the config file is loaded.

Can you cat the symlink?

Kyle Brandt
  • 82,107
  • 71
  • 302
  • 444
-1

Instead of creating a symlink from conf.d to wherever it is, could you leave the file in the conf.d directory and create a symlink to the file in conf.d. Example syntax: ln -s /etc/httpd/conf.d/foo.conf /tmp/foo.conf

Alternatively, use a hard link, so it is a regular file in both places. One file with two locations. Example syntax: ln /tmp/foo.conf /etc/httpd/conf.d Note that this will only work if both locations are on the same filesystem.

Kevin M
  • 2,302
  • 1
  • 16
  • 21