ivoba
ivoba

Reputation: 5986

Apache in Docker says: Symbolic link not allowed

I use a Docker image: https://github.com/docker-library/php/blob/fec7f537f049aafd2102202519c3ca9cb9576707/5.5/apache/Dockerfile

And i use it with docker-compose:

apache:
  build: ./site/docker/apachephp
  environment:
    - VIRTUAL_HOST=www.test.dev
  volumes:
    - ./site/code:/var/www/app
  expose:
    - "80"

The code is a symfony app and uses symbolic link in the web folder, but for all assets in the symbolic links i get in the apache logs:

AH00037: Symbolic link not allowed or link target not accessible: /var/www/app/web/test

All other code runs fine.
I wonder if that Options +FollowSymLinks -SymLinksIfOwnerMatch is used correct and if there maybe other config files that override someting?

Or is it some Permission issue? The files on the host belong not to the apache user www-data but to another user, read rights are set however.

The Apache config is:

# see http://sources.debian.net/src/apache2/2.4.10-1/debian/config-dir/apache2.conf

Mutex file:/var/lock/apache2 default
PidFile /var/run/apache2/apache2.pid
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User www-data
Group www-data
HostnameLookups Off
ErrorLog /proc/self/fd/2
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# ports.conf
Listen 80
<IfModule ssl_module>
    Listen 443
</IfModule>
<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

<Directory />
    AllowOverride None
    Require all denied
</Directory>

<Directory /var/www/app>
    Options +FollowSymLinks -SymLinksIfOwnerMatch
    AllowOverride All
    Require all granted
</Directory>

DocumentRoot /var/www/app/web

AccessFileName .htaccess
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

CustomLog /proc/self/fd/1 combined

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

# Multiple DirectoryIndex directives within the same context will add
# to the list of resources to look for rather than replace
# https://httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex
DirectoryIndex disabled
DirectoryIndex app_dev.php index.php index.html

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

Upvotes: 2

Views: 3439

Answers (2)

Fabiano Couto
Fabiano Couto

Reputation: 31

I also had a problem with symbolic links, and in my case it was because the link was with a physical path from the root of the system, and Docker somehow virtualizes the paths of the instance. As follows:

analyticsSync -> /media/user/DATA/dev/web/ic/analytics/public/sync/analyticsSync

I solved it by creating the relative symbolic link:

analyticsSync -> ic/analytics/public/sync/analyticsSync

"/media/user/DATA" is the physical path of my data partition, which is not recognized by Docker.

I hope it helps.

Upvotes: 1

ivoba
ivoba

Reputation: 5986

To answer my own question: thanks to the tips in the comments above, i logged in the container and checked the pathes and the symlinks were pathes of the host, so that couldnt work.

So i probably have to create the symlinks in the container, unless there is some way to tell docker to follow symlinks from the host, but i doubt that.

Upvotes: 1

Related Questions