Installing xdebug php profiler on unix - php

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

Related

How to install Xdebug on Ubuntu?

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

Wrong version in pecl install xdebug

I am trying to install xdebug with pecl install xdebug on PHP 5.5.27
According to PECL website https://pecl.php.net/package/xdebug latest stable version of xdebug is 2.3.3
However command above is trying to install xdebug 2.3.2
What is wrong with this?
When using pecl program to install a package, you can install a specific version, or upgrade to a specific version:
pecl install xdebug-2.3.3
Even if it's not the case here if one needs to downgrade a package, the force (-f) option may be required to make it work:
pecl install -f xdebug-2.3.3
You need to download it manually:
wget http://xdebug.org/files/xdebug-2.3.3.tgz
tar -xvzf xdebug-2.3.3.tgz
cd xdebug-2.3.3
phpize
./configure
make
If you are running a tool like homestead you won't need further steps and do not forget to take backup before steps below.
cp modules/xdebug.so /usr/lib/php5/20131226
Update /etc/php5/fpm/php.ini
zend_extension = /usr/lib/php5/20131226/xdebug.so
Restart the webserver

Xdebug with XAMPP in Ubuntu 14.04

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

Gmagick extension for php install -- how and where?

Downloaded php-pear and tried installing gmagick extension by following the steps given in link "http://www.gerd-riesselmann.net/development/how-install-imagick-and-gmagick-ubuntu"
The pecl gave an error --
gmagick-1.0.9b1$ pecl install gmagick
Failed to download pecl/gmagick within preferred state "stable", latest release is version 1.0.9b1, stability "beta", use "channel://pecl.php.net/gmagick-1.0.9b1" to install
install failed
Tried adding the channel (no result)--
gmagick-1.0.9b1$ pecl channel-add http://pecl.php.net/package/gmagick/1.0.9b1
Error: No version number found in tag
channel-add: invalid channel.xml file
Found the link "http://pecl.php.net/package/gmagick" to download the php extension untar'd it to find the following files --
gmagick-1.0.9b1$ ls
config.m4 gmagickdraw_methods.c gmagick_methods.c LICENSE php_gmagick_helpers.h README
gmagick.c gmagick_helpers.c gmagickpixel_methods.c php_gmagick.h php_gmagick_macros.h
Tried . / config.m4 only to find more errors
gmagick-1.0.9b1$ . / config.m4
./config.m4: line 1: syntax error near unexpected token `gmagick,'
./config.m4: line 1: `PHP_ARG_WITH(gmagick, whether to enable the gmagick extension,'
Been at this since a day with no result.Read that gmagick is a swiss knife of image processing,sad that there isnt much documentation done on it or at least a proper how to install link anywhere.
Badly need help.
Thanks in advance.
The following works for me on Kubuntu 11.04. First install the development files:
sudo apt-get install libgraphicsmagick1-dev
Then install GMagick for PHP:
sudo pecl install gmagick-1.1.1RC1
Finally load the extension in PHP:
sudo sh -c 'echo "extension=gmagick.so" >> /etc/php5/apache2/php.ini'
sudo service apache2 restart
Found the answer >>
shell> cd gmagick-1.0.9b1
shell> phpize
shell> ./configure
shell> make
shell> make install
Then,
Create file /etc/php/conf.d/imagick.ini and add a line "extension=imagick.so"
Reload Apache: sudo /etc/init.d/apache2 reload
For some reason,pecl never worked.but a combination of the links "http://www.gerd-riesselmann.net/development/how-install-imagick-and-gmagick-ubuntu" and the tutorial " helped me.
apt-get install php-pear
pecl install gmagick-1.1.7RC3
apt-get install libevent-dev
apt-get install libgraphicsmagick1-dev
nano /etc/php5/mods-available/gmagick.ini // Add "extension=gmagick.so"
cd /etc/php5/cli/conf.d/
ln -s ../../mods-available/gmagick.ini 20-gmagick.ini
php5enmod gmagick
service nginx restart
service php5-fpm restart
I never liked "PECL", but seems is the only way to get that gmagick added to my php#7.3 being Mac zealoth.
After running pecl install gmagick the output in the console will be similar to:
Failed to download pecl/gmagick within preferred state "stable", latest release is version 2.0.5RC1, stability "beta", use "channel://pecl.php.net/gmagick-2.0.5RC1" to install
The content of the page and the page URL points to "Release 2.0.5RC1", so the command becomes:
pecl install gmagick-2.0.5RC1
That "PECL" thing installs extensions to a pecific directory, which PHP scans
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
extension_dir = "/usr/local/lib/php/pecl/20180731"

Install PECL SSH2 extension for PHP

I am trying to install this
http://fr2.php.net/manual/en/book.ssh2.php
on a Centos 5 (a fork of RHEL 5).
I installed libssh2 (yum install libssh2) which is located in /usr/lib, and when I install SSH2 extension (via pecl install -f ssh2) I get this message
checking for ssh2 files in default path... not found
configure: error: The required libssh2 library was not found. You can obtain that package from http://sourceforge.net/projects/libssh2/
ERROR: `/tmp/pear/download/ssh2-0.11.0/configure --with-ssh2=/usr' failed
If I set /usr/lib, I get the same message
ERROR: `/tmp/pear/download/ssh2-0.11.0/configure --with-ssh2=/usr/lib' failed
Where is the problem?
Installing libssh2 via tar.gz from http://sourceforge.net/projects/libssh2/ help a lot (--with-ssh2=/usr/local/include/).
But :
yum install libssh2-devel
...is a better idea.
$ sudo pecl channel-update pecl.php.net
$ sudo apt-get install libssh2-1-dev
$ sudo pecl install -a ssh2-0.12
$ echo 'extension=ssh2.so' | sudo tee /etc/php5/mods-available/ssh2.ini > /dev/null
$ sudo php5enmod ssh2
yum install libssh2-devel didn't work for me:
No package libssh2-devel available.
So I downloaded rpm package from rpmfind and installed with rpm -ivh
After that just added extension=ssh2.so to /etc/php.d/ssh2.ini
This is updated answer from #klay + modification from #avn from comment under working solution for PHP 7.x.
$ sudo pecl channel-update pecl.php.net
$ sudo apt-get install libssh2-1-dev
$ sudo pecl install -a ssh2-1.0
$ echo 'extension=ssh2.so' | sudo tee /etc/php/7.2/mods-available/ssh2.ini > /dev/null
$ sudo phpenmod ssh2
Regarding line:
echo 'extension=ssh2.so' | sudo tee /etc/php/7.2/mods-available/ssh2.ini > /dev/null
Make sure that path /etc/php/7.2/mods-available is valid and there is a match with your php version.
I'm running on Centos, none of these answer were the entire solution for me. I followed these instructions:
$ sudo yum install -y gcc php-devel php-pear libssh2 libssh2-devel
But php-devel would not install, complaining about conflicts. I searched yum to find what php devel packages I had available
$> yum search php|grep devel
...
php55u-devel.x86_64 : Files needed for building PHP extensions
php56u-devel.x86_64 : Files needed for building PHP extensions
php70u-devel.x86_64 : Files needed for building PHP extensions
...
So I ran
$> sudo yum install -y php56u-devel
And it installed cleanly. Then, continuing with the instructions, I ran
$ pecl install -f ssh2
And it compiled. Then I added the extension to php
$ touch /etc/php.d/ssh2.ini
$ echo extension=ssh2.so > /etc/php.d/ssh2.ini
And on my system, instead of
$ /etc/init.d/httpd restart
I had to do
$ sudo /bin/systemctl restart php-fpm.service
So that was all the steps to install. And finally to confirm:
$> php -m|grep ssh2
ssh2
I had this problem:
I'm on a Pair.com "Advanced" hosted account, so I'm a little limited on what I'm allowed to do. I don't think I can yum nor aptitude nor any of the other pre-compiled packages.
I've downloaded and compiled libssh2. During the pecl process, it asks where the library is located. It's in "~/usr/local/lib" and I've tried several variations, including fully qualified. But I kept getting the same error.
The error message doesn't spell out precisely which file it's looking for. libssh2.so is in that directory. I know the output is supposed to be ssh2.so. I wondered if there is supposed to be an ss2.something, or libssh.nothing?
I fixed it thus. In my case, after compiling libssh2 I downloaded the PEAR tarball. The trick was:
./configure --with-ssh2=<libssh2 location> --prefix=<libssh2 location>
Another trick is that, since Pair.com is running FreeBSD, I have to do a "cd ." after the ./configure command. Otherwise, make produces a "Permission denied" error. Apparently, this is necessary on all *nix BSD flavors.
The error:
checking for ssh2 files in default path... not found
configure: error: The required libssh2 library was not found.
...can be seen in the source code.
The logic in the code reveals that it will throw this error if it cannot find /include/libssh2.h in either /usr/local, /usr or in the path supplied by the optional --with-ssh2=[DIR] directive. In other words, without customising the directive, it needs to find one of the following:
/usr/local/include/libssh2.h
/usr/include/libssh2.h
If it passes this check, it then assumes it can find the libssh2 lib at /usr/local/lib or /usr/lib.
Hopefully the info above is enough to help someone debug their issue. My own case is fairly specific and unusual (macOS with Homebrew in a custom install path), but in case it helps anyone else, here's my horrifically hacky workaround. Works perfectly lol
In a nutshell I'm creating two temporary symlinks so that pecl can find ssh2 where it expects.
# First check that neither /usr/local/include nor /usr/local/lib exists
sudo ln -s /usr/local/CustomInstallPath/Homebrew/Cellar/libssh2/1.9.0_1/include /usr/local/include
sudo ln -s /usr/local/CustomInstallPath/Homebrew/Cellar/libssh2/1.9.0_1/lib /usr/local/lib
pecl install -a ssh2-1.3.1
sudo rm -rf /usr/local/include
sudo rm -rf /usr/local/lib

Categories