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

Self Contained Binary not connecting to Mysql Database. #736

Open
fariatanha2024 opened this issue Apr 19, 2024 · 4 comments
Open

Self Contained Binary not connecting to Mysql Database. #736

fariatanha2024 opened this issue Apr 19, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@fariatanha2024
Copy link

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.

image

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 fariatanha2024 added the bug Something isn't working label Apr 19, 2024
@sneycampos
Copy link
Contributor

@fariatanha2024 could you share more details? .env configurations for example or php artisan about

@fariatanha2024
Copy link
Author

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.

@sneycampos
Copy link
Contributor

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?

@fariatanha2024
Copy link
Author

fariatanha2024 commented Apr 22, 2024

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.

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

2 participants