How to set up Xdebug profiling on PHP 7.2 & PHP-FPM - xdebug

I'm trying to do some PHP profiling using Xdebug on a local environment. I'm running Ubuntu 22.04
I'm using PHP-FPM to run PHP v7.2 through a virtualhost.
php -v outputs
Zend Engine v4.1.7, Copyright (c) Zend Technologies
with Zend OPcache v8.1.7, Copyright (c), by Zend Technologies
with Xdebug v3.1.4, Copyright (c) 2002-2022, by Derick Rethans
On /tmp/xdebug I've run
sudo chown $USER:$USER /tmp/xdebug
At the bottom of my /etc/php/7.2/fpm/php.ini & /etc/php/8.1/apache2/php.ini files I've put:
[xdebug]
zend_extension=xdebug
xdebug.output_dir = /tmp/xdebug
xdebug.remote_port=9001
xdebug.mode=develop,trace,profile
I then run
sudo systemctl restart apache2
The enabled Xdebug features are showing up in phpinfo() in my main /localhost/ directory (using PHP 8.*), but not in the one using PHP 7.2
In my virtualhost .conf file I'm setting the PHP version like (I'm including this because I'm not sure if I need to do anything in this .conf file or not)
<FilesMatch \.php$>
# For Apache version 2.4.10 and above, use SetHandler to run PHP as a fastCGI process server
SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost"
</FilesMatch>
The image below shows phpinfo() picking up my Xdebug settings on PHP 8.*; the directory using PHP 7.2 shows no Xdebug settings enabled.
My question(s) / Issues:
How do I get PHP 7.2 to recognize my Xdebug settings?
How do I get Xdebug to output profile files to /tmp/xdebug? (I plan to use Webgrind)

I'm using PHP-FPM to run PHP v7.2
PHP 7.2 is no longer supported, so please upgrade to at least PHP 7.4, but preferably PHP 8.0 or 8.1.
the directory using PHP 7.2 shows no Xdebug settings enabled.
Make sure that you edit the right php.ini file — the xdebug_info() and phpinfo() sections should show which files it used.
Did you restart your PHP 7.2 PHP-FPM as well? The systemctl restart line for Apache does not automatically do that.
sudo chown $USER:$USER /tmp/xdebug
This is unlikely to be correct, as it needs to be the Apache user (often www-data) that can write to that directory, and not your shell user (which is likely just your log-in username — you can check that with echo $USER).

