在 Mac 上使用 Clion 调试 PHP 源码

参考 https://www.jianshu.com/p/f6af567b25a7

一、编译安装 debug 版本的 PHP

  1. configure php

    1
    2
    3
    4
    5
    6
    ./configure --enable-fpm --enable-debug  --with-openssl=/usr/local/Cellar/openssl@1.1/1.1.1i/ \
    --enable-bcmath --with-curl --enable-exif --with-mysqli --with-pdo-mysql \
    --enable-zip --with-zlib=/usr/local/Cellar/zlib/1.2.11/ --enable-intl --enable-pcntl --enable-mbstring --enable-soap \
    --with-icu-dir=/usr/local/Cellar/icu4c/67.1 \
    --with-iconv=/usr/local/Cellar/libiconv/1.16 \
    --with-libxml-dir=/usr/local/Cellar/libxml2/2.9.10_2
  2. 修改 makefile

查找关键字 EXTRA_LIBS = 我的在 line 108,删除所有的 -liconv,末尾加上 /usr/local/opt/libiconv/lib/libiconv.dylib

1
2
3
4
5
# 修改前
EXTRA_LIBS = -lcrypto -lssl -lcrypto -lz -lresolv -lstdc++ -liconv -liconv -lz -lcrypto -lssl -lcrypto -lm -lxml2 -lz -liconv -lm -lcurl -lxml2 -lz -liconv -lm -licui18n -licuuc -licudata -licuio -lxml2 -lz -liconv -lm -lxml2 -lz -liconv -lm -lxml2 -lz -liconv -lm -lxml2 -lz -liconv -lm -lxml2 -lz -liconv -lm

# 修改后
EXTRA_LIBS = -lcrypto -lssl -lcrypto -lz -lresolv -lstdc++ -lz -lcrypto -lssl -lcrypto -lm -lxml2 -lz -lm -lcurl -lxml2 -lz -lm -licui18n -licuuc -licudata -licuio -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm /usr/local/opt/libiconv/lib/libiconv.dylib

  1. make

    1
    make
  2. sudo make install

    1
    sudo make install

二、设定一些目录的权限,不然 Clion 不能正常调试

1
sudo chown -R rovast:wheel /usr/local/lib/php/

makefile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cmake_minimum_required(VERSION 3.13)
project(php_7_2_27)

set(CMAKE_CXX_STANDARD 14)

set(PHP_SOURCE /Users/rovast/Software/tmp/php-7.2.27)

include_directories(${PHP_SOURCE}/main)

include_directories(${PHP_SOURCE}/Zend)

include_directories(${PHP_SOURCE}/sapi)

include_directories(${PHP_SOURCE}/pear)

include_directories(${PHP_SOURCE}/TSRM)

include_directories(${PHP_SOURCE})

add_custom_target(makefile COMMAND make && make install WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

debug on ubuntu

1
2
sudo apt install libxml2-dev
./configure --enable-debug --enable-fpm