layout: post

编译一下php73(apt系)

subtitle: 编译一下php73(apt系) date: 2020-20-21 author: BY header-img: img/post-bg-kuaidi.jpg catalog: true tags: - php73 - 编译

编译一下php73(apt系)

  • 下载源码,hub.fastgit.org 是 github 加速地址

wget http://hub.fastgit.org/php/php-src/archive/php-7.3.23.tar.gz
  • 生成 configure 文件

./buildconf
  • 部分依赖

# configure: error: bison is required to build PHP/Zend when building a GIT checkout!
sudo apt install bison

# Cannot find OpenSSL's libraries
find /usr/lib/ -name libssl.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib

# Cannot find libxml2
sudo apt install libxml2-dev

# Please reinstall the libcurl distribution
# https://github.com/laruence/yar/issues/111#issuecomment-352615976
sudo apt install libcurl4-gnutls-dev
sudo ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/

# configure: error: jpeglib.h not found.
sudo apt-get install libjpeg-dev

# configure: error: png.h not found.
sudo apt-get install libpng-dev

# error: libXpm.(a|so) not found.
sudo apt-get install libxpm-dev

# error: freetype.h not found.
sudo apt-get install libfreetype6-dev

# error: freetype-config not found.
# 检测参数 --with-freetype-dir 目录是否正确
# 如果仍失败 使用旧版本 freetype https://github.com/centos-bz/ezhttp/issues/31#issue-445848320
wget https://download.savannah.gnu.org/releases/freetype/freetype-2.8.1.tar.bz2
# 解压
tar xvf freetype-2.8.1.tar.bz2
cd freetype-2.8.1
./configure
make && sudo make install
# 安装可看到提示的位置 /usr/local/include/freetype2/freetype

# mcrypt.h not found. Please reinstall libmcrypt.
sudo apt-get install libmcrypt-dev

# xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
sudo apt-get install libxslt1-dev

# error: Please reinstall the libzip distribution
sudo apt install libzip-dev

# error: re2c 0.13.4 is required to generate PHP lexers.
sudo apt install re2c
# 或者源码编译 wget http://hub.fastgit.org/skvadrik/re2c/releases/download/2.0.3/re2c-2.0.3.tar.xz

# checking for libxml-2.0 >= 2.7.6... no
sudo apt-get install pkg-config
wget https://hub.fastgit.org/GNOME/libxml2/archive/v2.9.10.tar.gz
tar xvzf v2.9.10.tar.gz
cd libxml2-2.9.10
./autogen.sh
./configure --prefix=/usr --disable-static --with-history
make -j4
sudo make install

# No package 'oniguruma' found
sudo apt install libonig-dev
  • 初始化

./configure \
--prefix=/usr/local/php73 \
--exec-prefix=/usr/local/php73 \
--bindir=/usr/local/php73/bin \
--sbindir=/usr/local/php73/sbin \
--includedir=/usr/local/php73/include \
--libdir=/usr/local/php73/lib/php \
--mandir=/usr/local/php73/php/man \
--with-config-file-path=/usr/local/php73/etc \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mcrypt=/usr/include \
--with-mhash \
--with-openssl \
--with-mysql=shared,mysqlnd \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-gd \
--with-iconv \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--with-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir=/usr/local/include/freetype2/freetype \
--enable-opcache \
--enable-redis \
--enable-fpm \
--enable-fastcgi \
--with-fpm-user=www \
--with-fpm-group=www \
--without-gdbm
  • 编译 安装

make -j4
make install


# 安装完成提示
Installing shared extensions:     /usr/local/php73/lib/php/extensions/no-debug-non-zts-20180731/
Installing PHP CLI binary:        /usr/local/php73/bin/
Installing PHP CLI man page:      /usr/local/php73/php/man/man1/
Installing PHP FPM binary:        /usr/local/php73/sbin/
Installing PHP FPM defconfig:     /usr/local/php73/etc/
Installing PHP FPM man page:      /usr/local/php73/php/man/man8/
Installing PHP FPM status page:   /usr/local/php73/php/php/fpm/
Installing phpdbg binary:         /usr/local/php73/bin/
Installing phpdbg man page:       /usr/local/php73/php/man/man1/
Installing PHP CGI binary:        /usr/local/php73/bin/
Installing PHP CGI man page:      /usr/local/php73/php/man/man1/
Installing build environment:     /usr/local/php73/lib/php/build/
Installing header files:          /usr/local/php73/include/php/

Installing helper programs:       /usr/local/php73/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php73/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php73/lib/php/php/
--2020-10-21 16:29:59--  https://pear.php.net/install-pear-nozlib.phar
Resolving pear.php.net (pear.php.net)... 109.203.101.62
Connecting to pear.php.net (pear.php.net)|109.203.101.62|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3634227 (3.5M)
Saving to: ‘pear/install-pear-nozlib.phar’
install-pear-nozlib.phar   100%[=======================================>]   3.47M  67.9KB/s    in 89s

2020-10-21 16:31:34 (39.7 KB/s) - ‘pear/install-pear-nozlib.phar’ saved [3634227/3634227]

[PEAR] Archive_Tar    - installed: 1.4.9
[PEAR] Console_Getopt - installed: 1.4.3
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.5
warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.4.9 is not the recommended version 1.4.4
[PEAR] PEAR           - installed: 1.10.12
Wrote PEAR system config file at: /usr/local/php73/etc/pear.conf
You may want to add: /usr/local/php73/lib/php/php to your php.ini include_path
/mnt/d/docker/work/php-src-php-7.3.23/build/shtool install -c ext/phar/phar.phar /usr/local/php73/bin
ln -s -f phar.phar /usr/local/php73/bin/phar
Installing PDO headers:           /usr/local/php73/include/php/ext/pdo/
  • 安装扩展 swoole

# 源码地址: https://github.com/swoole/swoole-src/releases

/usr/local/php73/bin/phpize

./configure --with-php-config=/usr/local/php73/bin/php-config

# 如果之前编译过其他版本php的话,请先清除
make clean

make -j4

make install

# 配置
sudo touch /usr/local/php73/etc/php.ini

echo "extension=swoole.so" > /usr/local/php73/etc/php.ini

cat /usr/local/php73/etc/php.ini