Publish a static site built in php without a certificate and without a DBMS

Can you recommend a script in Docker Compose to publish a static site built in PHP? I need the latest version of PHP (8.0.21) and Docker Compose.

I don’t need https.

I don’t need a database.

I have to publish a simple .php file like this:

<!doctype html>
<html lang="it">
<head><title>Ciao Mondo!</title></head>
<h1>Ciao Mondo!</h1>
<p>Questa &egrave; una semplice pagina PHP.</p>

The plain HTML example you’re showing is not using PHP. And the word “static” in the topic title also suggests you may not need any programming language at all?

That said, did you try php:<version>-apache from

1 Like

Thanks for the reply. I need php because in the .php pages I include some pieces of html code. I also use the if and for loops as well.
I don’t know which tag to use, there are too many options and I don’t know what code I need to write in the Dockerfile.
Tomorrow I’ll try to write something, thanks.

If you don’t specify a version or specific base image in the tag, you’ll use the most common and latest. So, with a file index.php that holds, say, <?php phpinfo(); ?> the following command, run from the folder that holds that file, should already allow you to browse to http://localhost to see the information page:

docker run --rm -p 80:80 -v "$PWD":/var/www/html php:8.1-apache

For Windows, you may need something else instead of "$PWD".

There is also a Dockerfile example on the page I linked to, which for a more recent version might read:

FROM php:8.1-apache
COPY src/ /var/www/html/

Without the need for a Dockerfile, docker-compose.yml may read something like:

version: "3.7"

    image: php:8.1-apache
      - 80:80
      - .:/var/www/html/
1 Like

If I write:
I am sent back to:
If I write:
the page is reached.
Is there a way to remove the redirect to https?
I use this code:

version: "3.9"

    build: ./php-apache
    image: image-php-eb:v.1.0
    container_name: container-php-eb
      - 80:80
      - type: bind
        source: ./volumes/data-php/
        target: /var/www/html/
    restart: on-failure
FROM php:8.1-apache

There is no redirect to HTTPS by default. Try it from an incognito window in your browser so if you tested SSL on localhost before, the browser will not remember that. If it doesn’t help, then it must be caused by your configuration or code.

$(pwd) instead of $PWD actually works in bash on Linux and in Powershell on Windows too.


It is very strange and I do not understand why such a thing happens, however it is true, if I open an incognito window I have no problems. I use Linux Ubuntu 22.04 LTS on vmware. Docker doesn’t work on Windows. Thank you

It is simply because. HTTP redirection can be permanent or temporary. Redirecting from HTTP to HTTPS is often permenent. If you try something on localhost, the browser saves that information and will continue to redirect even if the server doesn’t send the “Location” header in the HTTP response.

Docker does work on Windows and you can run Linux containers too, since Docker Desktop runs Docker in a virtual machine. It is just harder to configure in some cases.

I wonder, did you really want to accept your post as a solution instead of the answer from @avbentem who actually told you which image you could use and gave you an example?

1 Like

Thank you very much, all clear. On Windows it’s agony to install Docker, I’ve given up. I prefer to use Docker inside Ubuntu and inside Vmware. I corrected the tick on solution. Thanks for both of your contributions.