centos7源码安装php-7.3 & 7.2

举报
yd_297912461 发表于 2026/10/20 09:06:20 2026/10/20
【摘要】 下载安装包 php-7.3.6.tar.gz安装需要的依赖包,可自行安装如:yum  install –y  gcc make gd-devel libxml2-devel openssl openssl-devel   bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel  libxml2-devel libcurl...

下载安装包 php-7.3.6.tar.gz

安装需要的依赖包,可自行安装如:

yum  install –y  gcc make gd-devel libxml2-devel openssl openssl-devel   bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel  libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel gmp-devel libjpeg-devel libpng-devel libargon2-devel    libzip libzip-devel



tar -zxvf php-7.3.6.tar.gz

cd php-7.3.6

./configure --prefix=/usr/local/php7.3 --with-zlib --with-png-dir --with-jpeg-dir  --with-libxml-dir --with-freetype-dir --with-gd --with-curl --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-sockets --enable-bcmath --enable-mbstring --enable-dom --enable-xml --enable-fpm --enable-zip --with-pdo-sqlite --with-libdir=lib64



./configure --prefix=/usr/local/php73 --with-config-file-path=/usr/local/php73/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=dev --with-fpm-group=dev --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --enable-calendar --enable-wddx --with-gmp --with-curl --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-png-dir --with-jpeg-dir   --with-freetype-dir     --enable-exif --with-readline --with-password-argon2



如果出现openssl 的问题:


--with-openssl --with-openssl-dir=/usr/local/openssl-1.1.1i PKG_CONFIG_PATH=/usr/local/openssl-1.1.1i/lib/pkgconfig


  285  wget 
  287  tar zxvf openssl-1.1.1i.tar.gz -C /usr/local/src/
  288  cd /usr/local/src/openssl-1.1.1i/
  294  tar zxvf openssl-1.1.1i.tar.gz -C /usr/local/src/
  295  cd /usr/local/src/openssl-1.1.1i/
  297  ./config --prefix=/usr/local/openssl-1.1.1i/ -fPIC -shared
  298  ./config --prefix=/usr/local/openssl-1.1.1i/  -shared
  299  ./config --prefix=/usr/local/openssl-1.1.1i  
  300  ./Configure --prefix=$HOME/openssl-1.1.1i/bin -fPIC -shared linux-x86_64
  301  ./config --prefix=/usr/local/openssl-1.1.1i/  -shared
  302  ./Configure --prefix=$HOME/openssl-1.1.1i/bin -fPIC -shared linux-x86_64
  304  ./config --prefix=/usr/local/openssl-1.1.1i  -shared
  305  ./config --prefix=/usr/local/openssl-1.1.1i/ -fPIC -shared
  308  /usr/local/openssl-1.1.1i/bin/openssl version
  309  openssl version




php7.2 编译,  增加freetype


./configure --prefix=/usr/local/php72 --with-config-file-path=/usr/local/php72/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=lser --with-fpm-group=web --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --enable-calendar --enable-wddx --with-gmp --with-curl --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --enable-exif --with-readline --with-openssl --with-openssl-dir=/usr/local/openssl-1.1.1i PKG_CONFIG_PATH=/usr/local/openssl-1.1.1i/lib/pkgconfig  --with-freetype-dir --with-jpeg-dir





编译报错 configure: error: Please reinstall the libzip distribution

解决方法:

yum -y install perl


wget https://nih.at/libzip/libzip-1.2.0.tar.gz

tar -zxvf libzip-1.2.0.tar.gz

cd libzip-1.2.0

configure

make && make install

======================额外内容: php7.3 环境重新安装libzip 1.5.2 (1.5.2 需要cmake3)========================

卸载旧版本libzip

yum remove -y libzip

安装cmake3

yum install -y cmake3
sudo ln -sf /usr/bin/cmake3 /usr/bin/cmake

下载最新版libzip

wget https://libzip.org/download/libzip-1.5.2.tar.gz -O libzip.tar.gz
tar xvf libzip.tar.gz
cd libzip*

使用cmake3编译安装libzip

mkdir build && cd build
cmake ..
make && make install

php zip扩展安装

/usr/local/php7/bin/pecl install zip
echo "extension=zip.so;" >> /usr/local/php7/lib/php.ini
service php-fpm restart



====================================================================================

重新编译报错:configure: error: off_t undefined; check your library configuration

解决方法:

添加搜索路径到配置文件

echo '/usr/local/lib64

/usr/local/lib

/usr/lib

/usr/lib64'>>/etc/ld.so.conf

更新配置

ldconfig -v




重新编译,编译成功 ,执行安装






make && make install

安装报错:

/usr/local/include/zip.h:59:21:致命错误:zipconf.h:没有那个文件或目录

解决方法:手动复制过去

cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

重新执行安装命令,安装成功






/usr/local/php73  是我的安装路径

cp php.ini-production /usr/local/php73/etc/php.ini         #复制php.ini

cp /usr/local/php73/etc/php-fpm.conf.default /usr/local/php73/etc/php-fpm.conf  #复制php-fpm配置文件

cp /usr/local/php73/etc/php-fpm.d/www.conf.default /usr/local/php73/etc/php-fpm.d/www.conf

cp /usr/local/php73/sbin/php-fpm /etc/init.d/php-fpm73    #注意:这是可运行文件, 不是 service 脚本


chmod +x /etc/init.d/php-fpm73

启动php

/usr/local/php7.3/sbin/php-fpm73

配置环境变量

vim /etc/profile

在最后面加上:

PATH=$PATH:/usr/local/php/bin

export PATH

立即生效:

source /etc/profile

运行php -v就可看到安装好的php版本了








设置开机启动

在源码包的目录下,我的目录

/www/package/php-7.3.6/sapi/fpm






复制init.d.php-fpm到/etc/init.d/目录下并命名为php-fpm

cp init.d.php-fpm /etc/init.d/php-fpm

使用service命令来 启动/停止 fpm:

  service php-fpm start

  service php-fpm stop

如果失败,请检测php-fpm文件执行权限是否足够

最后, 来设置开机启动

chkconfig php-fpm on

ok这样子就完成啦


【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0)

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。