How do I fix my ngnix unit config.json to work with wordpress on the unit:php8.2 docker image?

I’m trying to configure wordpress on my docker unit:php8.2 image as such:

{
  "listeners": {
    "*:80": {
      "pass": "routes"
    }

  },

  "routes": [
    {
      "match": {
        "uri": [
          "*.php",
          "*.php/*",
          "/wp-admin/"
        ]
      },

      "action": {
        "pass": "applications/wordpress/direct"
      }
    },
    {
      "action": {
        "share": "/app/$uri",
        "fallback": {
          "pass": "applications/wordpress/index"
        }
      }
    }
  ],

  "applications": {
    "wordpress": {
      "type": "php",
      "targets": {
        "direct": {
          "root": "/app"
        },

        "index": {
          "root": "/app",
          "script": "index.php"
        }
      }
    }
  }
}

Instead of passing the request http://localhost to the PHP engine, it seems to send back the index.php file for me to download.

Please help. :slight_smile:

edit I checked the perms and they are 0777. I also moved it to /var/www/html to no avail.

Clearly it’s seeing my index.php file but sending it back as raw text (static file?) instead of parsing it through the PHP engine.

It is also seeing my config.json file and reconfiguring as per the logs:

app-1  | /usr/local/bin/docker-entrypoint.sh: Applying configuration /docker-entrypoint.d/config.json
app-1  | /usr/local/bin/docker-entrypoint.sh: OK: HTTP response status code is '200'
 }success": "Reconfiguration done."

Why is the topic tagged with “Window containers”? I don’t see Windows support on Docker Hub for that image:

https://hub.docker.com/_/unit/tags?page=1&name=php

So I guess you mean Linux containers on Windows in Docker Desktop’s virtual machine.

Unfortunately I don’t know anything about Unit, and you haven’T shared any Docker config that would indicate it is a Docker issue, so I found the Unit documentation if that helps:

and the link to the Docker images which I’M sure you new already

https://unit.nginx.org/installation/#docker-images

In general, an NginX server is just a proxy for the PHP FPM process so you need a PHP interpreter, but it seems the php variant of the unit image contains PHP as well. I don’t think it is a permission issue because than the php file would not be shown as HTML. If it does, the interpreter was not called and nginx returned it because it didn’t know the file was PHP.

1 Like

Thanks for the reply @rimelek , my first post here and quite recently jumped into the docker world.

My wordpress configuration is pretty much from this link.

Yeah, it’s seeing the file and sending it back to me. I think somehow, the PHP engine isn’t processing it before it’s sent. I think it’s more of a unit configuration but I’m stumped as I copied the config from the Nginx unit website and assume it to be correct. But posting here hoping someone has done it with the unit:php8.2 image before.

DOCKERFILE

FROM unit:php8.2
LABEL authors="abc"

EXPOSE 80

WORKDIR /var/www/html
#WORKDIR /app
#RUN chown -R www-data:www-data /app

COPY . /var/www/html
#COPY . /app

COPY ./unit-config.json /docker-entrypoint.d/config.json

@rimelek

So this might also help. I started another docker project, same docker file, same unit config. But I replaced Wordpress with a simple hello world index.php file. And it worked. The logs are also interesting. In the docker-php log, without wordpress, it stated that it started the wordpress application. However, in the WordPress docker, it didn’t.

Docker log docker-wp

 ✔ Network docker-wp_default  Created                                                                              0.1s
 ✔ Container mariadb          Started                                                                              0.1s
  D:\code\learn\docker-wp  main ≢  ?6   1.109s   
❯  docker compose up app                                                                            in pwsh at 18:52:19
[+] Running 1/1
 ✔ Container docker-wp-app-1  Created                                                                              0.1s
