如何在 Ubuntu 上安装 Xdebug?

god*_*dot 18 php xdebug

我正在尝试xdebug在 Ubuntu上安装:

sudo apt-get install php-xdebug
Run Code Online (Sandbox Code Playgroud)

并收到以下错误:

需要获得 806 kB 的档案。此操作后,将使用 4.423 kB 的额外磁盘空间。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获取 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 未找到 E : 无法获取一些档案,也许运行 apt-get update 或尝试使用 --fix-missing?

我怎么解决这个问题 ?

小智 32

首先,您需要使用以下命令更新本地包:

sudo apt update
# OR
sudo apt-get update
Run Code Online (Sandbox Code Playgroud)

现在您可以xdebug使用以下命令进行安装:

sudo apt install php-xdebug
Run Code Online (Sandbox Code Playgroud)

并将其配置为:

sudo nano /etc/php/7.0/mods-available/xdebug.ini
Run Code Online (Sandbox Code Playgroud)

将以下代码添加到其中:

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 
Run Code Online (Sandbox Code Playgroud)

注意:目录20151012对您来说很可能会有所不同。cd进入/usr/lib/php并检查此格式的哪个目录中包含该xdebug.so文件并使用该路径。

然后重启服务:

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
Run Code Online (Sandbox Code Playgroud)


小智 10

我使用以下方法,它可以从 php 信息中检索内容

$ php -i> info.txt
Run Code Online (Sandbox Code Playgroud)

复制 info.txt 文件中的所有文本,然后进入 xdebug安装向导 并按照那里可用的行列进行操作。

看起来像这样

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
Run Code Online (Sandbox Code Playgroud)


Sum*_*hwa 8

如何在 Ubuntu 上安装 Xdebug

如果上述解决方案都不适合您,那么您最后的选择可能是使用pecl

如果您还没有pecl安装:

sudo apt -y install php7.3-dev php-pear // replace php7.3 with your version
Run Code Online (Sandbox Code Playgroud)

运行pecl安装xdebug

sudo pecl install xdebug
Run Code Online (Sandbox Code Playgroud)

安装结束时,您可能会看到以下输出:

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
Run Code Online (Sandbox Code Playgroud)

打开 php.ini 文件,在最底部添加 zend_exntension 行(如果 pecl 已经能够放置它,则跳过):

sudo vim /etc/php/7.3/apache2/php.ini // again replace 7.3 with your version
Run Code Online (Sandbox Code Playgroud)

最后,重新启动您的网络服务器或 PHP-FPM,具体取决于您使用的服务器。


小智 6

我认为您应该首先通过键入以下命令使用存储库中所做的最新更改来更新本地包索引:

sudo apt update
Run Code Online (Sandbox Code Playgroud)

或者

sudo apt-get update
Run Code Online (Sandbox Code Playgroud)

APT 包索引本质上是 /etc/apt/sources.list 文件和 /etc/apt/sources.list.d 目录中定义的存储库中可用包的数据库。

学分