Linux源码安装PHP 7.4.33

小柒助手 PHP评论876字数 1672阅读5分34秒阅读模式

一、PHP简介

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

PHP是免费的,并且使用非常广泛。同时,对于像微软ASP这样的竞争者来说,PHP无疑是另一种高效率的选项。
文章源自小柒网-https://www.yangxingzhen.cn/8912.html

二、Centos 7源码安装PHP 7.4.33

1、安装Libzip

下载地址:https://libzip.org/download/libzip-1.2.0.tar.gz
文章源自小柒网-https://www.yangxingzhen.cn/8912.html

1)安装依赖包
文章源自小柒网-https://www.yangxingzhen.cn/8912.html

[root@localhost ~]# yum -y install wget gcc gcc-c++ zlib-devel
文章源自小柒网-https://www.yangxingzhen.cn/8912.html

2)下载安装包
文章源自小柒网-https://www.yangxingzhen.cn/8912.html

[root@localhost ~]# wget https://libzip.org/download/libzip-1.2.0.tar.gz
文章源自小柒网-https://www.yangxingzhen.cn/8912.html

3)解压安装包
文章源自小柒网-https://www.yangxingzhen.cn/8912.html

[root@localhost ~]# tar xf libzip-1.2.0.tar.gz
文章源自小柒网-https://www.yangxingzhen.cn/8912.html

4)预编译
文章源自小柒网-https://www.yangxingzhen.cn/8912.html

[root@localhost ~]# cd libzip-1.2.0/
文章源自小柒网-https://www.yangxingzhen.cn/8912.html

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

5)编译和安装

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

6)配置动态库路径

[root@localhost libzip-1.2.0]# vim /etc/ld.so.conf

# 添加以下几行内容

/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64

[root@localhost libzip-1.2.0]# ldconfig -v

2、安装oniguruma

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

1)安装依赖包

[root@localhost libzip-1.2.0]# 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

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

5)编译和安装

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

3、安装PHP 7.4.33

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

1)下载php-7.4.33软件包

[root@localhost onig-6.9.7]# cd ~ && wget -c https://www.php.net/distributions/php-7.4.33.tar.gz

2)解压php-7.4.33软件包

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

3)进入php目录

[root@localhost ~]# cd php-7.4.33

4)安装epel-release源

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

5)安装依赖包

[root@localhost php-7.4.33]# 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 flex

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

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

[root@localhost php-7.4.33]# ./configure --prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-mysqlnd-compression-support \
--enable-inline-optimization \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-pdo \
--enable-fpm \
--enable-opcache \
--enable-bcmath \
--enable-calendar \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--enable-ftp \
--enable-gd \
--with-fpm-user=www \
--with-fpm-group=www \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-sqlite3 \
--with-iconv \
--with-bz2 \
--with-curl \
--with-cdb \
--with-zlib \
--with-gettext \
--with-gmp \
--with-mhash \
--with-jpeg \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-pdo-sqlite \
--with-readline \
--with-xsl

7)编译和安装

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

8)配置php-fpm

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

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

[root@localhost php-7.4.33]# 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.33]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system

9)创建配置文件

[root@localhost php-7.4.33]# 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.33]# useradd -s /sbin/nologin www

11)配置开机自启动

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

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

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

12)启动php-fpm

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

13)查看php版本信息

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

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

PHP 7.4.33 (cli) (built: Mar 27 2023 15:18:32) ( NTS )

Copyright (c) The PHP Group

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

14)常用基本操作

1、启动PHP

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

2、停止PHP

[root@localhost ~]# systemctl stop php-fpm

3、重载PHP

[root@localhost ~]# systemctl reload php-fpm

4、重启PHP

[root@localhost ~]# systemctl restart php-fpm

5、查询PHP运行状态

[root@localhost ~]# systemctl status php-fpm

6、查询PHP进程

[root@localhost ~]# ps -ef |grep php-fpm

7、查询PHP监听端口

[root@localhost ~]# netstat -lntup |grep php-fpm