Attaching to app-1
app-1  | /usr/local/bin/docker-entrypoint.sh: Launching Unit daemon to perform initial configuration...
app-1  | 2023/12/19 11:52:25 [info] 8#8 unit 1.31.1 started
app-1  | 2023/12/19 11:52:25 [info] 10#10 discovery started
app-1  | 2023/12/19 11:52:25 [notice] 10#10 module: php 8.2.13 "/usr/lib/unit/modules/php.unit.so"
app-1  | 2023/12/19 11:52:25 [info] 9#9 controller started
app-1  | 2023/12/19 11:52:25 [notice] 9#9 process 10 exited with code 0
app-1  | 2023/12/19 11:52:25 [info] 14#14 router started
app-1  | 2023/12/19 11:52:25 [info] 14#14 OpenSSL 1.1.1w  11 Sep 2023, 1010117f
app-1  | {
app-1  |        "certificates": {},
app-1  |        "js_modules": {},
app-1  |        "config": {
app-1  |                "listeners": {},
app-1  |                "routes": [],
app-1  |                "applications": {}
app-1  |        },
app-1  |
app-1  |        "status": {
app-1  |                "connections": {
app-1  |                        "accepted": 0,
app-1  |                        "active": 0,
app-1  |                        "idle": 0,
app-1  |                        "closed": 0
app-1  |                },
app-1  |
app-1  |                "requests": {
app-1  |                        "total": 0
app-1  |                },
app-1  |
app-1  |                "applications": {}
app-1  |        }
app-1  | }
app-1  | /usr/local/bin/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, applying initial configuration...
app-1  | /usr/local/bin/docker-entrypoint.sh: Looking for certificate bundles in /docker-entrypoint.d/...
app-1  | /usr/local/bin/docker-entrypoint.sh: Looking for JavaScript modules in /docker-entrypoint.d/...
app-1  | /usr/local/bin/docker-entrypoint.sh: Looking for configuration snippets in /docker-entrypoint.d/...
app-1  | /usr/local/bin/docker-entrypoint.sh: Applying configuration /docker-entrypoint.d/config.json
app-1  | /usr/local/bin/docker-entrypoint.sh: OK: HTTP response status code is '200'
 }success": "Reconfiguration done."
app-1  | /usr/local/bin/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/...
app-1  | /usr/local/bin/docker-entrypoint.sh: Stopping Unit daemon after initial configuration...
app-1  | 2023/12/19 11:52:25 [notice] 9#9 process 13 exited with code 0
app-1  | /usr/local/bin/docker-entrypoint.sh: Waiting for control socket to be removed...
app-1  | 2023/12/19 11:52:25 [notice] 9#9 process 14 exited with code 0
app-1  |
app-1  | /usr/local/bin/docker-entrypoint.sh: Unit initial configuration complete; ready for start up...
app-1  |
app-1  | 2023/12/19 11:52:26 [info] 1#1 unit 1.31.1 started
app-1  | 2023/12/19 11:52:26 [info] 36#36 discovery started
app-1  | 2023/12/19 11:52:26 [notice] 36#36 module: php 8.2.13 "/usr/lib/unit/modules/php.unit.so"
app-1  | 2023/12/19 11:52:26 [info] 1#1 controller started
app-1  | 2023/12/19 11:52:26 [info] 38#38 router started
app-1  | 2023/12/19 11:52:26 [notice] 1#1 process 36 exited with code 0
app-1  | 2023/12/19 11:52:26 [info] 38#38 OpenSSL 1.1.1w  11 Sep 2023, 1010117f

docker log docker-php (simple index.php)

 ✔ Container docker-php-app-1  Removed                                                                             0.0s
 ✔ Network docker-php_default  Removed                                                                             0.2s
  D:\code\learn\docker-php   787ms   
❯  docker compose up app                                                                            in pwsh at 18:51:54
[+] Running 2/2
 ✔ Network docker-php_default  Created                                                                             0.1s
 ✔ Container docker-php-app-1  Created                                                                             0.1s
