Home > Mobile >  Wordpress in Azure App Service unable to read files via symbolic link
Wordpress in Azure App Service unable to read files via symbolic link

Time:10-26

I have setup a containerized Wordpress project as a Azure App Service based on the official Wordpress Docker image where I have made no modifications to the image itself other than adding a SSH server based on the instructions given by Azure. This is what the Dockerfile looks like:

FROM wordpress:6.0.3-php7.4

########################################## Add SSH support for Azure ##########################################
# Install OpenSSH and set the password for root to "Docker!".
RUN apt update \
    && apt install -y openssh-server \
    && rm -rf /var/lib/apt/lists/*

RUN echo "root:Docker!" | chpasswd

# Copy the sshd_config file to the /etc/ssh/ directory
COPY docker/ssh/sshd_config /etc/ssh/

# Copy and configure the ssh_setup file
RUN mkdir -p /tmp
COPY docker/ssh/ssh_setup.sh /tmp
RUN chmod  x /tmp/ssh_setup.sh \
    && (sleep 1;/tmp/ssh_setup.sh 2>&1 > /dev/null)

# Open port 2222 for SSH access
EXPOSE 80 2222
###############################################################################################################

COPY docker/script.sh script.sh
RUN chmod  x script.sh
CMD []
ENTRYPOINT ["./script.sh"]

And docker/script.sh

#!/bin/bash
exec service ssh start &
exec /usr/local/bin/docker-entrypoint.sh apache2-foreground

On the App Service I have added the WEBSITES_ENABLE_APP_SERVICE_STORAGE=true application setting to enable persistent storage as well as set the WORDPRESS_DB_HOST, WORDPRESS_DB_NAME, WORDPRESS_DB_PASSWORD and WORDPRESS_DB_USER settings to connect to my database running on a another host.

When accessing the app service page in the browser and going through the Wordpress setup I can easily upload new files which are placed in the file system at /var/www/html/wp-content/uploads/<year>/<month>/<filename> which I can then access in my browser at https://my-app-service.azurewebsites.net/wp-content/uploads/<year>/<month>/<filename>.

With Azure only persisting data written in /home I instead tried to move the /var/www/html/wp-content/uploads directory to /home/uploads and then create a symbolic link to this from the expected path like so (the symbolic link creation could then also be added to the Dockerfile to automate this during deployment):

$ cd /var/www/html/wp-content
$ mv uploads /home/uploads
$ ln -s /home/uploads uploads

Now however, when I access https://my-app-service.azurewebsites.net/wp-content/uploads/<year>/<month>/<filename> I just get an empty 400 response.

In order to see if this was some sort of limitation of Azure I decided to try something similar with the most simple Python page instead. Dockerfile:

FROM python:3.10.0
RUN mkdir -p /var/www/html
WORKDIR /var/www/html

########################################## Add SSH support for Azure ##########################################
# Install OpenSSH and set the password for root to "Docker!".
RUN apt update \
    && apt install -y openssh-server \
    && rm -rf /var/lib/apt/lists/*

RUN echo "root:Docker!" | chpasswd

# Copy the sshd_config file to the /etc/ssh/ directory
COPY docker/ssh/sshd_config /etc/ssh/

# Copy and configure the ssh_setup file
RUN mkdir -p /tmp
COPY docker/ssh/ssh_setup.sh /tmp
RUN chmod  x /tmp/ssh_setup.sh \
    && (sleep 1;/tmp/ssh_setup.sh 2>&1 > /dev/null)

# Open port 2222 for SSH access
EXPOSE 80 2222
###############################################################################################################

COPY docker/script.sh script.sh
RUN chmod  x script.sh
CMD []
ENTRYPOINT ["./script.sh"]

And docker/script.sh

#!/bin/bash
exec service ssh start &
exec python -m http.server 80

Doing the same thing here works, so it doesn't seem to be a limitation with Azure. What I don't understand, however, is that the Wordpress docker image with the symbolic link works as expected running on my local machine.

What am I doing wrong? Why does the Python project work but not the Wordpress one?

CodePudding user response:

You have to change the configuration of apache webserver so, that it can follow symbolic links:

<VirtualHost *:80>
    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

CodePudding user response:

Solved it by adding an Alias instead of a symbolic link and disabling MMAP:

docker/extra.conf:

Alias /wp-content/uploads/ "/home/uploads/"
<Directory "/home/uploads/">
        Options Indexes MultiViews
        AllowOverride None
        Require all granted
</Directory>

<Directory "/home/uploads">
  EnableMMAP Off
</Directory>

docker/script.sh

#!/bin/bash
exec service ssh start &
exec /usr/local/bin/docker-entrypoint.sh apache2-foreground

Dockerfile

FROM wordpress:6.0.3-php7.4

########################################## Add SSH support for Azure ##########################################
# Install OpenSSH and set the password for root to "Docker!".
RUN apt update \
    && apt install -y openssh-server \
    && rm -rf /var/lib/apt/lists/*

RUN echo "root:Docker!" | chpasswd

# Copy the sshd_config file to the /etc/ssh/ directory
COPY docker/ssh/sshd_config /etc/ssh/

# Copy and configure the ssh_setup file
RUN mkdir -p /tmp
COPY docker/ssh/ssh_setup.sh /tmp
RUN chmod  x /tmp/ssh_setup.sh \
    && (sleep 1;/tmp/ssh_setup.sh 2>&1 > /dev/null)

# Open port 2222 for SSH access
EXPOSE 80 2222
###############################################################################################################

COPY docker/apache/extra.conf /etc/apache2/extra.conf
RUN cat /etc/apache2/extra.conf >> /etc/apache2/apache2.conf

COPY docker/script.sh /usr/local/bin/script.sh
RUN chmod  x /usr/local/bin/script.sh
CMD []
ENTRYPOINT ["/usr/local/bin/script.sh"]
  • Related