I’ve been struggling to get xdebug to work all day. I have tried a complete reinstall of homebrew, cleared out php and installed the newest version, reinstalled apache (following: https://getgrav.org/blog/macos-catalina-apache-multiple-php-versions) and now have tried to install using pecl as well as from the source xdebug and I continue to get errors. Trying to install via pecl:
sudo pecl install xdebug
Password:
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in Validator.php on line 1933
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /usr/local/pear/share/pear/PEAR/PackageFile/v2/Validator.php on line 1933
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
Cannot install, php_dir for channel "pecl.php.net" is not writeable by the current user
robshpiel1@iPutz47 ~ % pecl config-get php_dir
/usr/lib/php/
robshpiel1@iPutz47 ~ % sudo chown robshpiel1 /usr/lib/php
chown: /usr/lib/php: Read-only file system
robshpiel1@iPutz47 ~ % pecl config-set php_dir /usr/local/opt/[email protected]/
config-set succeeded
robshpiel1@iPutz47 ~ % sudo pecl install xdebug
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in Validator.php on line 1933
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /usr/local/pear/share/pear/PEAR/PackageFile/v2/Validator.php on line 1933
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading xdebug-2.9.0.tgz ...
Starting to download xdebug-2.9.0.tgz (242,853 bytes)
..................................................done: 242,853 bytes
Fatal error: Cannot use result of built-in function in write context in /usr/local/pear/share/pear/Archive/Tar.php on line 639
Or when making from the actual source i get the following on make install:
robshpiel1@iPutz47 xdebug % sudo make install
Password:
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20180731/
cp: /usr/lib/php/extensions/no-debug-non-zts-20180731/#INST@4741#: Read-only file system
make: *** [install-modules] Error 1
robshpiel1@iPutz47 xdebug %
Something has to be wrong with permissions and the read only file system in Catalina and I can’t seem to wrap my head around it. I even tried turning off SIP.
Any clues?
PHP, Apache, Homebrew, Eclipse are all installed and working..just can’t get xdebug to work.
3
Answers
Ok, I got this working, thanks to Derek's help. Here is what I did for a full Mac PHP Development setup:
0) Install prerequisite software if not already installed (homebrew, xcode, etc)
Xcode command line tools:
Homebrew:
Catalina Required Libraries:
1) Completely uninstall php, httpd (apache), and delete xdebug files (if you had them already installed):
Find whatever versions of php you have installed based on the brew list command then uninstall them, e.g.:
Clean out any old php configurations
2) Install Apache
If you already have the built-in Apache running, it will need to be shutdown first, and any auto-loading scripts removed:
Install apache:
Setup Apache to autostart:
You should now be able to go to http://localhost:8080 and see an "It Works" message.
3) Configure Apache
Using your favorite text editor, open
/usr/local/etc/httpd/httpd.conf
Find the line that says
Listen 8080
and change it toListen 80
If you want, change to default directory of where you serve your websites from. Search for the term
DocumentRoot
and change the value to where you want. I used:but you can put it anywhere you like (such as
/Users/your_user/Sites
for example)You also need to change the tag reference right below the DocumentRoot line. This should also be changed to point to your new document root also:
In that same block you will find an AllowOverride setting, this should be changed to:
Also we should now enable mod_rewrite which is commented out by default. Search for mod_rewrite.so and uncomment the line by removing the leading #:
Change the user and group to match your currently logged in user:
Change the servername to
localhost
Save the file.
Restart Apache to ensure your changes take effect:
3) Install PHP
I installed php 7.2, even though it's not the latest, simply because my hosting site and wordpress uses php 7.2 and I want to integrate my php application with my wordpress site.
Once php is installed, go back to your httpd.conf file and add the following line:
below the previously uncommented LoadModule rewrite _module from the last step.
Also you must set the Directory Indexes for PHP explicitly, so search for this block:
Copy and replace it with this:
Save the file and restart the apache server again:
4) Validate the php installation
Simply create a file called info.php in your Sites/ folder you created earlier with this one-liner.
Point your browser to http://localhost/info.php and you should see a PHP information page.
Homebrew should have added its preferred /usr/local/bin and /usr/local/sbin to your path as part of its installation process. Quickly test this by typing:
If you don't see this, you might need to add these manually to your path. Depending on your shell you're using, you may need to add this line to ~/.profile, ~/.bash_profile, or ~/.zshrc:
5) Install Xdebug.
If the command:
Fails due to the phpize not returning the correct information, or it's trying to write to folders it cannot, or it cannot find php.h, etc, as it did for me and what started this post, try the following:
First, you need to make sure that Xcode and the command line tools installed. Open a terminal window and run the following command to display the SDK path:
This command should output something like this:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
If it doesn't, install them using the command listed in step 0.
Now create a new folder in your home folder for phpize:
And copy the following file to it:
Open a text editor, and create a file with the following patch code:
Save that file as phpize-catalina.patch in your new php-private folder (be sure to cd in to that folder too).
Next patch your new copy of phpize:
Next, download the latest source files of xdebug, for me it was 2.9.0
That should have downloaded all the source files to the ~/xdebug path. Change directories to this path.
Now run the phpize file we patched:
You should see the following output:
If you receive the error:
It means you do not have autoconf installed. Try:
Once you receive the above output of phpize, configure and install xdebug:
This should use the php config that you installed via homebrew in step 3.
Now build the extension:
Now install it:
You should see something like:
Now you need to add the extension to your php.ini file. Use your favorite editor to modify
/usr/local/etc/php/7.2/php.ini
(don't forget sudo when opening your text editor) and add this to the very bottom:Note, all you really need to add is the zend_extension line but in order to have it work with Eclipse I use the remote enabled flags along with the other settings listed there.
Finally, restart apache:
And then when you refresh the info.php page you created earlier you should see lines for xdebug in the configuration. Something like:
succesful xdebug validation
6) Finally, for my complete PHP mac development setup, I installed the latest version of eclipse for php (from their website) as well as SQL Server (using homebrew). You can google how to install those as they are pretty straightforward.
Each error has a different cause.
First of all, your
sudo pecl install
is generally the right way of installing Xdebug, because, as you’ve found you can set the installation directory withpecl config-set
.However, the pecl/pear version that you are running, is likely for an old version of PHP. Because PHP does change once in a while, the pecl tool needs to be updated too. For PHP 7.2, I run pecl version 1.10.9 (you can check with
pecl -V
). I would think that the one you’re running is quite a bit older. Generally you can update pear/pecl by usingpear upgrade pear
, but you will likely run into an unwritable directory problem again.Secondly,
sudo make install
to fails because it is trying to write into an unwritable directory (/usr/lib/php/extensions/no-debug-non-zts-20180731/
). If you know what the right directory is (check withphp -i | grep extensions
), you can just copy it into that directory yourself. After themake
stage, there should be axdebug.so
in themodules
directory within the Xdebug source tree.The “official” way to solve the latter problem is to use the
--with-php-config
option to Xdebug’s./configure
line, where you can specify the one that you want to use for Xdebug with something like:./configure --with-php-config=/usr/local/opt/[email protected]/bin/php-config
(but check the paths, as I don’t have a Mac set up here). This should then pick up the right extensions directory, andsudo make install
should work.Alternatively, if you are a MAC user is to install MAMP. It comes with the xdebug extension ready to use in all the versions of php that MAMP has built-in.
After installing MAMP, you just have to add these lines in the php.ini file corresponding to each version of PHP:
For php8:
for php 7.4 and earlier: