Is anyone using VSCode for developing in Magento? I have been using it for years for other languages, thus I found convenient to adopt it for Magento too.
However, I am not able to make it running. I followed all the steps recommended, but it did not worked:
yum install php-devel
yum install php-pear
yum install gcc gcc-c++ autoconf automake
pecl install xdebug-3.1.5
Add it to /etc/php.ini:
zend_extension="/usr/lib64/php/modules/xdebug.so"
xdebug.remote_enable = 1
chmod +x /usr/lib64/php/modules/xdebug.so
service httpd restart
I've installed Xdebug extension and launched the .json file for attaching the session:
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
}
When I open Magento, the breakpoint is never met and stopped. Why?
I solved the issue by adding the following to setting to the php.ini.
xdebug.mode=debug
xdebug.start_with_request=yes
Related
I am looking for some guidance on setting up Xdebug with Docker and VSCode on Windows 10. My docker settings are as follows, but I always get 'EADDRINUSE: address already in use :::9000' and never get any output from Xdebug from inside VSCode!
The project is Laravel based.
.vscode\launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug on Docker App",
"type": "php",
"request": "launch",
"port": 9000,
// "pathMappings": {
// "/var/www/html": "${workspaceFolder}"
"pathMappings": {
"/var/www/html": "C:\\development\\inventory-service\\"
},
}
]
}
dockerfile
# Create and build composer dependencies
FROM composer:2.0 AS vendor
COPY database/ database/
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN composer install \
--ignore-platform-reqs \
--no-interaction \
--no-plugins \
--no-scripts \
--prefer-dist
# Create and build application
FROM php:8.0-apache
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf \
&& sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN apt-get update && apt-get install -y \
libpng-dev \
zlib1g-dev \
libxml2-dev \
libzip-dev \
libonig-dev \
zip \
curl \
unzip \
&& docker-php-ext-configure gd \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install zip \
&& docker-php-source delete
# Install Xdebug
# RUN pecl install -f xdebug
# RUN echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini;
RUN pecl install xdebug && docker-php-ext-enable xdebug \
&& echo "\n\
xdebug.remote_host = 192.168.150.1 \n\
xdebug.default_enable = 1 \n\
xdebug.remote_autostart = 1 \n\
xdebug.remote_connect_back = 0 \n\
xdebug.remote_enable = 1 \n\
xdebug.remote_handler = "dbgp" \n\
xdebug.remote_port = 9000 \n\
xdebug.remote_log = /var/www/html/xdebug.log \n\
" >> /usr/local/etc/php/conf.d/docker-php-xdebug.ini
# Copy the scheduler script into the image
COPY scheduler.sh /usr/local/bin/scheduler
COPY service.sh /usr/local/bin/service
# Set permissions on image folders
RUN a2enmod rewrite headers \
&& chmod u+x /usr/local/bin/scheduler \
&& chmod u+x /usr/local/bin/service
# Copy the application into the image
COPY --from=vendor /usr/bin/composer /usr/bin/composer
COPY --from=vendor /app/vendor/ /var/www/html/vendor/
COPY . /var/www/html
# Set permissions on image folders
RUN chown -R www-data:www-data /var/www/html
I've gone through a number of posts online to set this up but I always seem to have the same issue of port usage and/or no debug data (despite VSCode running the debugger).
Any help much appreciated...
OK, so there was 1 file I needed to update (dockerfile) and I needed to create a new file (.vscode\launch.json).
Add the following to dockerfile (port number used by Xdebug is 9003)
# Install Xdebug
RUN pecl install xdebug && docker-php-ext-enable xdebug \
&& echo "\n\
xdebug.client_host=host.docker.internal \n\
xdebug.mode=debug \n\
xdebug.start_with_request=yes \n\
xdebug.discover_client_host=0 \n\
xdebug.remote_handler = "dbgp" \n\
xdebug.client_port=9003 \n\
xdebug.log = /var/www/html/xdebug.log \n\
" >> /usr/local/etc/php/conf.d/docker-php-xdebug.ini
And then create or update your .vscode\launch.json (pathMappings: path on Docker then local path to your code folder)
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug on Docker App",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html": "C:\\development\\inventory-service\\"
},
}
]
}
...then rebuild your docker instance.
Debugging in browser:
From VSCode, select file for debugging, add break points where needed, then hit F5 to start debugging session. Then go to the page you are debugging, locally, from your web browser.
Debugging artisan commands via console:
From VSCode, select file for debugging, add break points where needed, then hit F5 to start debugging session. Then run the console command from the command line directly (in the normal manner) on the docker instance (choose the CLI from docker desktop for the relevant container/service).
I believe there is a way to test console from your VSCode terminal, but it never worked for me!
I'm sorry in advance, I did my research and I noticed the same question multiple times on this page, I've been trying to figure it out by myself but I can't quite comprehend how to get this working with my specific configuration
This is a project from work which has this Dockerfile:
FROM php:7.3-apache
RUN apt-get update && apt-get install -y acl unzip \
&& rm -r /var/lib/apt/lists/*
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
RUN install-php-extensions gd intl pdo_mysql soap xdebug zip
RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_port=10000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_host=172.17.0.1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
WORKDIR /var/www/app
COPY --from=composer:1.10 /usr/bin/composer /usr/bin/composer
COPY docker/000-default.conf /etc/apache2/sites-enabled/000-default.conf
COPY docker/app.conf /etc/apache2/conf-enabled/z-app.conf
COPY docker/app.ini $PHP_INI_DIR/conf.d/app.ini
RUN ln -s $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini
RUN a2enmod rewrite
It's supposed to already have Xdebug working, no?
I installed the php debug extension on VSCode and this is my launch.json config:
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 10000,
"pathMappings": {
"/var/www/app": "${workspaceFolder}"
},
}
I start the debugging session but the project doesn't stop on breakpoints, so I'm just lost
I hope you guys can help me out, thanks!
I'm trying to install xdebug on Ubuntu:
sudo apt-get install php-xdebug
and getting following error:
Need to get 806 kB of archives. After this operation, 4.423 kB of
additional disk space will be used. Err:1
http://ppa.launchpad.net/ondrej/php/ubuntu artful/main amd64
php-xdebug amd64 2.5.5-3+ubuntu17.10.1+deb.sury.org+1 404 Not Found
E: Failed to fetch
http://ppa.launchpad.net/ondrej/php/ubuntu/pool/main/x/xdebug/php-xdebug_2.5.5-3+ubuntu17.10.1+deb.sury.org+1_amd64.deb
404 Not Found E: Unable to fetch some archives, maybe run apt-get
update or try with --fix-missing?
How can I solve this problem ?
First, you need to update local packages using the following command:
sudo apt update
# OR
sudo apt-get update
Now you can install xdebug with the following command:
sudo apt install php-xdebug
And configure it as:
sudo nano /etc/php/7.0/mods-available/xdebug.ini
Add the following code into it:
zend_extension=/usr/lib/php/20151012/xdebug.so
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_log = /tmp/xdebug_remote.log
xdebug.remote_mode = req
xdebug.remote_port = 9005 #if you want to change the port you can change
Note: Directory 20151012 is most likely to be different for you. cd into /usr/lib/php and check which directory in this format has the xdebug.so file inside it and use that path.
And then restart the services:
sudo systemctl restart php7.0-fpm
sudo systemctl restart nginx # If you are using nginx server
sudo systemctl restart apache2 # If you are using apache server
I use the following method and it works
retrieve content from php info
$ php -i> info.txt
copy all the text in the info.txt file then enter the xdebug installation wizard
and follow the ranks available there.
will look like this
Download xdebug-2.7.2.tgz
Install the pre-requisites for compiling PHP extensions.
On your Ubuntu system, install them with: apt-get install php-dev autoconf automake
Unpack the downloaded file with tar -xvzf xdebug-2.7.2.tgz
Run: cd xdebug-2.7.2
Run: phpize (See the FAQ if you don't have phpize).
As part of its output it should show:
Configuring for:
...
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
If it does not, you are using the wrong phpize. Please follow this FAQ entry and skip the next step.
Run: ./configure
Run: make
Run: cp modules/xdebug.so /usr/lib/php/20170718
Update /etc/php/7.2/cli/php.ini and change the line
zend_extension = /usr/lib/php/20170718/xdebug.so
How to install Xdebug on Ubuntu
If none of the above solutions worked for you, then your last resort might be to use pecl
If you don't have pecl installed already:
sudo apt -y install php7.3-dev php-pear // replace php7.3 with your version
Run pecl to install xdebug:
sudo pecl install xdebug
At the end of the installation, you may see this output:
Build process completed successfully
Installing '/usr/lib/php/20180731/xdebug.so'
install ok: channel://pecl.php.net/xdebug-3.0.2
configuration option "php_ini" is not set to php.ini location
You should add "zend_extension=/usr/lib/php/20180731/xdebug.so" to php.ini
Open your php.ini file, add the zend_exntension line at the very bottom (skip if pecl was able to place it already):
sudo vim /etc/php/7.3/apache2/php.ini // again replace 7.3 with your version
Finally, restart your webserver, or PHP-FPM, depending on what you are using.
I think that you should update the local package index with the latest changes made in the repositories first by typing the following command :
sudo apt update
Or
sudo apt-get update
The APT package index is essentially a database of available packages from the repositories defined in the /etc/apt/sources.list file and in the /etc/apt/sources.list.d directory.
Credits
For anyone finding this answer, please bear in mind that there are significant changes between xdebug 2 and xdebug 3. There is upgrade guide provided by XDebug here: http://xdebug.org/docs/upgrade_guide
Update for php 7.4.8: In the Xdebug configuration file
/etc/php/7.4/mods-available/xdebug.ini
I had to add the line:
xdebug.force_display_errors = 1
As Xdebug wouldn't work instead.
please, disable ppa/php and run sudo apt install php-xdebug
System Configuration
Ubuntu 14.04
Xampp v 5.6.3
installed php5-dev after xampp on
sudo /opt/lampp/lampp start
now want to install Xdebug wihin xampp and I tried available 3 method but nothing is working out , please see the whole process.
1)Ubuntu software package
sudo apt-get install php5-xdebug
command exceuted successfully but no such file in .usr/lib/php5/...
uninstalled
2)Tailored Installation Instructions
downloaded xdebug.tar.gz after checking with wizard
ice#cold:~/Downloads/xdebug-2.2.6$ /usr/bin/phpize5
/usr/bin/phpize5 Cannot find config.m4.
Make sure that you run '/usr/bin/phpize5' in the top level source directory of the module
also tried with phpize, /opt/lampp/bin/phpize but not working out
3)PECL Installation
before that let me check with pecl help version
PEAR Version: 1.9.4
PHP Version: 5.5.9-1ubuntu4.5
Zend Engine Version: 2.5.0
Running on: Linux ice-cold 3.13.0-39-generic #66-Ubuntu SMP Tue Oct 28 13:30:27 UTC 2014 x86_64
pecl install xdebug
...
...
Build process completed successfully
Installing '/usr/lib/php5/20121212/xdebug.so'
install ok: channel://pecl.php.net/xdebug-2.2.6
configuration option "php_ini" is not set to php.ini location
You should add "zend_extension=xdebug.so" to php.ini
executed completely
I can see the file
644 /usr/lib/php5/20121212/xdebug.so
added below line in /opt/lampp/etc/php.ini
[xdebug]
zend_extension="/usr/lib/php5/20121212/xdebug.so"
restart lampp
but still xdebug icon is missing
Please tell me what is wrong
xdebug is located under xampp folder in
/opt/lampp/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
on ubuntu 14.04 just search for it in /opt/lampp and copy the full path to it and then open php.ini and replace
;zend_extension=opcache.so
with
zend_extension="/path/xdebug.so"
in my case
zend_extension="/opt/lampp/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so"
edited in /opt/lmapp/etc/php.ini assigned the location of xdebug.so to zend_extension
[xdebug]
zend_extension="/usr/lib/php5/20121212/xdebug.so"
Replace with
[xdebug]
zend_extension="xdebug.so"
and restart lampp and Xdebug is installed.
AS I was not doing this before because Xdebug Docs itself warn not to do this
Note: You should ignore any prompts to add "extension=xdebug.so" to php.ini — this will cause problems.
[xdebug]
zend_extension="xdebug.so"
Replace with
[xdebug]
zend_extension="20160603/xdebug.so"
I have installed it by:
sudo apt install php-pear
sudo pecl channel-update pecl.php.net
sudo apt install php7.2-dev
sudo pecl install xdebug
Read the last part of the output, follow, and add the corresponding zend_extension=... line to your php.ini file. Restart php-fpm (or Apache if you have it as an Apache module), and you'll have XDebug!
In my case:
open /opt/lampp/etc/php.ini
configuration option "php_ini" is not set to php.ini location
You should add "zend_extension=/usr/lib/php/20170718/xdebug.so" to php.ini
sudo /opt/lampp/lampp restart
Just type the command sudo pecl install xdebug
OR
Install it with source code
git clone -b xdebug_2_4 --single-branch https://github.com/xdebug/xdebug/
OR
wget https://github.com/xdebug/xdebug/archive/XDEBUG_2_4_0.zip xdebug.zip && unzip xdebug.zip
cd xdebug
sudo chmod +x ./rebuild.sh && ./rebuild.sh
./configure <CONFIG>
make && sudo make install
I want to start profiling some PHP code and I have that using xdebug and webgrind seems to be the way to go.
I downloaded xdebug and got these instructions..
Unpack the downloaded file with tar -xvzf xdebug-2.2.3.tgz
Run: cd xdebug-2.2.3
Now, this may be a stupid question, but where exactly should I upload xdebug to so it can be unpacked? Does it matter? I assume it shouldn't be web-accessible?
It is assumed you have Apache2 + PHP5 working already.
sudo apt-get install php5-dev php-pear
Now install xdebug thru PECL.
sudo pecl install xdebug
Now we need to find where xdebug.so went (the compiled module)
martin#martin-dev:/$ find / -name 'xdebug.so' 2> /dev/null
/usr/lib/php5/20060613/xdebug.so
Then edit php.ini:
sudo gedit /etc/php/apache2/php.ini
Add the following line:
zend_extension="/usr/lib/php5/20060613/xdebug.so"
Then restart apache for changes to take effect
sudo /etc/init.d/apache2 restart
and see
http://xdebug.org/docs/install
http://www.anil2u.info/2013/03/install-xdebug-in-ubuntu/
http://2bits.com/articles/setting-up-xdebug-dbgp-for-php-on-debian-ubuntu.html
http://www.michaelbender.net/?p=64