可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm having issues setting up my PHP development environment on OS X after installing OS X 10.9 Mavericks.
Here is the command I am using to install.
sudo pecl install xdebug
downloading xdebug-2.2.3.tgz ...
Starting to download xdebug-2.2.3.tgz (250,543 bytes)
.....................................................done: 250,543 bytes
66 source files, building
running: phpize
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
ERROR: `phpize' failed
Anyone have a solution or a workaround?
回答1:
The fast copy-paste way
sudo sh -c 'echo zend_extension=$(find /usr/lib/php/extensions -name "xdebug.so") >> $(php -qr "echo php_ini_loaded_file();") && apachectl restart'
This command do the following :
- Finds the native Xdebug extension that comes with Xcode
- Asks php which config file is loaded
- Adds the Xdebug extension path in the config file
- Restarts apache.
Compatible with Sierra, El Capitan & Yosemite with the bundeled apache, but untested with MAMP & XAMPP.
Before launching the command, make sure Xcode command line tools are installed : xcode-select --install
回答2:
Don't know about using pecl
. Getting Xdebug after an OS X install is pretty straightforward without pecl
. You've got two easy options:
Use the version already available at:
/usr/lib/php/extensions/no-debug-non-zts-2010052/xdebug.so
Build your own:
Make sure you have the Xcode CLI tools: xcode-select --install
will prompt you to install the CLI tools. With the CLI tools installed, there should be stuff inside /usr/include/php
.
Go to http://xdebug.org/download.php and download the source tarball for the version of Xdebug you want. For example: http://xdebug.org/files/xdebug-2.2.3.tgz.
Extract the tarball and cd
into the directory it created. Inside that directory you'll see a README
. From here it's:
$ phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
$ ./configure --enable-xdebug
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
[... output ...]
$ make
[... output ...]
Your built xdebug.so
is now at modules/xdebug.so
. The phpize
is critical to do with XCode CLI tools installed, because phpize
sets up the build parameters for your version of PHP.
With your xdebug.so
in hand from (1) or (2) above, you can add this block to the php.ini
being used by your php
or php-fpm
:
[Xdebug]
zend_extension=<full_path_to_xdebug.so>
xdebug.remote_enable=1
xdebug.remote_host=<host running PHP (e.g. localhost)>
xdebug.remote_port=<port Xdebug tries to connect to on the host running PHP (default 9000)>
回答3:
There are two issues here. The first is that you need to install Xcode command line tools with the command:
xcode-select --install
This will mean that the files previously not found in /usr/include/php/
will be available.
The next step is to install autoconf
in the same way as Ares shows in his answer.
I would cd
into your download folder first
cd ~/Downloads/
curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz
tar xzf autoconf-latest.tar.gz
cd autoconf-*
./configure --prefix=/usr/local
make
sudo make install
now you can run the pecl install
command
sudo pecl install xdebug
回答4:
If you are using Mac Yosemite 10.10 and none of the above answers solved the problem. Do the following:
Open a terminal
Execute find /usr/lib/php/extensions -name "xdebug.so"
to know the path to the debug library.
- Execute
sudo nano /etc/php.ini
to open and edit the php.ini file
In php.ini add the following lines at the end
[XDebug]
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
(When finished, type control+o
to save and control+x
to close the file)
(Don't forget to replace the value in zend_extension for whatever you got from the first terminal command)
- Execute
sudo apachectl restart
to load the new configuration
- Sit back and relax
回答5:
For anyone who is facing this issue I had to build autoconf from source. I followed this answer from another StackOverflow question.
https://stackoverflow.com/a/12333230/2272004
回答6:
For the issue phpize error,try this will solve your problem:
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include /usr/include
回答7:
I had to brew install xdebug
and choose for my version of PHP and it worked!
For example,
brew install homebrew/php/php56-xdebug
For a PHP version 5.6 variant.