In case it helps someone, I made two basic mistakes. Thank you #Derick
Mistake #1: My xdebug profiling directory should have been owned by www-data
sudo chown www-data /tmp/xdebug
Mistake #2: I forgot to restart PHP 7.2 PHP-FPM
sudo systemctl restart php7.2-fpm
So, compiled, the steps I took to get Xdebug working with PHP 7.2 PHP-FPM
(Assumes installed LAMP environment)
1 - Install Xdebug (I'm on Ubuntu)
sudo apt-get install php-xdebug
2 - Create the directory to store profiling files & give Apache ownership
sudo mkdir /tmp/xdebug
sudo chown www-data /tmp/xdebug
3 - Enable Xdebug via php.ini (you can use phpinfo() to determine your .ini file location)
sudo nano /etc/php/7.2/fpm/php.ini
Add the following at the bottom of the .ini file (see settings documentation for your needs)
[xdebug]
zend_extension=xdebug
xdebug.output_dir = /tmp/xdebug
xdebug.remote_port=9001
xdebug.mode=develop,trace,profile
4 - Restart PHP-FPM & Apache
sudo systemctl restart php7.2-fpm
sudo systemctl restart apache2

Related

ubuntu 18.4: how to get php 7.2 to work with apache 2?

I purchased a virtual server from vpscity, and chose the Ubuntu 18.4 64bit image.
it came with apache 2 installed.
i am trying to get webpagetest server installed using these instructions: https://docs.webpagetest.org/private-instances/
I did this:
sudo apt-get update &&
sudo apt-get -y dist-upgrade &&
sudo apt-get -y install zip python2.7 nginx php-fpm php-cli php-xml php-apcu php-gd php-zip php-mbstring php-curl php-sqlite3 beanstalkd imagemagick ffmpeg libjpeg-turbo-progs libimage-exiftool-perl python-setuptools python-dev build-essential python-pip python-numpy python-scipy &&
sudo pip install monotonic ujson pillow pyssim
And restarted apache.
However, when I view the website, I see raw php code.
the instructions say:
Using the PHP DSO handler mod_php can dramatically reduce the CPU required when working with large numbers of agents uploading results.
But I dont know what this means or how to implement.
If I look in /etc/apache2/mods-available
I dont see anything with php in it.
There are various people with the same problem, and several different conflicting answers such as:
AddType application/x-httpd-php .php
AddType application/x-httpd-phps .phps
AddType application/x-httpd-php3 .php3 .phtml
AddType application/x-httpd-php .html
LoadModule php7_module modules/mod_php.so
AddModule mod_php7.c
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.0-fpm
service apache2 reload
a2enmod php7.0
service apache2 restart
sudo apt install php libapache2-mod-php
sudo apt install php7.0-mbstring
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
service apache2 restart
gksu gedit /etc/apache2/apache2.conf
sudo apt-get install -y php5-gd php5-curl php-apc libapache2-mod-php5 ffmpeg imagemagick libjpeg-progs libimage-exiftool-perl
sudo a2enmod php5
I never thought getting apache to work with php would be this difficult.
I just noticed that the apt-get I did has nginx in it. Thats not good. Maybe there is a conflict, and I need to re-build the server and do it again without nginx? I dont see nginx running (only apache).
php -version
PHP 7.2.24-0ubuntu0.18.04.15 (cli) (built: Nov 2 2022 09:09:52) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.24-0ubuntu0.18.04.15, Copyright (c) 1999-2018, by Zend Technologies
After much trial and error, this one worked:
apt-get -y install libapache2-mod-php7.2
systemctl restart apache2

How to install and configure xdebug in Linux Mint 18?

I am using the Netbeans IDE, PHP version 7.0 and I have already installed Apache version 2.4.18 and Linux Mint 18.
I have also tried to install the debug files with
sudo apt-get install php7.0-xdebug
How can I proceed further?
Download last stable release of xdebug 2.6.0 :
wget -c "http://xdebug.org/files/xdebug-2.6.0.tgz"
Extract file :
tar -xf xdebug-2.6.0.tgz
cd xdebug-2.6.0/
Build extension
phpize
./configure
make && make install
after finshed compiling i found the binary on path;
/usr/lib/php/20151012/xdebug.so
for find xdebug.so use this comand :
pwd -L xdebug
it print out : /etc/php/7.0/mods-available
then go in directory /etc/php/7.0/mods-available and edit file as superuser nano xdebug.ini file add follows lines:
zend_extension=/usr/lib/php/20151012/xdebug.so
xdebug.show_error_trace = 1
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.profiler_enable=1
sudo systemctl restart apache2.service or sudo /etc/init.d/apache2 restart
http://wiki.netbeans.org/HowToConfigureXDebug

CakePHP 3.0 installation: intl extension missing from system

Using the CakePHP docs, I am trying to install 3.0-beta2 using composer but I got this error:
cakephp/cakephp 3.0.x-dev requires ext-intl * -> the requested PHP extension intl is missing from your system
However, I know for sure that intl is installed (it shows on phpinfo). I'm using PHP 5.4.33/Apache 2.4.10.1
I faced the same problem today. You need to enable the intl PHP extension in your PHP configuration (.ini).
Solution Xampp (Windows)
Open /xampp/php/php.ini
Change ;extension=php_intl.dll to extension=php_intl.dll (remove the semicolon)
Copy all the /xampp/php/ic*.dll files to /xampp/apache/bin
Restart apache in the Xampp control panel
Solution Linux (thanks to Annamalai Somasundaram)
Install the php5-intl extension sudo apt-get install php5-intl
1.1. Alternatively use sudo yum install php5-intl if you are on CentOS or Fedora.
Restart apache sudo service apache2 restart
Solution Mac/OSX (homebrew) (thanks to deizel)
Install the php5-intl extension brew install php56-intl
If you get No available formula for php56-intl follow these instructions.
Restart apache sudo apachectl restart
Eventually you can run composer install to check if it's working. It will give an error if it's not.
I faced the same issue in ubuntu 12.04
Installed: sudo apt-get install php5-intl
Restarted the Apache: sudo service apache2 restart
OS X Homebrew (May 2015):
The intl extension has been removed from the main php5x formulas, so you no longer compile with the --enable-intl flag.
If you can't find the new package:
$ brew install php56-intl
Error: No available formula for php56-intl
Follow these instructions: https://github.com/Homebrew/homebrew-php/issues/1701
$ brew install php56-intl
==> Installing php56-intl from homebrew/homebrew-php
When using MAMP
1 Go to terminal
vim ~/.bash_profile
i
export PATH=/Applications/MAMP/bin/php/php5.6.2/bin:$PATH
Change php5.6.2 to the php version you use with MAMP
Hit ESC,
Type :wq,
hit Enter
source ~/.bash_profile
which php
2 Install Mac Ports
https://www.macports.org/install.php
sudo port install php5-intl OR sudo port install php53-intl
cp /opt/local/lib/php/extensions/no-debug-non-zts-20090626/intl.so /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/
{take a good look at the folder names that u use the right ones}
3 Add extension
Now, add the extension to your php.ini file:
extension=intl.so
Usefull Link:
https://gist.github.com/irazasyed/5987693
The error message clearly states what the problem is. You need the intl extension installed.
Step 1: install PHP intl you comfortable version
$sudo apt-get install php-intl
step 2:
For XAMPP Server intl extension is already installed, you need to enable this extension to uncomment below the line in your php.ini file. Php.ini file is located at c:\xampp\php\php.ini or where you have installed XAMPP.
Before uncomment:
;extension=php_intl.dll ;extension=php_mbstring.dll
After uncommenting:
extension=php_intl.dll extension=php_mbstring.dll
Short answer: activate intl extension in php_cli.ini. Thanks to #ndm for his input.
If you are using latest version Ubuntu 16.04 or later just do
sudo apt-get install php-intl
Then restart your apache
sudo service apache2 restart
In my case I was not actually trying to run cakephp locally, I was just trying to get it to auto update locally using composer (because I am playing with writing plugins that you install with composer). Since I don't actually even run it locally I could simply ignore requirements by adding the --ignore-platform-reqs flag.
php composer.phar update --ignore-platform-reqs
In my case, my running php version is 7.1.x on mac OSX .
I installed intl command using brew install php71-intl.
Placing extension=intl.so inside php.ini was no effect at all. Finally i looked for extension installed directory and there i saw intl.so and placed that path (extension=/usr/local/Cellar/php71-intl/7.1.11_20/intl.so) to my php.ini file and it solved my problem.
In my case (xampp PHP 8.0)
Find ;extension=intl in /xampp/php/php.ini
Remove ; and Restart Apache
MAKE this
In XAMPP, intl extension is included but you have to uncomment extension=php_intl.dll in php.ini and restart the server through the XAMPP Control Panel.
In WAMP, the intl extension is “activated” by default but not working. To make it work you have to go to php folder (by default) C:\wamp\bin\php\php{version}, copy all the files that looks like icu*.dll and paste them into the apache bin directory C:\wamp\bin\apache\apache{version}\bin. Then restart all services and it should be OK.
if you use XAMPP do this
1. turn off XAMPP
2. Modifed the php.ini is located in c/:xampp/php/php.ini
3. intl extension is included but you have to uncomment extension=php_intl.dll in php.ini and restart the server through the XAMPP Control Panel.
For Ubuntu terminal:
Please follow the steps:
Step-1:
cd ~
Step -2: Run the following commands
sudo apt-get install php5-intl
Step -3: You then need to restart Apache
sudo service apache2 restart
For Windows(XAMPP) :
Find the Php.ini file:
/xampp/php/php.ini
Update the php.ini file with remove (;) semi colon like mentioned below:
;extension=php_intl.dll to extension=php_intl.dll
and save the php.ini file.
After that you need to
Restart the xampp using xampp control.
Intl Means :Internationalization extension which enables programmers to perform UCA-conformant collation and number,currency,date,time formatting in PHP scripts.
To enable PHP Intl with PECL can be used.
pecl install intl
On a plain RHEL/CentOS/Fedora, PHP Intl can be install using yum
yum install php-intl
On Ubuntu, PHP Intl can be install using apt-get
apt-get install php5-intl
Restart Apache service for the changes to take effect.
That's it
For those who get Package not found error try sudo apt-get install php7-intl then run composer install in your project directory.
I had the same problem in windows
The error was that I had installed several versions of PHP and the Environment Variables were routing to wrong Path of php see image example
I'm using Mac OS High Sierra and none of these worked for me. But after searching a lot I found one that worked!
This may seem trivial, but in fact about 2 months ago some clever guys made changes in brew repository, so doing just: brew install php71-intl will show you error with message that such recipe doesn’t exists.
Fortunately, there is. There is temporary fix in another brew repo, so all you have to do is:
brew tap kyslik/homebrew-php
brew install kyslik/php/php71-intl
SOURCE: http://blastar.biz/2018/04/14/how-to-enable-php-intl-extension-for-php-7-1-using-xampp-on-macos-high-sierra/
I use Linux Ubuntu 20, you can try this:
Check php installed modules:
php -m | grep intl
If there are no result(s) from this command, you should just go ahead and install the module:
sudo apt-get install php7.4-intl
you will need to change *php7.4 to your desired php version.
you should restart apache when you're done:
sudo service apache2 restart

Class 'Locale' not found issue on CakePHP 3

I'm just downloaded the files from this link, extracted and tried execute but I had this error:
Fatal error: Class 'Locale' not found in D:\xampp\htdocs\cake-3-beta-2\vendor\cakephp\cakephp\src\I18n\I18n.php on line 229
I'm running on localhost with xampp... I had the same issue with beta 1 and 2.
I faced the same problem today. You need to enable the intl PHP extension in your PHP configuration (.ini).
Solution Xampp (Windows)
Open /xampp/php/php.ini
Change ;extension=php_intl.dll to extension=php_intl.dll (remove the semicolon)
Copy all the /xamp/php/ic*.dll files to /xampp/apache/bin
Restart apache in the Xampp control panel
Solution Linux (thanks to Annamalai Somasundaram)
Install the php5-intl extension sudo apt-get install php5-intl
1.1. Alternatively use sudo yum install php5-intl if you are on CentOS or Fedora.
Restart apache sudo service apache2 restart
Solution Mac/OSX (homebrew) (thanks to deizel)
Install the php5-intl extension brew install php56-intl
If you get No available formula for php56-intl follow these instructions.
Restart apache sudo apachectl restart
Eventually you can run composer install to check if it's working.
Change in php ini file
For Older php version
;extension=php_intl.dll to extension=php_intl.dll
For New php versions
;extension=intl to extension=intl

xdebug not loading. not found in phpinfo() after apache restart

I've been scouring every resource I could find, but came up empty. I get the dreaded "Waiting for Connection" message in NetBeans 6.9 when I start a debug session. After much reading, most folks are able to get phpinfo() to display that it loaded the xdebug module. Not so with me.
I downloaded the source through SVN using this call
svn co svn://svn.xdebug.org/svn/xdebug/xdebug/trunk xdebug
I switched to the xdebug directory and then ran phpize on the source
sudo /Applications/MAMP/bin/php5/bin/phpize
Password:
grep: /Applications/MAMP/bin/php5/include/php/main/php.h: No such file or directory
grep: /Applications/MAMP/bin/php5/include/php/Zend/zend_modules.h: No such file or directory
grep: /Applications/MAMP/bin/php5/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
A big fat nothing! The referenced directories don't even exist. So, I make the assumption that any .ini tweaking I do beyond this point is useless. If I do a whereis php, I find it in /usr/bin. That's the default php pre-loaded with the OS. I don't want that one. I need to use the php installed with MAMP. I cannot believe how insanely frustrating it is to get this thing working!
For the record, my xdebug section in my php.ini looks like this:
[xdebug]
; xdebug config for Linux and Mac OS X
zend_extension="/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.idekey="netbeans-xdebug"
xdebug.profiler_enable=1
xdebug.profiler_output_name=xdebug.cachegrind-out.%s.%p
xdebug.remote_log="/Applications/MAMP/logs/xdebug_log.log"
It's a mish-mash of many different attempts to get xdebug to work. So, I don't know which pieces are valid or not.
I throw myself on the mercy of the experts because I obviously am not one of them. I have absolutely no idea how to proceed at this point.
Thanks in advance.
To use phpize in the MAMP directory instead of your system path, you should add MAMP's directory for PHP binaries to your $PATH. Below I'm using MAMP 1.9.1, which offers PHP 5.2 and PHP 5.3. We'll assume you're compiling for PHP 5.3.
Open or create ~/.bash_profile and put the following contents:
#Add MAMP binaries to path
export PATH="/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php5.3/bin:$PATH"
You may also need to chmod the binaries inside /Applications/MAMP/bin/php5.3/bin to be executable:
chmod 755 /Applications/MAMP/bin/php5.3/bin/pear
chmod 755 /Applications/MAMP/bin/php5.3/bin/peardev
chmod 755 /Applications/MAMP/bin/php5.3/bin/pecl
chmod 755 /Applications/MAMP/bin/php5.3/bin/phar
chmod 755 /Applications/MAMP/bin/php5.3/bin/phar.phar
chmod 755 /Applications/MAMP/bin/php5.3/bin/php
chmod 755 /Applications/MAMP/bin/php5.3/bin/php-config
chmod 755 /Applications/MAMP/bin/php5.3/bin/phpcov
chmod 755 /Applications/MAMP/bin/php5.3/bin/phpize
Restart your Terminal session for the new $PATH to be loaded. Run the command which phpize and it should display /Applications/MAMP/bin/php5.3/bin/phpize. If not, the path to phpize in your MAMP directory is not being loaded in your $PATH. Use echo $PATH in Terminal to make sure /Applications/MAMP/bin/php5.3/bin is in the $PATH.
To get xDebug to compile, you need the header files from when PHP was compiled. These are available on the MAMP website in a DMG, and called "MAMP Components": http://www.mamp.info/en/downloads/index.html
Unpack MAMP Components and copy MAMP_src to your Desktop. Unpack MAMP_src/php-5.3.2.tar.gz and move it into the include path present in php-config --includes which should include /Applications/MAMP/bin/php5.3/include/php.
cd ~/Desktop/MAMP_src
tar -xvzf php-5.3.2.tar.gz
mkdir -p /Applications/MAMP/bin/php5.3/include
mv php-5.3.2/ /Applications/MAMP/bin/php5.3/include/php
You can now run phpize in the xDebug source dir.
I had a similar problem with XAMPP on Mac OSX 10.6.
I got no version Numbers when running phpize in the xdebug download directory.
PHP Api Version:
Zend Module Api No:
Zend Extension Api No
I had to install the 'Development Package' which adds /Applications/XAMPP/xamppfiles/include and other files to your XAMPP install. Installing the Development Package also fixed pecl so I tried using pecl to install xdebug.
pecl install xdebug
but apache failed to start with error
Failed loading /Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so: dlopen(/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so, 9): no suitable image found. Did find:
/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so: mach-o, but wrong architecture
I tried compiling from source and got the same 'wrong architecture' errors
Finally I just used the KomodoIDE binary from active state which worked.
I just started working with xdebug myself due to problems with PHP 5.3.1. I had used PECL per instructions a couple weeks ago but it looks like phpize is the new black. I looked over the new instructions (generated from my phpinfo()) # http://xdebug.org/find-binary.php
this is of note:
Run: phpize
As part of its output it should show:
Configuring for:
PHP Api Version: 20090626
...
Zend Extension Api No: 220090626
If it does not, you are using the wrong phpize. Please follow this FAQ entry and skip the next step.
2 things:
have you checked that phpize is up to date?
if that doesnt work try these instructions: http://xdebug.org/docs/install

Resources