I'm trying to use xdebug 3 with docker on ubuntu 20.04, but I'm not getting success,
xdebug does not enter the interruption point, I already searched for everything and no answer solved my problem, it would be something about the docker host, because the same configuration is the right one in windows, I don't know what else I can try to solve the problem,
I would like a help to understand what I'm doing wrong, below is my configuration.
My docker-compose file
version: '3.7'
networks:
supervisao:
services:
nginx:
image: nginx:stable-alpine
container_name: supervisao-web
ports:
- "80:80"
volumes:
- .:/var/www/html/
- ./.docker/web/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- supervisao
mysql:
image: mysql:latest
container_name: supervisao-db
command: --default-authentication-plugin=mysql_native_password
restart: always
tty: true
ports:
- "3306:3306"
volumes:
- ./.docker/mysql/:/var/lib/mysql
environment:
MYSQL_DATABASE: supervisao
MYSQL_USER: user
MYSQL_PASSWORD: pass
MYSQL_ROOT_PASSWORD: pass
SERVICES_TAGS: dev
SERVICES_NAME: mysql
networks:
- supervisao
php:
build:
context: .
dockerfile: Dockerfile
container_name: supervisao-php
volumes:
- .:/var/www/html/
- ./.docker/php/docker-xdebug.ini:/usr/local/etc/php/conf.d/php-docker.ini
ports:
- "9000:9000"
networks:
- supervisao
redis:
image: redis:latest
volumes:
- ./.docker/redis:/data
ports:
- 6379:6379
networks:
- supervisao
my xdebug.ini
# File: docker-xdebug.ini
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so
xdebug.discover_client_host=1
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = host.docker.internal
xdebug.client_port = 9003
xdebug.log = /var/www/html/xdebug.log
I appreciate if someone can collaborate, thank you
Make sure you have xdebug 3 loaded in PHP.
Create the phpinfo.php file
<?php
phpinfo();
Surf to it to check that xdebug is loaded by PHP and is version 3.
If the xdebug is version 2.x then you can install v3 with pecl instead.
If you have shell access to your docker box you can try the pecl command directly and see in phpinfo if you got xdebug v3.
In your DockerFile:
# PECL
RUN mkdir -p /tmp/pear/cache
RUN pecl channel-update pecl.php.net
RUN apt install -y php-pear
COPY xdebug.ini "/etc/php/${PHP_VERSION}/mods-available/xdebug.ini"
# The xdebug distributed with Ubuntu 20.04 LTS is v2.9.2, we want v3.0.x
RUN pecl install xdebug
# Enable xdebug by default
RUN phpenmod xdebug
In your xdebug.ini
zend_extension=xdebug.so
xdebug.default_enable = On
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.discover_client_host=yes
xdebug.max_nesting_level = -1
xdebug.log = "/var/www/log/xdebug.log"
xdebug.output_dir = "/var/www/log/profiler"
Now you could rebuild the docker boxes
docker stop
docker build --no-cache
docker up
Check in phpinfo if you got the settings enabled.
If you have shell access to your docker box you can look at the log file.
tail -n 100 /var/www/log/xdebug.log
If you run PHP Storm there is an excellent validator in PHP Storm >> File >> Settings >> Languages & Frameworks >> PHP >> Debug
Click the link "Validate". Set local web server path to your public folder. Validation script to your webb address. Works good on shared folders and not so good on synced folders.
If you run Ubuntu as host then look at the firewall settings.
"9000/tcp ALLOW IN Anywhere" and the same for port 9003. Or try temprarily to disable the firewall.
I also added port 9003:9003 to the DockerFile. But have not tested if that makes any difference.
Hope any of this was of help to you.
In my case, disabling firewall did the trick - sudo ufw disable
Related
How can I recreate this?
Create install from Laravel 8 docs and Laravel Sail docs.
I use the sail up command, which works great. The command builds docker containers, connects them, and makes development as easy as we can imagine, especially for VSCode, and this works fine, but it's slow in development with WSL2. I mean commands like `sail npm run dev.' Any ideas on how to speed this up?
FYI: The same project that runs on the same machine is at least 10x faster. For more information, I ran tests on i9-10900X, 32 GB RAM on Docker Desktop for Windows 10.
docker-compose.yml
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
- redis
mysql:
image: 'mysql:8.0'
ports:
- '${DB_PORT}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
redis:
image: 'redis:alpine'
ports:
- '${REDIS_PORT}:6379'
volumes:
- 'sailredis:/data'
networks:
- sail
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- 1025:1025
- 8025:8025
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
sailredis:
driver: local
You should run docker from WSL2 if possible.
Install docker and WSL2.
Move your project to WSL by opening \\wsl$\ in explorer and navigating to your VM's home, in my case \\wsl$\Ubuntu-20.04\home\thomas
Run docker-compose up -d / sail up from the VM
I was going to explain this but just go here and read for yourself. This is what helped me. VSCode kinda yelled at me when I opened up a project in the default location and gave me this link. https://learn.microsoft.com/en-us/windows/wsl/compare-versions
Performance across OS file systems
We recommend against working across operating systems with your files,
unless you have a specific reason for doing so. For the fastest
performance speed, store your files in the WSL file system if you are
working in a Linux command line (Ubuntu, OpenSUSE, etc). If you're
working in a Windows command line (PowerShell, Command Prompt), store
your files in the Windows file system.
For example, when storing your WSL project files:
Use the Linux file system root directory: \\wsl$\Ubuntu-18.04\home\<user name>\Project
Not the Windows file system root directory: C:\Users\<user name>\Project
All currently running distributions (wsl -l) are accessible via
network connection. To get there run a command [WIN+R] (keyboard
shortcut) or type in File Explorer address bar \\wsl$ to find
respective distribution names and access their root file systems.
You can also use windows commands inside WSL's Linux Terminal. Try
opening a Linux distribution (ie Ubuntu), be sure that you are in the
Linux home directory by entering this command: cd ~. Then open your
Linux file system in File Explorer by entering (don't forget the
period at the end): powershell.exe /c start .
I am currently learning Docker for a project and got a configuration to start on my PHP website that I intend to change. The problem is that even when I set up different versions in Dockerfile I get the same PHP version.
This is the output when I do the docker-compose up command.
It keeps using the PHP version 7.0.33. That's the version that it shows in the browser as well.
This is my docker-compose.yml file:
# tell docker what version of the docker-compose.yml were using
version: '3'
# define the network
networks:
web-network:
# start the services section
services:
# define the name of our service
# corresponds to the "--name" parameter
docker-php-cli:
# define the directory where the build should happened,
# i.e. where the Dockerfile of the service is located
# all paths are relative to the location of docker-compose.yml
build:
context: ./php-apache
# reserve a tty - otherwise the container shuts down immediately
# corresponds to the "-i" flag
tty: true
# mount the app directory of the host to /var/www in the container
# corresponds to the "-v" option
volumes:
- ./app:/var/www
# connect to the network
# corresponds to the "--network" option
networks:
- web-network
docker-nginx:
build:
context: ./nginx
# defines the port mapping
# corresponds to the "-p" flag
ports:
- "8080:80"
tty: true
volumes:
- ./app:/var/www
- ./nginx/conf.d:/etc/nginx/conf.d
networks:
- web-network
docker-php-fpm:
build:
context: ./php-fpm
tty: true
volumes:
- ./app:/var/www
networks:
- web-network
These are the Docker files:
php-apache folder
FROM php:5.6-apache
RUN pecl install xdebug-2.6.0 \
&& docker-php-ext-enable xdebug
php-fpm folder
FROM php:5.6-fpm
RUN pecl install xdebug-2.6.0 \
&& docker-php-ext-enable xdebug
I would like to change it for PHP 5.6 but I couldn't, then I tested with many other versions and it didn't work.
I did try removing the RUN part from each Dockerfile.
Can someone help me with that?
Thank you!
You are using docker-compose up what that command does is, it's start containers from previously build images(to see images on you local use docker image ls)
after changing Dockerfile what you need to do is run docker-compose down
and up again with --build flag. docker-compose up --build
Relevant document https://docs.docker.com/compose/reference/up/
I have a problem with composer install on docker. This is my docker-compose file:
version: '3'
services:
webserver:
image: nginx:latest
ports:
- 80:80
- 433:433
volumes:
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./:/var/www/html/
links:
- php-fmp
- db
networks:
- app-network
php-fmp:
build: docker/php-fmp
volumes:
- ./:/var/www/html/
ports:
- 9000:9000
links:
- db
networks:
- app-network
db:
image: mysql
ports:
- 3306:3306
volumes:
- /var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
- MYSQL_DATABASE=goexpress
- MYSQL_USER=root
- MYSQL_PASSWORD=root
- MYSQL_ROOT_PASSWORD=docker
networks:
- app-network
networks:
app-network:
driver: bridge
I try to execute docker-compose run php-fmp composer install it starts after some minutes it shows memory limit xxxxxxxxx. I have tried also memory_limit=-1.
My laptop memory: 6GB.
In another pc it works perfect.
Before upgrade of memory it has worked. Memory before was 4GB now it is 6GB. The project that I want to run is symfony.
Composer has its own COMPOSER_MEMORY_LIMIT environment variable, but uses php.ini's memory_limit by default when its own variable is not set. https://getcomposer.org/doc/03-cli.md#composer-memory-limit
With Docker Compose you will need to pass COMPOSER_MEMORY_LIMIT as an environment variable to the container where Composer is installed. Your docker-compose.yml file would look like this:
services:
php-fmp: //the name of your container (as per your question)
environment:
- COMPOSER_MEMORY_LIMIT=-1 //-1 means unlimited
This environment variable would be taken into account every time you run Composer with docker-compose:
docker-compose exec php-fmp composer [your composer command]
Instead of php -d memory_limit=-1 composer install try COMPOSER_MEMORY_LIMIT=-1 composer install. Composer starts a new php process, that does not adhere to the setting you provide and it might even override the config (I'm not a 100% sure about that).
If that still does not help open the preferences for Docker (by clicking on the icon in the task bar) under the Advanced tab you can specify how many cores and how much memory docker is allowed to consume. I think the default is 2GB and you might want to change that to e.g. 4GB.
Forgive me if this is an obvious question. I am fairly new to docker and I am having trouble understanding the installation instructions here:
https://hub.docker.com/_/composer/
I want to use PHP Composer in my Limesurvey docker image that was generated with the following docker-compose "yml" file:
limesurvey-md:
image: mariadb
restart: always
ports:
- "32805:3306"
environment:
MYSQL_DATABASE: limesurvey
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: limesurvey
MYSQL_PASSWORD: password
volumes:
- limesurvey-db:/var/lib/mysql
- limesurvey-dblog:/var/log/mysql
- limesurvey-dbetc:/etc/mysql
limesurvey:
image: fjudith/limesurvey
restart: always
ports:
- "32705:80"
volumes:
- limesurvey-upload:/var/www/html/upload
links:
- limesurvey-md:mysql
What do I need to add to my yml file to accomplish this? If it helps, there is a directory called "application" in the Limesurvey image:
/var/www/html/application
And how do I give this composer a command while it is in the container? I am using Windows 10 and the docker container is running the default linux environment. fjudith's Limesurvey container is using the last 2.X branch of Limesurvey (the one right before 3.X) and it is running PHP 7.2
You can create a custom image with a dockerfile build, yo can specify the dockerfile name in the build section, the docker-compose.yml and dockerfile are in the same folder here i attach and example:
docker-compose.yml:
version: '3.1'
services:
limesurvey-md:
image: mariadb
restart: always
ports:
- 32805:3306
environment:
MYSQL_DATABASE: limesurvey
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: limesurvey
MYSQL_PASSWORD: password
volumes:
- limesurvey-db:/var/lib/mysql
- limesurvey-dblog:/var/log/mysql
- limesurvey-dbetc:/etc/mysql
limesurvey:
build:
context: .
dockerfile: dockerfile
restart: always
ports:
- 32705:80
volumes:
- limesurvey-upload:/var/www/html/upload
links:
- limesurvey-md:mysql
volumes:
limesurvey-db:
driver: local
limesurvey-dblog:
driver: local
limesurvey-dbetc:
driver: local
limesurvey-upload:
driver: local
dockerfile:
FROM "fjudith/limesurvey:latest"
LABEL maintainer="ing.brayan.cm#gmail.com"
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
Thanks Brayan! I just (10 minutes ago) figured out another way, you can also do a bash command. Since I was in Windows the two lines I had to do in my command prompt were
docker exec -it <my_container_name> bash
Then it put me into "/var/www/html#" where I did the following command:
$sudo curl -o /tmp/composer-setup.php https://getcomposer.org/installer && curl -o /tmp/composer-setup.sig https://composer.github.io/installer.sig && php -r "if (hash('SHA384', file_get_contents('/tmp/composer-setup.php')) !== trim(file_get_contents('/tmp/composer-setup.sig'))) { unlink('/tmp/composer-setup.php'); echo 'Invalid installer' . PHP_EOL; exit(1); }" && php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer --snapshot && rm -f /tmp/composer-setup.*
I adapted the second line from here: Get composer (php dependency manager) to run on a docker image build
From there it's easy! You can just do
composer
and it guides you through the possible commands. It suggests not using the "root" administrator. I'll have to look into creating another user in the docker image.
I run a WordPress installation in a docker-container with the WordPress image (https://hub.docker.com/_/wordpress/). My problem is that I can't send mails via wp_mail() or with PHP mail().
When I try to call a mail()-function I get an "Internal Server Error".
What can I do? Do I need a external mail server?
My docker-compose.yml:
wordpress:
image: wordpress
container_name: shk_wordpress
links:
- mariadb:mysql
environment:
- WORDPRESS_DB_PASSWORD=admin
ports:
- "8000:80"
volumes:
- ./app:/var/www/html
- ./theme/:/var/www/html/wp-content/themes/shk-theme
mariadb:
image: mariadb
container_name: shk_mariadb
environment:
- MYSQL_ROOT_PASSWORD=admin
- MYSQL_DATABASE=wordpress
volumes:
- ./database:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: shk_phpmyadmin
environment:
- PMA_ARBITRARY=1
- MYSQL_USER=root
- MYSQL_PASSWORD=admin
- MYSQL_ROOT_PASSWORD=admin
ports:
- "9000:80"
links:
- "mariadb:mysql"
It seems that this problem was already been discused at WP docker image repo.
Checkout this answer on
Github
Further down you might find some other solutions to your problem if that one doesn't work.
Step 1 :
In your docker-compose.yml, replace
image: wordpress
by
build: .
Step 2 :
Create a Dockerfile :
FROM wordpress
RUN apt-get update
RUN apt-get install -y ssmtp
RUN echo "sendmail_path = /usr/sbin/ssmtp -t" >> /usr/local/etc/php/conf.d/sendmail.ini
RUN sed -i -e 's/mailhub=mail/mailhub=[IP RELAY SERVER]/' /etc/ssmtp/ssmtp.conf
RUN sed -i -e 's/#rewriteDomain=/rewriteDomain=[IP RELAY SERVER]/' /etc/ssmtp/ssmtp.conf
RUN sed -i -e '/hostname=/d' /etc/ssmtp/ssmtp.conf
Step 3 :
Replace [IP RELAY SERVER]