PHP

总结Mac下编译php过程的问题(不全)

2020年7月9日

最近刚入职新东家,重新编译下php,简单总结了一点,以备以后使用,不过估计以后也很少再去编译了

基本编译步骤

# 如果要重新编译 记得清理
./buildconf --force
./configure clean

./configure

选项自行配置

./configure --prefix=/usr/share/php7.0 \
--with-config-file-path=/etc/php/7.0 \
--with-curl=/usr/local/opt/curl \
--with-pear \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib=/usr/local/opt/zlib \
--with-xpm-dir \
--with-freetype-dir \
--with-mcrypt=/usr/local/opt/mcrypt \
--with-mhash \
--with-mysql \
--with-mysqli \
--enable-pdo \
--with-pdo-mysql \
--with-openssl \
--with-xmlrpc \
--with-xsl \
--with-gettext \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--enable-fpm \
--enable-exif \
--enable-wddx \
--enable-zip \
--enable-bcmath \
--with-bz2=/usr/local/opt/bzip2 \
--enable-calendar \
--enable-ftp \
--enable-mbstring \
--enable-soap \
--enable-sockets \
--enable-shmop--enable-dba \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-debug--enable-maintainer-zts \
--enable-embed \
--with-openssl=/usr/local/opt/openssl \
--with-iconv=/usr/local/opt/libiconv

make

make

make install

 make install

问题

找不到.h文件

例如:configure: error: Cannot find OpenSSL’s

解决方法

1. 安装对应开发包后,指定库所在目录

brew install openssl
--with-openssl=/usr/local/opt/openssl

2. 将.h文件放到php源码目录中的对应拓展目录下

cp /path/evp.h /path/php/ext/openssl/

make后缺少.o文件

例如:clang: error: no such file or directory: ‘ext/date/php_date.o’

clang: error: no such file or directory: 'ext/date/php_date.o'
clang: error: no such file or directory: 'ext/date/lib/astro.o'
clang: error: no such file or directory: 'ext/date/lib/dow.o'
clang: error: no such file or directory: 'ext/date/lib/parse_date.o'
clang: error: no such file or directory: 'ext/date/lib/parse_tz.o'
clang: error: no such file or directory: 'ext/date/lib/timelib.o'
clang: error: no such file or directory: 'ext/date/lib/tm2unixtime.o'
clang: error: no such file or directory: 'ext/date/lib/unixtime2tm.o'
clang: error: no such file or directory: 'ext/date/lib/parse_iso_intervals.o'

解决方法:

原因:OS X puts the files in .libs directory. Workaround is to copy the files.
我写了一段php脚本用来将.libs中的.o文件复制出来

setup1 将错误信息保存到文本1.txt中,并之保留对应的.o文件名,就像下面一样

main/fastcgi.o
sapi/fpm/fpm/fpm.o
sapi/fpm/fpm/fpm_children.o
sapi/fpm/fpm/fpm_cleanup.o
sapi/fpm/fpm/fpm_clock.o
sapi/fpm/fpm/fpm_conf.o
sapi/fpm/fpm/fpm_env.o
sapi/fpm/fpm/fpm_events.o
sapi/fpm/fpm/fpm_log.o
sapi/fpm/fpm/fpm_main.o
sapi/fpm/fpm/fpm_php.o
sapi/fpm/fpm/fpm_php_trace.o
sapi/fpm/fpm/fpm_process_ctl.o
sapi/fpm/fpm/fpm_request.o
sapi/fpm/fpm/fpm_shm.o
sapi/fpm/fpm/fpm_scoreboard.o
sapi/fpm/fpm/fpm_signals.o
sapi/fpm/fpm/fpm_sockets.o
sapi/fpm/fpm/fpm_status.o
sapi/fpm/fpm/fpm_stdio.o
sapi/fpm/fpm/fpm_unix.o
sapi/fpm/fpm/fpm_worker_pool.o
sapi/fpm/fpm/zlog.o
sapi/fpm/fpm/events/select.o
sapi/fpm/fpm/events/poll.o
sapi/fpm/fpm/events/epoll.o
sapi/fpm/fpm/events/kqueue.o
sapi/fpm/fpm/events/devpoll.o
sapi/fpm/fpm/events/port.o
sapi/fpm/fpm/fpm_trace.o
sapi/fpm/fpm/fpm_trace_mach.o
sapi/cgi/cgi_main.o

setup2 执行php脚本,此脚本会生成 2.sh

<?php
$fp = fopen("./1.txt", "r");
while($c = fgets($fp)) {
    $c = trim($c);
    $should = trim(str_replace(".o", ".o", $c));
    $arr = explode("/", $should);
    $should = array_merge(array_slice($arr, 0, count($arr) - 1), ['.libs'], array_slice($arr, count($arr) - 1));
    $should = implode('/', $should);
    var_dump($should);
    $s =  "cp {$should} {$c}";
    file_put_contents('./2.sh', $s . PHP_EOL, FILE_APPEND);
}

setup3 执行2.sh

sh 2.sh

因为错误不是一下就消失的,解决了一批会再出来一批,所以这个过程需要循环执行,直到这些错误不再出现。(这个过程挺复杂,有时间都放到php脚本中)

发表评论

电子邮件地址不会被公开。 必填项已用*标注