-1

I want to dockerize an existing PHP website but I am running into an issue. Can you help me to understand what is happening here?

Issue

The index.php page loads fine. However, all other pages such as about.php are not loading. It produces the error message shown below. I would like to understand why I cannot navigate to other pages.

I've verified that the project files are being copied to the docker container by connecting using the following command:

  • docker exec -it <container_id> bash

Looking at the code, we aren't using any third party libraries so I don't think it's a router type of issue. This is a basic website with little PHP functionality.

What's interesting is that I can run this site on my laptop using the default MacOS apache web server. The pages load fine. There must be a configuration in the docker image that I might need to change, but I am unsure what that would be.

Dockerfile

FROM php:8.2.5-apache as php

WORKDIR /var/www/html

COPY ./ ./

EXPOSE 80

Error

404 Not Found

The requested URL was not found on this server.

Apache/2.4.56 (Debian) Server at localhost Port 80

Thank you for your guidance.

6
  • 3
    When you shelled into the running container, did you use ls -la /var/www/html? What was the result? Please edit your question to include details of the files you expect to work and the exact URLs you're trying to open in your browser. I suspect this is a filename case problem since Linux file systems are case-sensitive Commented Apr 27, 2023 at 0:05
  • I see that the URL's work with the .php extension. It seems the developer had left off the .php extensions and I didn't pick up on that. http://localhost/about.php works, but the code has links like /about instead. This must have been intentional and I'll start researching how to handle the scenario where we drop off the file extension. Thank you for pointing that out. Commented Apr 27, 2023 at 1:15
  • 1
    Did the developer potentially leave out the .htaccess file that'd allow URL rewriting to occur and show the URL's without the .php extension? Commented Apr 27, 2023 at 1:38
  • 1
    You can achieve extension-less resource loading simply by using Apache's MultiViews Commented Apr 27, 2023 at 1:49
  • It's funny my question was closed. I didn't ask how to hide php extensions. I asked for guidance as to why pages weren't loading in a docker container. Commented Apr 27, 2023 at 11:36

1 Answer 1

-1

I will try to help maybe you need to change the base URL with this: base_url() In some cases: people usually use HTTP://localhost and when running the docker container domain name will change to HTTP://docker_container to fix this you need to set the base URL in PHP Code. I usually do this:

$base_url = "HTTP://docker_container";

and I usually do this on the link like this:

<a href="<?php echo $base_url; ?>/about.php">About</a>

I hope this can help you.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.