Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 when accessing http://127.0.0.1:8080/openapi #3

Closed
mevdschee opened this issue Oct 12, 2023 · 11 comments
Closed

404 when accessing http://127.0.0.1:8080/openapi #3

mevdschee opened this issue Oct 12, 2023 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@mevdschee
Copy link
Contributor

mevdschee commented Oct 12, 2023

maurits@n100dc:~/projects/php-crud-api-quick-start$ docker-compose up
Starting mysql_treeqlqs ... done
Starting php-fpm_treeqlqs ... done
Starting nginx_treeqlqs   ... done
Starting dbadmin_treeqlqs ... done
Starting swagger_treeqlqs ... done
Attaching to mysql_treeqlqs, php-fpm_treeqlqs, nginx_treeqlqs, dbadmin_treeqlqs, swagger_treeqlqs
dbadmin_treeqlqs | [Thu Oct 12 17:45:49 2023] PHP 7.4.33 Development Server (http://[::]:8080) started
nginx_treeqlqs |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
nginx_treeqlqs |                                  Dload  Upload   Total   Spent    Left  Speed
mysql_treeqlqs | 2023-10-12 17:45:48+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.1.0-1.el8 started.
100  480k  100  480k    0     0  1596k      0 --:--:-- --:--:-- --:--:-- 1600k
nginx_treeqlqs | 2023/10/12 17:45:49 [warn] 1#1: server name "http://127.0.0.1:8080/" has suspicious symbols in /etc/nginx/conf.d/default.conf:3
nginx_treeqlqs | nginx: [warn] server name "http://127.0.0.1:8080/" has suspicious symbols in /etc/nginx/conf.d/default.conf:3
nginx_treeqlqs | 2023/10/12 17:45:49 [notice] 1#1: using the "epoll" event method
nginx_treeqlqs | 2023/10/12 17:45:49 [notice] 1#1: nginx/1.25.2
nginx_treeqlqs | 2023/10/12 17:45:49 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14) 
nginx_treeqlqs | 2023/10/12 17:45:49 [notice] 1#1: OS: Linux 6.5.3-060503-generic
nginx_treeqlqs | 2023/10/12 17:45:49 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
nginx_treeqlqs | 2023/10/12 17:45:49 [notice] 1#1: start worker processes
nginx_treeqlqs | 2023/10/12 17:45:49 [notice] 1#1: start worker process 10
nginx_treeqlqs | 2023/10/12 17:45:49 [notice] 1#1: start worker process 11
nginx_treeqlqs | 2023/10/12 17:45:49 [notice] 1#1: start worker process 12
nginx_treeqlqs | 2023/10/12 17:45:49 [notice] 1#1: start worker process 13
php-fpm_treeqlqs | [12-Oct-2023 17:45:48] NOTICE: fpm is running, pid 1
php-fpm_treeqlqs | [12-Oct-2023 17:45:48] NOTICE: ready to handle connections
mysql_treeqlqs | 2023-10-12 17:45:48+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql_treeqlqs | 2023-10-12 17:45:48+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.1.0-1.el8 started.
mysql_treeqlqs | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
swagger_treeqlqs | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
swagger_treeqlqs | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
mysql_treeqlqs | 2023-10-12T17:45:48.998140Z 0 [System] [MY-015015] [Server] MySQL Server - start.
mysql_treeqlqs | 2023-10-12T17:45:49.228034Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
mysql_treeqlqs | 2023-10-12T17:45:49.229705Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.1.0) starting as process 1
swagger_treeqlqs | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
mysql_treeqlqs | 2023-10-12T17:45:49.240752Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql_treeqlqs | 2023-10-12T17:45:49.437918Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql_treeqlqs | 2023-10-12T17:45:49.697991Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql_treeqlqs | 2023-10-12T17:45:49.698019Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql_treeqlqs | 2023-10-12T17:45:49.703899Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
swagger_treeqlqs | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
mysql_treeqlqs | 2023-10-12T17:45:49.733495Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
mysql_treeqlqs | 2023-10-12T17:45:49.733774Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.1.0'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
swagger_treeqlqs | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
swagger_treeqlqs | /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
swagger_treeqlqs | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
swagger_treeqlqs | 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/default.conf.template to /etc/nginx/conf.d/default.conf
swagger_treeqlqs | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
swagger_treeqlqs | /docker-entrypoint.sh: Launching /docker-entrypoint.d/40-swagger-ui.sh
swagger_treeqlqs | /docker-entrypoint.sh: Configuration complete; ready for start up
swagger_treeqlqs | 2023/10/12 17:45:50 [notice] 1#1: using the "epoll" event method
swagger_treeqlqs | 2023/10/12 17:45:50 [notice] 1#1: nginx/1.25.2
swagger_treeqlqs | 2023/10/12 17:45:50 [notice] 1#1: built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r10) 
swagger_treeqlqs | 2023/10/12 17:45:50 [notice] 1#1: OS: Linux 6.5.3-060503-generic
swagger_treeqlqs | 2023/10/12 17:45:50 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
swagger_treeqlqs | 2023/10/12 17:45:50 [notice] 1#1: start worker processes
swagger_treeqlqs | 2023/10/12 17:45:50 [notice] 1#1: start worker process 57
swagger_treeqlqs | 2023/10/12 17:45:50 [notice] 1#1: start worker process 58
swagger_treeqlqs | 2023/10/12 17:45:50 [notice] 1#1: start worker process 59
swagger_treeqlqs | 2023/10/12 17:45:50 [notice] 1#1: start worker process 60
php-fpm_treeqlqs | ERROR: Passing INI directive through FastCGI: unable to set 'root'
php-fpm_treeqlqs | 172.18.0.4 -  12/Oct/2023:17:45:58 +0000 "GET /api.php" 404
nginx_treeqlqs | 172.18.0.1 - - [12/Oct/2023:17:45:58 +0000] "GET /openapi HTTP/1.1" 404 27 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/118.0"

