PHP编译安装及常见问题

PHP编译安装及常见问题

此贴待改,原始时间为:2019年6月13日15:29:19重修
centos7——64
2018年1月10日17:16:56
编译安装的Apache2.4 yum安装的 mariadb ,PHP源码包7.2.1
本文php7.3可用,需libzip版本0.11以上

2021年6月7日测试Centos8.3 PHP8.0.7测试可用

2021年6月8日测试Centos8.3 PHP7.4.2测试可用


安装:

PHP编译安装教程
参考https://www.cnblogs.com/pengyunjing/p/8687097.html

依赖:yum安装以下

yum -y install pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel libzip libzip-devel

下载源码包

https://www.php.net/downloads.php
wget https://www.php.net/distributions/php-7.3.6.tar.gz
解压
tar -zxvf php-7.3.6.tar.gz
进入目录

编译安装(Centos7-PHP7.2

#./configure \
--prefix=/opt/php \
--with-config-file-path=/opt/php/etc \
--with-apxs2=/opt/Apache/bin/apxs \
此项非apache环境不需要
--with-gd \
此项专业人员可以选择不加(自动编译gd库,如果加入gd编译 就不能引入外部的 gd.so)
--with-ldap \
--with-imap-ssl \
--with-curl \
--with-freetype-dir \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-mhash \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-xml \
--enable-zip \
--with-jpeg \

Centos8.-PHP7.4.20

./configure \
--prefix=/opt/php7 \
--with-config-file-path=/opt/php7/etc \
--with-ldap \
--with-imap-ssl \
--with-curl \
--with-freetype \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-mysqli \
--with-mhash \
--with-openssl \
--with-external-pcre \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-xml \
--with-zip \
--with-jpeg \

Centos8.-PHP8.0.7

在PHP8编译参数有点变动,示例:

./configure \
--prefix=/opt/php \
--with-config-file-path=/opt/php/etc \
--enable-gd \
此项专业人员可以选择不加(自动编译gd库,如果加入gd编译 就不能引入外部的 gd.so)
--with-ldap \
--with-imap-ssl \
--with-curl \
--with-freetype \
--with-gettext \
--with-iconv \
--with-kerberos \
--with-libdir=lib64 \
--with-mysqli \
--with-mhash \
--with-openssl \
--with-external-pcre \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--with-libxml \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-xml \
--with-zip \
--with-jpeg \

注意,当某些编译配置项的时候出现问题要重新配置的时候,养成清理当前环境的习惯:

#./configure clean
#make clean

编译安装

#echo $?
返回0时表示无错,其他返回请参考错误码
#make
#make install
  1. 配置

复制配置文件
cp 编译目录/php.ini-development 安装目录/etc/php.ini
cp 安装目录/etc/php-fpm.conf.default 安装目录/etc/php-fpm.conf
cp 安装目录/etc/php-fpm.d/www.conf.default 安装目录/etc/php-fpm.d/www.conf

修改php.ini

进入/opt/php/bin
查看php版本./php -v
完成

拓展

  • ldap:
    后期为zabbix加入ldap模块支持 需参考
    https://blog.csdn.net/Eric_Alive/article/details/79714838
    ldap依赖yum install -y openldap openldap-devel
    安装完成后
    修改php配置文件,将extension=ldap.so前的分号去掉,保存退出

  • jpeg:
    PHP7:
    后期为zabbix加入libjpeg模块支持

#tar -zxvf jpegsrc.v8b.tar.gz
#cd jpeg-8b
#./configure --prefix=/opt/jpeg --enable-shared --enable-static
#make && make install

PHP8:
#yum install libjpeg libjpeg-devel
安装完成
如果还没编译安装php的可以直接在编译的时候加上这个参数:
--with-jpeg-dir=/usr/local/jpeg \
如果已经安装了的,编译的时候带上了with-gd或者enable-gd则不能添加jpeg支持了,请重新编译整个php
编译的时候没有编译gd则先进入php源码目录:

#cd php-8.0.7/ext/gd
#/opt/php/bin/phpize
php7:
#./configure --with-php-config=/opt/php/bin/php-config --with-jpeg-dir=/opt/jpeg/
php8:
#./configure --with-php-config=/opt/php/bin/php-config --with-jpeg
#make && make install

参考http://jingzhiheng.iteye.com/blog/2335078
(未测试)参考文档https://blog.csdn.net/zzzxxbird/article/details/53609783

安装libzip需更新cmake

cmake-3.15.0-rc1
./configure –prefix=/usr/local/cmake
gmake
gmake install

错误参考:

  • configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
    yum install sqlite-devel

  • checking for oniguruma... no
    configure: error: Package requirements (oniguruma) were not met:
    Package 'oniguruma', required by 'virtual:world', not found

Centos7:

#yum -y install http://mirror.centos.org/centos-7/7.7.1908/cloud/x86_64/openstack-queens/oniguruma-6.7.0-1.el7.x86_64.rpm
#yum -y install http://mirror.centos.org/centos-7/7.7.1908/cloud/x86_64/openstack-queens/oniguruma-devel-6.7.0-1.el7.x86_64.rpm

Centos8:

#yum install autoconf automake libtool
#wget http://down.24kplus.com/linux/oniguruma/oniguruma-6.9.4.tar.gz
#tar -zxf oniguruma-6.9.4.tar.gz
#cd oniguruma-6.9.4
#./autogen.sh && ./configure --prefix=/usr
#make && make install
  • ft2build.h: No such file or directory
#yum install -y freetype freetype-devel
#export C_INCLUDE_PATH=/usr/include/freetype2
#export CPLUS_INCLUDE_PATH=/usr/include/freetype2

参考:
编译问题:找不到头文件,ft2build.h: No such file or directory_SundayO的博客-CSDN博客

参考:
configure: error: Package requirements (oniguruma) were not met_BLXH-AS-CSDN博客
centos ./autogen.sh:行47: autoreconf: 未找到命令_wang 恒 的博客-CSDN博客_autoreconf 未找到命令

# Linux  PHP 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×