网站首页 程序开发 centos7 编译安装 php7.4
centos7 编译安装 php7.4
编辑时间:2021-06-22 10:00 作者:nllihui6390 浏览量:1625

1. 下载安装编译工具

yum groupinstall 'Development Tools'

2.安装依赖包

yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel

3.下载并解压php7.4

wget https://www.php.net/distributions/php-7.4.20.tar.gz
tar -zxvf php-7.4.20.tar.gz 
cd php-7.4.20

4.编译安装(./configure --help 查看编译参数)

 编译前,新增用户组,用户,用于编译使用

groupadd www
useradd -g www www

开始编译(根据自己需要增减)

./configure --prefix=/usr/local/php  --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-xmlrpc --with-openssl --with-mcrypt --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-kerberos --with-libdir=lib64 --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --enable-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --with-zip --enable-xml --enable-mysqlnd-compression-support --without-pear --enable-opcache --enable-pcntl

这里需

要注意的是在php7.4 编译参数 --with-gd  要改成了 --enable-gd

当报错checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11

CentOS安装libzip-1.5.2

#先删除旧版本
yum remove -y libzip


首先下载libzip
# wget  

其次需要安装cmake3
# yum install cmake3 -y
# ln -s /usr/bin/cmake3 /usr/bin/cmake

解压并开始安装
# tar zxvf libzip-1.5.2.tar.gz(注意自行补全正确路径)
# cd libzip-1.5.2

分步安装
# mkdir build && cd build
# cmake ..
# make
# make install

或者一条命令安装
# mkdir build && cd build && cmake .. && make && make install

//添加
export PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig/"

error: Package requirements (sqlite3 > 3.7.4) were not met

yum install libsqlite3x-devel -y

error: Package requirements (oniguruma) were not met

yum install oniguruma-devel -y

 当yum install 提示 "没可用软件包"

yum install -y epel-release

off_t undefined 报错

configure: error: off_t undefined; check your library configuration

off_t 类型是在 头文件 unistd.h中定义的,
在32位系统 编程成 long int ,64位系统则编译成 long long int ,
在进行编译的时候 是默认查找64位的动态链接库,
但是默认情况下 centos 的动态链接库配置文件/etc/ld.so.conf里并没有加入搜索路径,
这个时候需要将 /usr/local/lib64 /usr/lib64 这些针对64位的库文件路径加进去。

#添加搜索路径到配置文件
echo '/usr/local/lib64/usr/local/lib/usr/lib/usr/lib64'>>/etc/ld.so.conf#然后 更新配置
ldconfig -v

/usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory

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

编译没问题了,执行make && make install  安装完毕

5.配置环境

执行完安装命令后php7.4就已经安装在到了/usr/local/php目录下了

/usr/local/php/bin/php -v

查看版本

添加环境变量

vim /etc/profile

添加到最后

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

更新环境变量

source /etc/profile

查看版本

php -v

6.配置php-fpm

cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

启动php-fpm

/etc/init.d/php-fpm start
或者
service php-fpm start


加入 systemtl 服务

cd /home/flame/software/php-7.3.0/sapi/fpm
cp php-fpm.service /usr/lib/systemd/system/


启动


systemctl start php-fpm



[root@web ~]# ps -aux | grep php


[root@test ~]# killall php-fpm

来说两句吧
乖,登录后才可以留言!
最新评论