Can you see why I get a 404 on http://127.0.0.1:8080/openapi? I think it is about these lines:

php-fpm_treeqlqs | ERROR: Passing INI directive through FastCGI: unable to set 'root'
php-fpm_treeqlqs | 172.18.0.4 -  12/Oct/2023:17:50:09 +0000 "GET /api.php" 404

Can you confirm? What is causing that?

@nik2208 nik2208 self-assigned this Oct 13, 2023
@nik2208 nik2208 added the bug Something isn't working label Oct 13, 2023
nik2208 added a commit that referenced this issue Oct 13, 2023
@nik2208
Copy link
Owner

nik2208 commented Oct 13, 2023

fixed here 3fe5ae4 just missed to put api.php in the right position (it worked on my machine for the exact reason I asked you to try it 😅 )

would u give it a try again?

@nik2208
Copy link
Owner

nik2208 commented Oct 13, 2023

there's still something missing.

this

web:
    image: nginx:latest
    container_name: nginx_treeqlqs
    restart: always
    environment:
      SERVER_NAME: ${SERVER_NAME}
      PHP_CRUD_API_PORT: ${PORT}
      PHP_CRUD_API_ADDRESS: ${SERVER_NAME}
      PHP_CRUD_API_DATABASE: ${MYSQL_DATABASE}
      PHP_CRUD_API_USERNAME: ${MYSQL_USER}
      PHP_CRUD_API_PASSWORD: ${MYSQL_PASSWORD}
      PHP_CRUD_API_DEBUG: ${PHP_CRUD_API_DEBUG}
    volumes:
      - ./nginx/default.conf.template:/etc/nginx/conf.d/default.conf.template
      - ./php:/var/www/html
    ports:
      - "${PORT}:80"
    command: /bin/bash -c "curl -o /var/www/html/api.php https://raw.githubusercontent.com/mevdschee/php-crud-api/main/api.php && envsubst '$$SERVER_NAME' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
    depends_on:
      - php
    networks: 
      - php-api-network

is the code setting up the nginx container.

all the env variables are properly set and available in the nginx container shell (I've checked their values one by one) but I'm getting

PDOException occurred (enable debug mode)

I found the exception in api.php but I'm not able to understand what causes it.

As long as I was using a static version (copy-pasted) of api.php turned into template and configured via envsubst everything was working
Using the env variables somethings wrong happens.

UPDATES
After further investigations, even if the env variables are properly set in the system, they aren't used by api.php:
if I leave a copy of api.php and set the config values, everything works correctly.

Enabling the debug flag, the previous PDO exception error turns into
{ "code": 9999, "message": "SQLSTATE[HY000] [2002] No such file or directory" }

Screenshot 2023-10-13 at 13 11 08

@mevdschee
Copy link
Contributor Author

SQLSTATE[HY000] [2002] No such file or directory

Probably you have no access to /var/lib/mysql/mysql.sock or you should connect on 127.0.0.1 instead of localhost.

@nik2208
Copy link
Owner

nik2208 commented Oct 14, 2023

It's something related to the env variables. If I properly set the configuration fields it works. If I leave the config section as is counting on the docker compose env variables it doesn't.

@nik2208
Copy link
Owner

nik2208 commented Oct 15, 2023

Do u have any hint/idea on why the api.php is unable to catch the env variables in the nginx image even if the are there as shown by the screenshot above?

@mevdschee
Copy link
Contributor Author

I think the PHP_CRUD_API_ADDRESS should be the hostname of the database, not the URL.

@nik2208
Copy link
Owner

nik2208 commented Oct 15, 2023

I realised that and I fixed it, but the problem persists.

@mevdschee
Copy link
Contributor Author

Can you post another dump of the env variables?

@jaanbv
Copy link

jaanbv commented Mar 21, 2024

Hi, I had the same issue and solved it by some changements in the docker-compose file. The debug var and some other things were not on the right place.
docker-compose.yml.txt

@bl45107
Copy link

bl45107 commented Jul 4, 2024

I think the PHP_CRUD_API_ADDRESS should be the hostname of the database, not the URL.

Yes, you are correct, current container_name is "mysql_treeqlqs" so:

$config = new Config([
        // 'driver' => 'mysql',
        'address' => 'mysql_treeqlqs',
        // 'port' => '3306',
        ...

This error is not impactful:

php-fpm_treeqlqs | ERROR: Passing INI directive through FastCGI: unable to set 'root'
php-fpm_treeqlqs | 172.18.0.4 -  12/Oct/2023:17:50:09 +0000 "GET /api.php" 404

@nik2208
Copy link
Owner

nik2208 commented Oct 15, 2024

fixed in 1.0.3

@nik2208 nik2208 closed this as completed Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants