Self Contained Binary not connecting to Mysql Database.
What happened?
Hello,
I run the self contained binary which has a laravel application After running it I can see that database is not connecting.
MySQL database is running on my pc but binary app is not getting it.
Build Type
Standalone binary
Worker Mode
Yes
Operating System
GNU/Linux
CPU Architecture
x86_64
PHP configuration
PHP 8.1
Relevant log output
SQLSTATE[HY000] [2002] No such file or directory
@fariatanha2024 could you share more details? .env configurations for example or php artisan about
Did anyone created a self contained binary of Laravel project, Where Laravel project connects MySQL database locally? I think remote database can work but local database can't connect. Same project connects with MySQL database with no problem. But after converting it to binary code it can run itself but can't connect MySQL database. Maybe no service it can connect locally, it don't have any access to local service? Please if anyone converted real laravel project with local database to binary code let me know... My system don't work.
Did anyone created a self contained binary of Laravel project, Where Laravel project connects MySQL database locally? I think remote database can work but local database can't connect. Same project connects with MySQL database with no problem. But after converting it to binary code it can run itself but can't connect MySQL database. Maybe no service it can connect locally, it don't have any access to local service? Please if anyone converted real laravel project with local database to binary code let me know... My system don't work.
Could you share your setup? docker-compose.yml, Dockerfile, .env settings etc?
here is docker compose
version: "3.8"
services:
php:
build:
context: .
target: php
args:
- APP_ENV=${APP_ENV}
environment:
- APP_ENV=${APP_ENV}
- CONTAINER_ROLE=app
working_dir: /app
volumes:
- ./:/app
ports:
- 80:80
depends_on:
- db
privileged: true
networks:
- my-network
db:
image: mysql
restart: always
environment:
- MYSQL_DATABASE=${DB_DATABASE}
- MYSQL_USER=${DB_USERNAME}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
volumes:
- ./mysql_data:/var/lib/mysql
networks:
- my-network
phpmyadmin:
image: phpmyadmin
restart: always
ports:
- 8080:80
environment:
- PMA_ARBITRARY=1
- PMA_HOST=mysql
- PMA_PORT=3306
- UPLOAD_LIMIT=300M
networks:
- my-network
networks:
my-network:
This is docker file
FROM alpine:3.19.0 as php
WORKDIR /app
COPY . .
EXPOSE 80
CMD ["./laravel-app", "php-server", "--root=public/"]
# CMD ["tail", "-f", "/dev/null"]
Note Here in this docker file I don't created the binary. From different dockerfile I first created the binary then I put the binary this project main folder then I built. Generation of the binary in different dockerfile.
Below this docker file generates the binary.
FROM --platform=linux/amd64 dunglas/frankenphp:static-builder as builder
# Copy your app
WORKDIR /go/src/app/dist/app
COPY ./src/. .
WORKDIR /go/src/app/
RUN EMBED=dist/app/ \
FRANKENPHP_VERSION=1.1.2 \
PHP_EXTENSIONS=mbstring,intl,mysqli,pdo_mysql,zip,gd \
PHP_VERSION=8.1 \
./build-static.sh
FROM alpine:3.19.0
WORKDIR /app
COPY --from=builder /go/src/app/dist/frankenphp-linux-x86_64 laravel-app
EXPOSE 80
CMD ["./laravel-app", "php-server", "--root=public/"];
And for both docker project the same env
Here is the ENV
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:r/xs7wkqK9eaVc/A3/k49iKVfkWb8cpOyND/9bvNHPM=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=medi_spa
DB_USERNAME=medispa
DB_PASSWORD=12345678
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
I tried with many combination. With and without using docker-compose to run it. None of the way can able to connect the Mysql database.