Hi,
I try to setup a container around wordpress as an exercise, so I know there must be ready to go images out there, but I need to do this
I get a 404 on the root page (index.php)
For comparison, I installed wamp to test the wordpress source I use and it works fine
I just dont understand what is going wrong here
Here is my docker file
# Use the official PHP image with Apache
FROM php:8.1-apache
# Install required
RUN apt-get update && apt-get install -y \
nano \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install gd \
&& docker-php-ext-install mysqli pdo pdo_mysql \
&& apt-get install -y wget unzip
# Enable Apache mod_rewrite
RUN a2enmod rewrite
RUN docker-php-ext-install pdo pdo_mysql fileinfo
# Set the working directory
WORKDIR /var/www/html
# Copy the custom php.ini file to the container
COPY ./php.ini /usr/local/etc/php/
# Set permissions for phpMyAdmin directory
RUN chown -R www-data:www-data /var/www/html
# Expose port 80
EXPOSE 80
# Start Apache
CMD ["apache2-foreground"]
my docker-compose.yml looks like this
version: '3.8'
services:
apache:
build:
context: .
dockerfile: Dockerfile
container_name: apache_server
ports:
- "80:80"
volumes:
- "c:/docker/www:/var/www/html/" # PHP source code
depends_on:
- db
db:
image: mysql:5.7
container_name: mysql_server
environment:
DB_HOST: localhost
DB_NAME: ***
DB_USER: ***
DB_PASSWORD: ***
MYSQL_ROOT_PASSWORD: ***
MYSQL_DATABASE: ***
MYSQL_USER: ***
MYSQL_PASSWORD: ***
ports:
- "3306:3306" # Maps localhost:3306 to container's port 3306
volumes:
- "c:/docker/mysql-data:/var/lib/mysql" # Persistent MySQL data
networks:
default:
driver: bridge
don’t know if any of you can help me out, this seems like a problem between apache and docker
thanks for your help
bluepuma77
(Bluepuma77)
December 10, 2024, 5:51am
2
Docker Desktop runs the containers in a Linux VM. You need to ensure that the Windows folder is available in Docker Desktop (“shared”).
then why the phpmyadmin folder and it index.php work as expected ?
bluepuma77
(Bluepuma77)
December 10, 2024, 10:07am
4
Get started with your problem solving skills
Check that you use the right folder inside container
Check inside container that files are at the right place and readable
Create a test file inside container and see if it can be served by Apache
Check that your Apache config is correct
Check Apache error logs
files are there definitely, I could bash to the container, go to /var/www/html, everything is there
docker exec -it apache_server bash
chown -R www-data:www-data /var/www/html/wordpress
chmod -R 755 /var/www/html/wordpress
I can even GET the wordpress licence.txt file
wp-admin index is working
the only index.php not working is the one at the roor folder, which makes no sense
all the files have the right attributes and are readable
[had to put this one in a separate answer]
as I check the log, the only thing appearing is a 404 error
bluepuma77
(Bluepuma77)
December 10, 2024, 11:33am
8
If some requests to your container work and some do not, then it should be a web server or WordPress configuration issue.
It has nothing to do with the Docker container.
the same source code put in a wamp server works perfectly fine
bluepuma77
(Bluepuma77)
December 10, 2024, 7:48pm
10
I don’t know what a wamp server is.
But I do know that Docker will never return a 404 to you. Either a port is published and reaches the container internal service or not. But Docker will not create a 404 error.
rimelek
(Ákos Takács)
December 10, 2024, 7:51pm
11
phil12345678910:
files are there definitely, I could bash to the container, go to /var/www/html, everything is there
docker exec -it apache_server bash
chown -R www-data:www-data /var/www/html/wordpress
chmod -R 755 /var/www/html/wordpress
Since you copied the files to the workdir not under wordpress, what is the purpose of the above commands?
phil12345678910:
admin is available
But you also added the PHP file to the URL. Have you tried http://localhost/index.php
?
In Apache HTTPD servers you need to set the DirectoryIndex to allow automatically loading PHP files. You could use the official Wordpress image too or at least compare your settings with the settings in that image.
It is also possible (since the official PHP image was used as a base image) that the directoryindex is correct, but the enabling the rewrite modul was not enough and you need to enable the rewrite for the document root using RewriteEngine On .
Of course if the directoryindex is correct, then it should load without the rewrite module, but I still assume something wrong with these settings.