参考:

https://www.sunanzhi.com/archives/27/

经验

优先使用源码安装,因为yum安装时,yum版本和系统版本和redhat版本各种不一致

 yum install 找不到源时吗,就搜索提供服务包的原地址,比如

yum -y install http://down.24kplus.com/linux/oniguruma/oniguruma-devel-6.7.0-1.el7.x86_64.rpm

安装

1、到官网获取下载地址 https://www.php.net/downloads

2、下载并解压

cd /home/install/php74
wget https://www.php.net/distributions/php-7.4.25.tar.gz
tar -zxvf php-7.4.25.tar.gz

3、进入解压目录编译配置

cd php-7.4.25

sudo ./configure --prefix=/usr/local/php74 \
 --with-config-file-path=/etc --enable-fpm  --enable-inline-optimization \
 --disable-debug --enable-mysqlnd --enable-static --disable-rpath --enable-shared --enable-soap  --with-xmlrpc \
 --with-openssl --with-mhash  --with-zlib \
 --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl \
 --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pear \
 --enable-opcache --enable-ftp --with-gdbm --with-openssl-dir --with-jpeg --with-zlib-dir \
 --with-freetype --enable-gd --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --with-sqlite3\
 --enable-mbstring --enable-mbregex --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
 --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg \
 --enable-sysvsem --enable-sysvshm --with-xsl --with-zip --enable-mysqlnd-compression-support --enable-intl \
 --with-config-file-path=/usr/local/php74/etc \
 PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/  (这句如果 libzip 没有报错不用复制)

注意 –with-config-file-path 指定 php.ini

或者

./configure 
--prefix=/usr/local/php74 
--disable-fileinfo 
--enable-fpm 
--with-config-file-path=/usr/local/php74/etc 
--with-config-file-scan-dir=/usr/local/php74/etc/php.d 
--with-openssl 
--with-zlib 
--with-curl 
--enable-ftp 
--with-gd 
--with-xmlrpc 
--with-jpeg-dir 
--with-png-dir 
--with-freetype-dir 
--enable-gd-native-ttf 
--enable-mbstring 
--enable-zip 
--enable-mysqlnd 
--with-mysqli=mysqlnd 
--with-pdo-mysql=mysqlnd 
--without-pear  
--enable-bcmath 
--enable-tokenizer 
--enable-libxml 
--enable-ctype 
--enable-pcntl 
--enable-cli

编译时可能会出现一些错误 configure error

1. configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
处理:yum install sqlite-devel -y

2. configure: error: Please reinstall the BZip2 distribution
处理:yum install bzip2 bzip2-devel -y

3. configure: error: Package requirements (libcurl >= 7.15.5) were not met:No package 'libcurl' found
处理:yum install libcurl libcurl-devel -y

4. configure: error: GNU MP Library version 4.2 or greater required.
处理:yum install gmp-devel -y

5. configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:
    No package 'icu-uc' found
    No package 'icu-io' found
    No package 'icu-i18n' found
处理:yum install libicu-devel -y

6. configure: error: Package requirements (oniguruma) were not met: No package 'oniguruma' found
处理:yum install oniguruma-devel -y

7. configure: error: Please reinstall readline - I cannot find readline.h
处理:yum install readline-devel -y

8. configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:No package 'libzip' found
处理:yum remove libzip libzip-devel
     cd /home/install/libzip1.2
     wget https://hqidi.com/big/libzip-1.2.0.tar.gz
     tar -zxvf libzip-1.2.0.tar.gz
     cd libzip-1.2.0
     ./configure
     make && make install

     #####完成后#####
     make[2]: Nothing to be done for `install-exec-am'.
     /usr/bin/mkdir -p '/usr/local/lib/pkgconfig'
     /usr/bin/install -c -m 644 libzip.pc '/usr/local/lib/pkgconfig'
     make[2]: Leaving directory `/home/install/libzip1.2/libzip-1.2.0'
     make[1]: Leaving directory `/home/install/libzip1.2/libzip-1.2.0'
     #####完成后#####

     export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
     echo $PKG_CONFIG_PATH

     #####显示#####
     /usr/local/lib/pkgconfig
     #####显示#####

4、安装

make && make install

 

配置

1、切换到 源代码目录

cd /home/install/php74/php-7.4.25

2、拷贝 php.ini文件

cp php.ini-production /usr/local/php74/etc/php.ini

3、服务管理

# 通过 service 管理
cd /home/install/php74/php-7.4.25/sapi/fpm
cp init.d.php-fpm /etc/init.d/php74-fpm
chmod 755 /etc/init.d/php74-fpm
# 配置完成之后
service php74-fpm start
# 自动开机启动
vi /etc/rc.d/rc.local
# 添加 下面一行并保存
/etc/init.d/php74-fpm start
# 然后执行加载配置
ldconfig

########################### 分割

# 通过 systemd 管理
cd /home/install/php74/php-7.4.25/sapi/fpm
cp php-fpm.service /lib/systemd/system/php74-fpm.service
vi /usr/lib/systemd/system/php74-fpm.service
# ProtectSystem=full 改成下面这个配置并保存
ProtectSystem=false
# 重载一下命令
systemctl daemon-reload
# 加入开机启动
systemctl enable php74-fpm.service
# 启动服务
systemctl start php74-fpm.service

4、配置php-fpm

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

# 如果需要修改 监听端口
vi /usr/local/php74/etc/php-fpm.d/www.conf
# listen = 1270.0.0.1:9000 改成 你想要监听的端口

5、修改php.ini时区

vi /usr/local/php74/etc/php.ini
# 修改并保存
date.timezone = "Asia/Shanghai"

 

安装其他拓展

redis 拓展

1、去官方拓展获取redis拓展地址 https://pecl.php.net/get/redis-5.3.4.tgz

2、下载解压

cd /home/install/php-redis

wget https://pecl.php.net/get/redis-5.3.4.tgz

tar zxvf redis-5.3.4.tgz

3、指定版本安装

cd /home/install/php-redis/redis-5.3.4
/usr/local/php74/bin/phpize
./configure --with-php-config=/usr/local/php74/bin/php-config
make && make install

4、修改php.ini文件

vi /usr/local/php74/etc/php.ini
# 末尾添加 redis.so 并保存
[redis]
extension=redis.so

5、重启 php

systemctl restart php74-fpm.service

gd扩展:GD扩展踩坑指南

安装依赖 libpng、libzip、zlib、freetype、libgd、libjpeg
libpng

wget http://jaist.dl.sourceforge.net/project/libpng/libpng16/1.6.31/libpng-1.6.31.tar.gz
tar -xzvf libpng-1.6.31.tar.gz
cd libpng-1.6.31
./configure --prefix=/usr/local/libpng --enable-shared
make
make install

libzip

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

zlib

wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar -xzvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix=/usr/local/zlib --enable-shared
make
make install

freetype

wget https://download.savannah.gnu.org/releases/freetype/freetype-2.10.1.tar.gz
tar -xzvf freetype-2.10.1.tar.gz
cd freetype-2.10.1
./configure --prefix=/usr/local/freetype --enable-shared
make
make install

libgd

wget https://github.com/libgd/libgd/releases/download/gd-2.2.3/libgd-2.2.3.tar.gz
tar -xzvf libgd-2.2.3.tar.gz
cd libgd-2.2.3
./configure --enable-shared
make
make install
make clean
make distclean

libjpeg

wget http://www.ijg.org/files/jpegsrc.v9d.tar.gz
tar -xzvf jpegsrc.v9d.tar.gz
cd jpeg-9d
./configure --prefix=/usr/local/libjpeg --enable-shared
make
make install
进入PHP目录安装扩展
cd ~/php-7.4.x/ #源码目录
cd ext/gd/

/usr/local/php74/bin/phpize #可能会报错

./configure --enable-gd 
--with-php-config=/usr/local/php74/bin/php-config
--with-jpeg=/usr/local/libjpeg
--with-png=/usr/local/libpng #可能无效,尝试加
--with-zlib=/usr/local/zlib #同上
--with-freetype=/usr/include/freetype2/freetype #使用ldconfig -p |grep freetype或者yum list install|grep freetype,实在不行使用 find / -name freetype
--enable-gd-native-ttf #和freetype配套 make make install

 

查看某个lib库是否安装
ldconfig -p | grep pcap
/usr/local/php74/bin/phpize #可能会报错
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

#解决
yum install autoconf
查看gd库具体支持哪些图片格式和图片操作
php-info()
GD扩展最后的效果:freetype,gif,jpeg,pngwbmp等等

 

 

 

 

 

版权声明:本文为细节决定专业原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/tkzc2013/p/16742880.html