一、PHP简介

PHP是一种创建动态交互性站点的强有力的服务器端脚本语言。PHP是目前动态网页开发中使用最为广泛的语言之一。PHP能运行在包括Windows、Linux等在内的绝大多数操作系统环境中。

PHP是免费的,并且使用非常广泛。同时,对于像微软ASP这样的竞争者来说,PHP无疑是另一种高效率的选项。

给大家介绍下CentOS 7.9下如何通过编译去安装php-7.4.29,教程为本人亲测。

操作系统:CentOS Linux release 7.9.2009

Libzip:1.2.0

Oniguruma:6.9.7.1

PHP版本:7.4.29

二、安装Libzip

下载地址:https://libzip.org/download/libzip-1.2.0.tar.gz

1、安装依赖包

[root@localhost ~]# cd ~ && yum -y install wget gcc gcc-c++ zlib-devel

2、下载安装包

[root@localhost ~]# wget https://libzip.org/download/libzip-1.2.0.tar.gz

3、解压安装包

[root@localhost ~]# tar xf libzip-1.2.0.tar.gz

4、预编译

[root@localhost ~]# cd libzip-1.2.0/

[root@localhost libzip-1.2.0]# ./configure

5、编译和安装

[root@localhost libzip-1.2.0]# make && make install

6、配置

[root@localhost libzip-1.2.0]# cat >/etc/ld.so.conf <<EOF

/usr/local/lib64

/usr/local/lib

/usr/lib

/usr/lib64

EOF

三、安装oniguruma

下载地址:https://github.com/kkos/oniguruma/releases/download/v6.9.7.1/onig-6.9.7.1.tar.gz

1、安装依赖包

[root@localhost ~]# cd ~ && yum -y install wget gcc gcc-c++

2、下载安装包

[root@localhost ~]# wget --no-check-certificate https://github.com/kkos/oniguruma/releases/download/v6.9.7.1/onig-6.9.7.1.tar.gz -O oniguruma-6.9.7.1.tar.gz

3、解压安装包

[root@localhost ~]# tar xf oniguruma-6.9.7.1.tar.gz

4、预编译

[root@localhost ~]# cd onig-6.9.7

5、编译和安装

[root@localhost onig-6.9.7]# ./configure --prefix=/usr --libdir=/lib64

[root@localhost onig-6.9.7]# make && make install

四、安装PHP

1、下载php-7.4.29软件包

下载地址:https://www.php.net/distributions/php-7.4.29.tar.gz

[root@localhost ~]# wget -c https://www.php.net/distributions/php-7.4.29.tar.gz

2、解压php-7.4.29软件包

[root@localhost ~]# tar xf php-7.4.29.tar.gz

3、进入php目录

[root@localhost ~]# cd php-7.4.29

4、安装epel-release源

[root@localhost php-7.4.29]# yum -y install epel-release

5、安装依赖包

[root@localhost php]# yum -y install sqlite-devel wget gcc gcc-c++ pcre pcre-devel openssl openssl-devel libxml2 libxml2-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 cmake

6、编译配置(如果出现错误,基本都是上一步的依赖文件没有安装所致),嫌麻烦的可以从这一步起参考PHP官方安装说明:

http://php.net/manual/zh/install.unix.nginx.php(极简安装)

[root@localhost php-7.4.29]# 

./configure --prefix=/usr/local/php \

--with-config-file-path=/etc \

--enable-fpm \

--with-fpm-user=www \

--with-fpm-group=www \

--enable-inline-optimization \

--disable-debug \

--disable-rpath \

--enable-shared \

--enable-soap \

--with-libxml-dir \

--with-xmlrpc \

--with-openssl \

--with-mhash \

--with-pcre-regex \

--with-sqlite3 \

--with-zlib \

--enable-bcmath \

--with-iconv \

--with-bz2 \

--enable-calendar \

--with-curl \

--with-cdb \

--enable-dom \

--enable-exif \

--enable-fileinfo \

--enable-filter \

--with-pcre-dir \

--enable-ftp \

--with-gd \

--with-openssl-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib-dir \

--with-freetype-dir \

--with-gettext \

--with-gmp \

--with-mhash \

--enable-json \

--enable-mbstring \

--enable-mbregex \

--enable-mbregex-backtrack \

--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 \

--enable-zip \

--enable-mysqlnd-compression-support \

--with-pear \

--enable-opcache

7、编译和安装

[root@localhost php-7.4.29]# make && make install

8、配置php-fpm

[root@localhost php-7.4.29]# cp php.ini-production /etc/php.ini

[root@localhost php-7.4.29]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@localhost php-7.4.29]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

[root@localhost php-7.4.29]# \cp sapi/fpm/php-fpm.service /usr/lib/systemd/system

9、创建配置文件

[root@localhost php-7.4.29]# vim /usr/local/php/etc/php-fpm.d/www.conf

[www]

listen = 0.0.0.0:9000

listen.mode = 0666

user = www

group = www

pm = dynamic

pm.max_children = 128

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 10000

rlimit_files = 1024

slowlog = log/$pool.log.slow

10、创建www用户,启动php-fpm

[root@localhost php-7.4.29]# useradd -s /sbin/nologin www >/dev/null 2>&1

11、配置开机自启动

[root@localhost php-7.4.29]# sed -i '/ProtectSystem/s/full/false/' /usr/lib/systemd/system/php-fpm.service

[root@localhost php-7.4.29]# systemctl daemon-reload

[root@localhost php-7.4.29]# systemctl enable php-fpm

12、启动php-fpm

[root@localhost php-7.4.29]# systemctl start php-fpm

13、查看php版本信息

[root@localhost php-7.4.29]# ln -sf /usr/local/php/bin/php /usr/bin/

[root@localhost php-7.4.29]# php -v

PHP 7.4.29 (cli) (built: Jul 6 2022 10:26:44) ( NTS )

Copyright (c) The PHP Group

Zend Engine v3.4.0, Copyright (c) Zend Technologies

# 至此就已经安装好php7.4.29了,希望可以帮助到大家。