I can use xdebug on a the web app, but when I try to execute a Symfony command, the execution doesn't stop at breakpoints.
This is my dockerfile:
FROM phpdockerio/php74-fpm:latest
WORKDIR "/application"
# Fix debconf warnings upon build
ARG DEBIAN_FRONTEND=noninteractive
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install php7.4-gd php7.4-memcached php7.4-mysql php7.4-redis php7.4-xdebug \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
RUN apt-get update \
&& apt-get -y --no-install-recommends install libfontconfig1 libxrender1 libxext6 \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
this is my docker-compose
version: "3.1"
services:
memcached:
image: memcached:alpine
container_name: my-memcached
mailhog:
image: mailhog/mailhog:latest
container_name: my-mailhog
ports:
- "1026:8025"
redis:
image: redis:alpine
container_name: my-redis
mariadb:
image: mariadb:10.4
container_name: my-mariadb
working_dir: /application
volumes:
- .:/application
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=mydb
- MYSQL_USER=mypass
- MYSQL_PASSWORD=secret
ports:
- "1028:3306"
webserver:
image: nginx:alpine
container_name: my-webserver
working_dir: /application
volumes:
- .:/application
- ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "80:80"
php-fpm:
build: phpdocker/php-fpm
container_name: my-php-fpm
working_dir: /application
environment:
PHP_IDE_CONFIG: "serverName=myServer"
volumes:
- .:/application
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini
extra_hosts:
- "host.docker.internal:host-gateway"
this is my php-ini-overrides
upload_max_filesize = 100M
post_max_size = 108M
[Xdebug]
;zend_extension="/usr/lib/php/20210902/xdebug.so"
xdebug.mode=debug
xdebug.idekey=PHPSTORM
xdebug.client_port=9003
xdebug.start_with_request=yes
xdebug.discover_client_host=0
xdebug.client_host=host.docker.internal
NO problem with web applications , but is not possible to debug cli apps, I added tried to add some variables to all files but never worked, Do I missed something?
Uncomment the zend_extension and fill the proper path to .so file.
The global $_SERVER variable is not populated by CLI SAPI and then client discovering does not work.
Related
I have a docker compose and Dockerfile, when building the project builds and the containers run but gives the site gives the error:
The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode
docker-compose.yml:
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: password
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
Dockerfile:
FROM php:8.1-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
mysql-client \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
nano \
curl \
libzip-dev
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install gd
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
COPY . /var/www/
COPY --chown=www:www . /var/www
USER www
EXPOSE 9000
CMD ["php-fpm"]
"docker-compose exec app chown -R www-data:www-data /var/www"
solved my problem
I was developing an app locally using Laravel. For testing I was using Pest and tests were running fast, really fast. That was until I decided to Dockerize my app, now tests are running pretty slow.
What it used to run in 3 seconds now it's running in over a minute.
Here's my Dockerfile:
FROM php:8.1.12-fpm
ARG uid=1000
ARG user=macgiver
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Install and enable xDebug
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install php modules required by laravel.
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Create system user to run Composer and Artisan commands.
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Install composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Set working directory
WORKDIR /var/www
USER $user
and this is my docker-compose:
version: "3.9"
services:
app:
build:
context: ./
dockerfile: Dockerfile
image: dmc
container_name: dmc-app
restart: unless-stopped
working_dir: /var/www/
depends_on:
- db
- nginx
volumes:
- ./:/var/www/
- ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
expose:
- "9003"
networks:
- dmc-net
nginx:
image: nginx:1.23.2-alpine
container_name: dmc-nginx
restart: unless-stopped
ports:
- "8000:80"
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d
networks:
- dmc-net
db:
image: mysql:8.0.31
container_name: dmc-db
restart: unless-stopped
# using 3307 on the host machine to avoid collisions in case there's a local MySQL instance installed already.
ports:
- "3307:3306"
# use the variables declared in .env file
environment:
MYSQL_HOST: ${DB_HOST}
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: abcd1234
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./docker-compose/mysql:/docker-entrypoint-initdb.d
- mysql-data:/var/lib/mysql
networks:
- dmc-net
networks:
dmc-net:
driver: bridge
volumes:
mysql-data:
Any ideas?
I have the following DockerFile and docker-compose.yml for an Laravel application. I have just added Redis today and this appeared in my terminal in the end of docker-compose up when I tried to connect and use Redis from PHP.
zinc_app | [23-Dec-2019 11:31:27] ALERT: oops, unknown child (32) exited on signal 2 (SIGINT). Please open a bug report (https://bugs.php.net).
zinc_app | [23-Dec-2019 11:31:27] ALERT: oops, unknown child (31) exited on signal 2 (SIGINT). Please open a bug report (https://bugs.php.net).
zinc_app | [23-Dec-2019 11:32:09] ALERT: oops, unknown child (20) exited on signal 9 (SIGKILL). Please open a bug report (https://bugs.php.net).
I am pretty sure the error came from the PHP Redis extension, because it didn't have the problem before. Have anyone encountered this problem before? Have I configured anything wrong?
I have tested this on another computer, but it didn't exhibit the same behavior. I have tried docker system prune -a and build and up again, but my computer still has the same problem.
As for the code I have run. I have run this in artisan tinker.
$redis = new Redis();
$redis->connect('zinc_redis', 6379);
$redis->get('1'); // The Oops message originated from this line.
Docker Compose:
version: '3.6'
services:
#PHP Service
zinc_app:
build:
context: .
dockerfile: Dockerfile
image: zinc/php
container_name: zinc_app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: zinc_app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- /tmp:/tmp #For CS Fixer
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
zinc_webserver:
image: nginx:alpine
container_name: zinc_webserver
restart: unless-stopped
tty: true
ports:
- "8080:80"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#Postgres Service
zinc_db:
image: postgres:12-alpine
container_name: zinc_db
restart: unless-stopped
tty: true
ports:
- "5432:5432"
environment:
POSTGRES_DB: zinc
POSTGRES_PASSWORD: admin
SERVICE_TAGS: dev
SERVICE_NAME: postgres
volumes:
- dbdata:/var/lib/postgresql
- ./postgres/init:/docker-entrypoint-initdb.d
networks:
- app-network
zinc_redis:
image: redis:5.0-alpine
container_name: zinc_redis
restart: unless-stopped
tty: true
ports:
- "6379:6379"
volumes:
- ./redis/redis.conf:/usr/local/etc/redis/redis.conf
- redisdata:/data
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
redisdata:
driver: local
FROM php:7.4-fpm
# Switch to root user
USER root
# Set working directory
WORKDIR /var/www
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
RUN chown www:www /var/www
# Copy composer
COPY --chown=www:www composer.json composer.lock /var/www/
# Install dependencies
RUN apt-get update && apt-get install --no-install-recommends -y \
build-essential \
libpq-dev \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
libzip-dev \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pgsql pdo_pgsql zip exif pcntl
# Enable igbinary & PHP Redis ext using igbinary
RUN pecl install -o -f igbinary && y | pecl install -o -f redis && docker-php-ext-enable redis igbinary
RUN rm -rf /tmp/pear
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
COPY --chown=www:www . /var/www/
# Change current user to www
USER www
# Install packages
RUN composer global require hirak/prestissimo && composer install
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
I am setting up a development environment with the docker. In it I need
NGINX (webservice)
PHP 7.2 (app)
MARIADB 10.3 (database)
In the app container I must install composer, I will work using laravel.
Using RUN composer install andCOPY .env.example .env in dockerfile to install vendor and configure.env, I did not get any error messages but no files were created either.
docker-compose.yml
version: '3'
services:
app:
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
build:
context: .
dockerfile: Dockerfile
image: php:7.2
container_name: app
restart: unless-stopped
tty: true
working_dir: /var/www
networks:
- app-network
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
networks:
- app-network
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
db:
image: mariadb:10.3
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: db
MYSQL_ROOT_PASSWORD: pass
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- app-network
volumes:
- dbdata:/var/lib/mysql
networks:
app-network:
driver: bridge
volumes:
dbdata:
driver: local
dockerfile
FROM php:7.2-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
mariadb-client-10.3 \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Run composer install
RUN composer install
# Create the .env from the .env.example
COPY .env.example .env
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
I have created a Setup to deploy a Laravel Application with the help of NGINX Web Server and MYSQL Database at Github.
It should be pretty easy to set up. If you encounter any issues, please feel free to raise an issue at Github, or ask me here.
When creating a LEMP stack using PHP-FPM I can't seem to load the PDO dirver it keeps defaulting to the sqlite driver.
Docker compose:
version: "3.5"
services:
redis:
image: redis:alpine
container_name: errors-redis
mysql:
image: mysql:8.0
container_name: errors-mysql
working_dir: /application
volumes:
- .:/application
environment:
- MYSQL_ROOT_PASSWORD=test
- MYSQL_DATABASE=errors
- MYSQL_USER=test
- MYSQL_PASSWORD=test
ports:
- "9011:3306"
webserver:
image: nginx:latest
container_name: errors-nginx
working_dir: /application
volumes:
- .:/application
- ./dev/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "9010:80"
php-fpm:
image: php:fpm
container_name: errors-php-fpm
working_dir: /application
volumes:
- .:/application
- ./dev/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
Docker file:
FROM phpdockerio/php72-fpm:latest
WORKDIR "/application"
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install php-memcached php7.2-mysql php-redis php-xdebug \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
PHP ini
upload_max_filesize = 100M
post_max_size = 108M
Now when I check phpinfo()
PDO support enabled
PDO drivers sqlite
I've not installed sqlite at any point so I'm not sure how it's gotten it. How do I change it to use MySQL instead of sqlite?
You need to add the PDO bits to your install as well...
apt-get -y --no-install-recommends install php-memcached php-redis php-xdebug mysqli pdo pdo_mysql \
Specifically the last 3. You can probably miss out the php7.2-mysql as this should be covered with the mysqli option.