centos7编译安装php8

参考:https://blog.csdn.net/zzz1502/article/details/120157436

 

首先安装需要的依赖和第三方库

# yum install -y --setopt=protected_multilib=false gcGc gcc-c++ make cmake automake autoconf gd file bison patch mlocate flex diffutils zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel kernel-devel libtool-libs readline-devel gettext-devel libcap-devel php-mcrypt libmcrypt libmcrypt-devel recode-devel sqlite-devel oniguruma oniguruma-devel libzip libzip-devel openssl-devel sqlite-devel

到PHP下载页面https://www.php.net/downloads.php

下载php源码

# wget  https://www.php.net/distributions/php-8.3.1.tar.gz

解压缩文件

# tar -xzvf  php-8.3.1.tar.gz

解压完成进入文件夹

# cd php-8.3

编译安装

# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli=shared,mysqlnd --with-pdo-mysql --enable-opcache --enable-gd --with-iconv  --with-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg --with-freetype --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm --enable-fast-install --disable-fileinfo --enable-bcmath --with-openssl

编译过程中可能会报错,排查错误一般多是第三方依赖库版本低,或者缺少依赖安装,

错误提示:

1、No package ‘oniguruma’ found

安装

# yum install -y epel-release
# yum install -y oniguruma oniguruma-devel

2 .Requested ‘libzip >= 0.11’ but version of libzip is 0.10.1 libzip 版本太低

	yum remove libzip libzip-devel
	wget https://libzip.org/download/libzip-1.2.0.tar.gz
	tar -zxvf libzip-1.2.0.tar.gz
	cd libzip-1.2.0
	./configure
	make && make install
	export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"

  重新执行 ./configure

执行完成后继续执行

# make && make install

出现如下提示信息代表安装成功

Generating files
configure: patching main/php_config.h.in
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

configure: WARNING: unrecognized options: --enable-inline-optimization, --with-xmlrpc

 

添加www-data用户并禁止登录

# useradd www-data -M -s /sbin/nologin

创建配置文件,并将其复制到正确的位置

cp php.ini-development /usr/local/php/php.ini
cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm /usr/local/bin

将 php.ini 文件中的配置项 cgi.fix_pathinfo 设置为 0 。

打开 php.ini:

# vim /usr/local/php/php.ini

定位到 cgi.fix_pathinfo= 并将其修改为如下所示:

cgi.fix_pathinfo=0

在启动服务之前,需要修改 php-fpm.conf 配置文件,确保 php-fpm 模块使用 www-data 用户和 www-data 用户组的身份运行。
# vim /usr/local/etc/php-fpm.d/www.conf

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = www-data
group = www-data

 

复制 php-fpm 的启动脚本(在php安装文件中)
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

增加执行权限
# chmod 744 /etc/rc.d/init.d/php-fpm

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

开启服务
# chkconfig --add php-fpm
# chkconfig php-fpm on

启动 php-fpm 服务:

/usr/local/bin/php-fpm

 

posted on 2023-12-24 14:17  建安永乐  阅读(385)  评论(0编辑  收藏  举报

导航