0

I am running apache2 2.4.10 in a debian docker container using below docker-compose file:

version: '3.8'
services:
  apache2-php:
    container_name: apache2-php-container
    image: apache2-php-image
    build:
      context: ./docker/apache2
    ports:
      - "8082:80"
    volumes:
      - ./docker/apache2/index.php:/var/www/index.php
 

with this site.

<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName localhost
    ServerAlias localhost
    DocumentRoot /var/www
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Its up an running just fine but for some reason logs are written to stdout/stderr instead of above specified files. Also I see:

$ ls -la /var/log/apache2
total 8
drwxrwxrwx 2 www-data www-data 4096 Dec 29  2018 .
drwxr-xr-x 1 root     root     4096 Dec 29  2018 ..
lrwxrwxrwx 1 www-data www-data   11 Dec 29  2018 access.log -> /dev/stdout
lrwxrwxrwx 1 www-data www-data   11 Dec 29  2018 error.log -> /dev/stderr
lrwxrwxrwx 1 www-data www-data   11 Dec 29  2018 other_vhosts_access.log -> /dev/stdout

Do I need to add some option in my site to force apache2 to write to the actual files instead of to stdout/stderr?

u123
  • 267
  • 1
  • 8
  • 24

1 Answers1

1

For some reason those are symlinks to the device files for stdout and stderr. To make Apache write to actual files, you simply need to remove the symlinks and restart Apache:

sudo rm /var/log/apache2/{access,error,other_vhosts_access}.log
sudo systemctl restart apache2
ThatGraemeGuy
  • 15,473
  • 12
  • 53
  • 79
  • Sorry was leaving out the docker details since I assumed it was irrelevant but could this be cause by some docker convention that logs are always written to stdout unless something explicit config is set - if possible? – u123 Nov 13 '21 at 19:55
  • I couldn't say, I'm not familiar with Docker. – ThatGraemeGuy Dec 24 '21 at 10:52