三、Centos 6源码安装PHP 7.4.33

1、安装Libzip

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

1)安装依赖包

[root@localhost ~]# 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]# vim /etc/ld.so.conf

# 添加以下几行内容

/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64

[root@localhost libzip-1.2.0]# ldconfig -v

2、安装oniguruma

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

1)安装依赖包

[root@localhost libzip-1.2.0]# 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

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

5)编译和安装

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

3、安装PHP 7.4.33

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

1)下载php-7.4.33软件包

[root@localhost onig-6.9.7]# cd ~ && wget -c https://www.php.net/distributions/php-7.4.33.tar.gz

2)解压php-7.4.33软件包

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

3)进入php目录

[root@localhost ~]# cd php-7.4.33

4)安装epel-release源

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

5)安装依赖包

[root@localhost php-7.4.33]# 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 flex

6)升级sqlite

[root@localhost php-7.4.33]# yum -y install http://repo.okay.com.mx/centos/6/x86_64/release/okay-release-1-1.noarch.rpm

[root@localhost php-7.4.33]# yum -y install sqlite-devel

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

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

[root@localhost php-7.4.33]# ./configure --prefix=/usr/local/php \

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

--enable-mysqlnd-compression-support \

--enable-inline-optimization \

--enable-session \

--enable-shmop \

--enable-simplexml \

--enable-sockets \

--enable-sysvmsg \

--enable-sysvsem \

--enable-sysvshm \

--disable-debug \

--disable-rpath \

--enable-shared \

--enable-soap \

--enable-json \

--enable-mbregex \

--enable-pdo \

--enable-fpm \

--enable-opcache \

--enable-bcmath \

--enable-calendar \

--enable-dom \

--enable-exif \

--enable-fileinfo \

--enable-filter \

--enable-ftp \

--enable-gd \

--with-fpm-user=www \

--with-fpm-group=www \

--with-xmlrpc \

--with-openssl \

--with-mhash \

--with-sqlite3 \

--with-iconv \

--with-bz2 \

--with-curl \

--with-cdb \

--with-zlib \

--with-gettext \

--with-gmp \

--with-mhash \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-pdo-sqlite \

--with-readline \

--with-xsl

8)编译和安装

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


9)配置php-fpm

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

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

[root@localhost php-7.4.33]# 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.33]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@localhost php-7.4.33]# chmod +x /etc/init.d/php-fpm

10)创建配置文件

[root@localhost php-7.4.33]# 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

11)创建www用户用于启动php-fpm

[root@localhost php-7.4.33]# useradd -s /sbin/nologin www

12)配置开机自启动

[root@localhost php-7.4.33]# chkconfig --add php-fpm

[root@localhost php-7.4.33]# chkconfig php-fpm on

13)启动php-fpm

[root@localhost php-7.4.33]# /etc/init.d/php-fpm start

14)查看php版本信息

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

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

PHP 7.4.33 (cli) (built: Mar 27 2023 16:18:32) ( NTS )

Copyright (c) The PHP Group

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

15)常用基本操作

1、启动PHP

[root@localhost ~]# /etc/init.d/php-fpm start

2、停止PHP

[root@localhost ~]# /etc/init.d/php-fpm stop

3、重载PHP

[root@localhost ~]# systemctl reload php-fpm

4、重启PHP

[root@localhost ~]# /etc/init.d/php-fpm reload

5、查询PHP运行状态

[root@localhost ~]# /etc/init.d/php-fpm status

6、查询PHP进程

[root@localhost ~]# ps -ef |grep php-fpm

7、查询PHP监听端口

[root@localhost ~]# netstat -lntup |grep php-fpm

若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
历史上的今天
3 月
28
Wechat
微信扫一扫,加我!
weinxin
我的微信
微信号已复制
微信公众号
微信扫一扫,关注我!
weinxin
我的公众号
公众号已复制
PHP最后更新:2023-4-13
小柒助手
  • 本文由 小柒助手 发表于 2023年3月28日 11:28:53
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.cn/8912.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证