Open mevdschee opened 9 months ago
fixed here https://github.com/nik2208/php-crud-api-quick-start/commit/3fe5ae4f444c1f1079bf6d23b28acdc106dbb4b3 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?
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" }
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
.
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.
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?
I think the PHP_CRUD_API_ADDRESS should be the hostname of the database, not the URL.
I realised that and I fixed it, but the problem persists.
Can you post another dump of the env variables?
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
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
Can you see why I get a 404 on
http://127.0.0.1:8080/openapi
? I think it is about these lines:Can you confirm? What is causing that?