Apache doesn't have write permissions any more

Hi,

As of last night, one of our servers doesn’t seem to be able to write files anymore:

Unable to open /home/japan/web/x.com/cgi-bin/news/admin/backup/BACKUP for writing: Read-only file system at nph-build.cgi line 335.

drwxrwxr-x 2 japan japan 4.0K Nov 26 15:23 backup

ls -ls
total 67832
67832 -rw-rw-r-- 1 japan japan 69456534 Nov 26 15:32 BACKUP

Is there anything in Apache that could cause this? Here is the apache config:

#=========================================================================#

# Default Web Domain Template                                             #

# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS   #

# 
      #

#=========================================================================#




<VirtualHost 139.162.106.5:8443>




    ServerName x.com

    ServerAlias www.x.com

    ServerAdmin [email protected]

    DocumentRoot /home/japan/web/x.com/public_html

    ScriptAlias /cgi-bin/ /home/japan/web/x.com/cgi-bin/

    Alias /vstats/ /home/japan/web/x.com/stats/

    Alias /error/ /home/japan/web/x.com/document_errors/

    SuexecUserGroup japan japan

    CustomLog /var/log/apache2/domains/x.com.bytes bytes

    CustomLog /var/log/apache2/domains/x.com.log combined

    ErrorLog /var/log/apache2/domains/x.com.error.log

    <Directory /home/japan/web/x.com/stats>

        AllowOverride All

    </Directory>

    <Directory /home/japan/web/x.com/public_html>

        AllowOverride All

        SSLRequireSSL

        Options +Includes -Indexes +ExecCGI

    </Directory>

    <Directory "/home/japan/web/x.com/cgi-bin">

        AllowOverride AuthConfig

        Options +ExecCGI -Indexes

        Require all granted

    </Directory>    

    SSLEngine on

    SSLVerifyClient none

    SSLCertificateFile /home/japan/conf/web/x.com/ssl/x.com.crt

    SSLCertificateKeyFile /home/japan/conf/web/x.com/ssl/x.com.key

    SSLCertificateChainFile /home/japan/conf/web/x.com/ssl/x.com.ca




    <FilesMatch \.php$>

        SetHandler "proxy:unix:/run/php/php8.4-fpm-x.com.sock|fcgi://localhost"

    </FilesMatch>

    SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0




    IncludeOptional /home/japan/conf/web/x.com/apache2.ssl.conf_*

    IncludeOptional /etc/apache2/conf.d/*.inc

</VirtualHost>

The only way I can get it working is by doing:

mkdir -p /etc/systemd/system/apache2.service.d
printf '%s\n' '[Service]' 'ProtectHome=false' \
  > /etc/systemd/system/apache2.service.d/zz-local-protect-home.conf
systemctl daemon-reload
systemctl show apache2 -p ProtectHome

But thats really dirty - and I don’t like it. Something must have changed somewhere thats broken this, as it was working about 9 hours ago, before the last update :confused:

Apache2 has been updated so I suppose the systemd service conf have changed (at least on Ubuntu).

❯ systemctl cat apache2 --no-pager
# /usr/lib/systemd/system/apache2.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=https://httpd.apache.org/docs/2.4/

[Service]
Type=notify
Environment=APACHE_STARTED_BY_SYSTEMD=true
ExecStart=/usr/sbin/apachectl start
ExecStop=/usr/sbin/apachectl graceful-stop
ExecReload=/usr/sbin/apachectl graceful
# Send SIGWINCH for graceful stop
KillSignal=SIGWINCH
KillMode=mixed
PrivateTmp=true
Restart=on-abnormal
OOMPolicy=continue
RemoveIPC=yes

DevicePolicy=closed
KeyringMode=private
LockPersonality=yes
MemoryDenyWriteExecute=yes
PrivateDevices=yes
ProtectClock=yes
ProtectControlGroups=yes
ProtectHome=read-only
ProtectHostname=yes
ProtectKernelLogs=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
ProtectSystem=full
RestrictNamespaces=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
SystemCallArchitectures=native
ProtectProc=invisible
ProcSubset=pid

ReadWritePaths=-/var/log/apache2
ReadWritePaths=-/var/cache/apache2/mod_cache_disk

InaccessiblePaths=/boot
InaccessiblePaths=/root
InaccessiblePaths=-/etc/sudoers
InaccessiblePaths=-/etc/sudoers.d
InaccessiblePaths=-/etc/ssh
InaccessiblePaths=-/etc/apt
InaccessiblePaths=-/etc/.git
InaccessiblePaths=-/etc/.svn

[Install]
WantedBy=multi-user.target

Show the output of these commands:

dpkg -l | grep 'apache2 '
systemctl cat apache2 --no-pager

Why? Adding the override is the way to go, so Apache2 works as it was working before the update.