Attaching to app-1
app-1  | /usr/local/bin/docker-entrypoint.sh: Launching Unit daemon to perform initial configuration...
app-1  | 2023/12/19 11:55:08 [info] 10#10 unit 1.31.1 started
app-1  | 2023/12/19 11:55:08 [info] 13#13 discovery started
app-1  | 2023/12/19 11:55:08 [notice] 13#13 module: php 8.2.13 "/usr/lib/unit/modules/php.unit.so"
app-1  | 2023/12/19 11:55:08 [info] 11#11 controller started
app-1  | 2023/12/19 11:55:08 [notice] 11#11 process 13 exited with code 0
app-1  | 2023/12/19 11:55:08 [info] 16#16 router started
app-1  | 2023/12/19 11:55:08 [info] 16#16 OpenSSL 1.1.1w  11 Sep 2023, 1010117f
app-1  | {
app-1  |        "certificates": {},
app-1  |        "js_modules": {},
app-1  |        "config": {
app-1  |                "listeners": {},
app-1  |                "routes": [],
app-1  |                "applications": {}
app-1  |        },
app-1  |
app-1  |        "status": {
app-1  |                "connections": {
app-1  |                        "accepted": 0,
app-1  |                        "active": 0,
app-1  |                        "idle": 0,
app-1  |                        "closed": 0
app-1  |                },
app-1  |
app-1  |                "requests": {
app-1  |                        "total": 0
app-1  |                },
app-1  |
app-1  |                "applications": {}
app-1  |        }
app-1  | }
app-1  | /usr/local/bin/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, applying initial configuration...
app-1  | /usr/local/bin/docker-entrypoint.sh: Looking for certificate bundles in /docker-entrypoint.d/...
app-1  | /usr/local/bin/docker-entrypoint.sh: Looking for JavaScript modules in /docker-entrypoint.d/...
app-1  | /usr/local/bin/docker-entrypoint.sh: Looking for configuration snippets in /docker-entrypoint.d/...
app-1  | /usr/local/bin/docker-entrypoint.sh: Applying configuration /docker-entrypoint.d/config.json
app-1  | 2023/12/19 11:55:08 [info] 23#23 "wordpress" prototype started
app-1  | 2023/12/19 11:55:08 [info] 24#24 "wordpress" application started
app-1  | /usr/local/bin/docker-entrypoint.sh: OK: HTTP response status code is '200'
 }success": "Reconfiguration done."
app-1  | /usr/local/bin/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/...
app-1  | /usr/local/bin/docker-entrypoint.sh: Stopping Unit daemon after initial configuration...
app-1  | 2023/12/19 11:55:08 [notice] 11#11 process 15 exited with code 0
app-1  | /usr/local/bin/docker-entrypoint.sh: Waiting for control socket to be removed...
app-1  | 2023/12/19 11:55:08 [notice] 11#11 process 16 exited with code 0
app-1  | 2023/12/19 11:55:08 [notice] 23#23 app process 24 exited with code 0
app-1  | 2023/12/19 11:55:08 [alert] 23#23 sendmsg(13, -1, -1, 2) failed (32: Broken pipe)
app-1  | 2023/12/19 11:55:08 [notice] 11#11 process 23 exited with code 0
app-1  |
app-1  | /usr/local/bin/docker-entrypoint.sh: Unit initial configuration complete; ready for start up...
app-1  |
app-1  | 2023/12/19 11:55:09 [info] 1#1 unit 1.31.1 started
app-1  | 2023/12/19 11:55:09 [info] 40#40 discovery started
app-1  | 2023/12/19 11:55:09 [notice] 40#40 module: php 8.2.13 "/usr/lib/unit/modules/php.unit.so"
app-1  | 2023/12/19 11:55:09 [info] 1#1 controller started
app-1  | 2023/12/19 11:55:09 [notice] 1#1 process 40 exited with code 0
app-1  | 2023/12/19 11:55:09 [info] 42#42 router started
app-1  | 2023/12/19 11:55:09 [info] 42#42 OpenSSL 1.1.1w  11 Sep 2023, 1010117f
app-1  | 2023/12/19 11:55:09 [info] 43#43 "wordpress" prototype started
app-1  | 2023/12/19 11:55:09 [info] 44#44 "wordpress" application started

Does it help?