1

I have the following directories, where /data is the mount point for a data partition, and /var is a symlink:

lrwxrwxrwx 1 root root 9 Nov 20 13:25 /var -> /data/var
lrwxrwxrwx 1 root root 9 Nov 20 23:41 /var/lock -> /run/lock
drwxr-xr-x 5 root root 4096 Nov 20 13:42 /data
drwxr-xr-x 12 root root 4096 Nov 21 01:44 /data/var
drwxr-xr-x 6 root root 4096 Dec 18 06:25 /data/var/log
drwxr-x--- 3 root adm 4096 Dec  8 06:25 /data/var/log/apache2/

Apache seems to have issues with this approach:

mktemp: failed to create directory via template '/var/lock/apache2.XXXXXXXXXX': No such file or directory

I solved that by changing /etc/apache2/envvars to refer to /run/lock directly, but the next error wasn't solved by changing APACHE_LOG_DIR in envvars:

(2)No such file or directory: AH02291: Cannot access directory '/var/log/apache2/' for main error log
(2)No such file or directory: AH02291: Cannot access directory '/var/log/apache2/' for error log of vhost defined at /etc/apache2/sites-enabled/site.conf:2
AH00014: Configuration check failed

How can I make this work?

Roger Dueck
  • 131
  • 5
  • 17

3 Answers3

2

Do not symlink /var as it is used for much more than Apache. if you're looking to just move the apache logs and site files to another partition/folder/disk, then simply change the configuration in apache to do so. It is a very flexible web server that allows you to put files wherever you want, but what you're trying to do is redirect a core folder of the OS when you should be updating the apache configs to store things where you want them to go.

SteamerJ
  • 403
  • 2
  • 7
  • But I really do want *all* of `/var` on my separate data partition if possible - a small and fairly static root partition, and a larger, dynamic data partition. With both `/var` and `/home` on the data partition, it didn't seem feasible to make each one a mount point. So far, the only program that seems to have a problem with the symlink is Apache. – Roger Dueck Dec 18 '18 at 20:37
  • If that is the use case you want, then you want to set that up when you install the OS since you can set it up for that in a clean manner. Doing it after the OS install via symlinks doesn't actually move it and you're going to run into a lot of issues. There are other ways to move an existing /var to a new partition without introducing all the issues you're going to run into with the way you're currently going. – SteamerJ Dec 18 '18 at 20:41
  • What would be different about doing at install time - separate partitions and mount points, instead of symlinks? Could you suggest some of those "other ways"? Why won't Apache just follow the symlinks? – Roger Dueck Dec 18 '18 at 20:46
  • 1
    The whole OS itself has dependencies and permissions set up around the /var folder. By symlinking it, you are redirecting anything that expects something in /var to go to another location which likely do not have permissions set up. The process to move your /var folder to another partition (not symlink it) can vary based on the linux distribution. A quick search can give you answers specific to your distro, but this can get you started in the right direction: https://unix.stackexchange.com/questions/131311/moving-var-home-to-separate-partition – SteamerJ Dec 18 '18 at 20:50
1

The solution is to bind mount, not symlink, as recommended here, with reasoning against the symlink to /var given in point #7:

the hierarchy standard dictates that it must be a directory

In my case, switching from symlink to bind mount was accomplished with:

sudo -s
rm /var && mkdir -p /var && mount -o bind /data/var /var
cat >> /etc/fstab << END
/data/var /var none bind 0 0
END

and now apache starts without complaint.

Roger Dueck
  • 131
  • 5
  • 17
0

Some Linux-based distributions run with SELinux enabled and configured for normal use. You're outside those parameters so you may need to adjust SELinux.

roaima
  • 1,591
  • 14
  • 28