热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CentOS8.4安装PHP7.4.25

1、下载官网:https:www.php.netdownloads#cdmydata#wgethttps:www.php.netdistributionsphp

1、下载

官网:https://www.php.net/downloads

# cd /mydata/
# wget https://www.php.net/distributions/php-7.4.25.tar.xz

2、解压

# cd /mydata/
# .tar.xz格式
# xz -dev php-7.4.25.tar.xz
# tar -xvf php-7.4.25.tar# 如果是.tar.gz格式
# tar -zxvf php-7.4.25.tar.gz

3、安装依赖

# yum -y install libzip-devel 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 krb5-devel sqlite-devel

4、安装

注意几个重点配置项:
--prefix=/usr/local/php7      //定义PHP安装目录
-with-config-file-path= /usr/local/php7/etc   //指定php.ini文件的放置路径,也可以是/etc目录下
--enable-fpm     //开启php-fpm    必须,
--with-fpm-user=www                  注意与你的nginx用户保持一致
--with-fpm-group=www                注意与你的nginx用户组保持一致
--disable-fileinfo        //当服务器内存为1G时,此项很有必要

# cd /mydata/php-7.4.24/
# ./configure --prefix=/usr/local/php7 --with-fpm-user=www --with-fpm-group=www --with-config-file-path=/usr/local/php7/etc --with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-iconv-dir=/usr/local --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-mhash --with-ldap-sasl --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-xml --with-zip --with-bz2 --enable-inline-optimization --enable-sysvsem

4-1、报错oniguruma的处理

# 报错如下:
configure: error: Package requirements (oniguruma) were not met:
Package 'oniguruma', required by 'virtual:world', not found

需要安装“” 扩展 ,可以去 https://pkgs.org/  里搜索 ,也可以使用
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz 进行下载

下载后,

# tar -zxvf oniguruma-6.9.4.tar.gz
# cd oniguruma-6.9.4/
# yum -y install autoconf automake libtool 先安装这几个命令
# ./autogen.sh
# ./configure --prefix=/usr --libdir=/lib64 //64位的系统一定要标识 --libdir=/lib64 否则还是不行
# make
# make install

然后再次执行 PHP的编译 # ./configure ....
最后出现:

+--------------------------------------------------------------------+
| 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.

继续

# make
大约20分钟 出现
...
clicommand.inc
pharcommand.inc
directorygraphiterator.inc
phar.inc
Build complete.
Don't forget to run 'make test'.OK 继续
# make install

如果 make 没有成功,而是出现了如:报错collect2: error: ld returned 1 exit status 
make: *** [sapi/cli/php] Error 1
collect2: error: ld returned 1 exit status
make: *** [Makefile:290: sapi/cli/php] Error 1
解决
vim Makefile
大约 113行 ,找到 EXTRA_LIBS  最后加上 -liconv   (有的是 -llber 根据实际情况)然后 #  make clean   再执行 make  即可。

 make install 最后出现

[root@qinser php-7.4.25]# make install
Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/
Installing PHP CLI binary: /usr/local/php7/bin/
Installing PHP CLI man page: /usr/local/php7/php/man/man1/
Installing PHP FPM binary: /usr/local/php7/sbin/
Installing PHP FPM defconfig: /usr/local/php7/etc/
Installing PHP FPM man page: /usr/local/php7/php/man/man8/
Installing PHP FPM status page: /usr/local/php7/php/php/fpm/
Installing phpdbg binary: /usr/local/php7/bin/
Installing phpdbg man page: /usr/local/php7/php/man/man1/
Installing PHP CGI binary: /usr/local/php7/bin/
Installing PHP CGI man page: /usr/local/php7/php/man/man1/
Installing build environment: /usr/local/php7/lib/php/build/
Installing header files: /usr/local/php7/include/php/
Installing helper programs: /usr/local/php7/bin/program: phpizeprogram: php-config
Installing man pages: /usr/local/php7/php/man/man1/page: phpize.1page: php-config.1
Installing PEAR environment: /usr/local/php7/lib/php/
[PEAR] Archive_Tar - installed: 1.4.14
[PEAR] Console_Getopt - installed: 1.4.3
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.5
warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.4.14 is not the recommended version 1.4.4
[PEAR] PEAR - installed: 1.10.13
Wrote PEAR system config file at: /usr/local/php7/etc/pear.conf
You may want to add: /usr/local/php7/lib/php to your php.ini include_path
/mydata/php-7.4.25/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin/phar.phar
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers: /usr/local/php7/include/php/ext/pdo/

OK 安装成功


5、创建php环境变量

# vim /etc/profile
# 把这一行“/usr/local/php7/bin”追加到之前配置的mysql配置后,用英文冒号隔开
# 如: export PATH="$PATH:/usr/local/mysql8/bin:/usr/local/php7/bin"# source /etc/profile 使配置立即生效
# php -v 查看PHP版本

6、设置启动文件并开机自动启动

1、生成php配置文件php.ini
# cd /mydata/php-7.4.25/
# cp php.ini-production /usr/local/php7/etc/php.ini2、生成www配置文件
# cd /usr/local/php7/etc/php-fpm.d/
# cp www.conf.default www.conf3、生成php-fpm配置文件
# cd /usr/local/php7/etc
# cp php-fpm.conf.default php-fpm.conf4 生成php-fpm服务启动文件
# cp /mydata/php-7.4.25/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //设置PHP启动文件
# chmod +x /etc/init.d/php-fpm //为其添加可执行权限5、添加到环境系统启动项
# chkconfig --add php-fpm //添加到开机重启
# chkconfig php-fpm on //启动php-fpm6、查看是否添加成功
# chkconfig --list
......
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off --- php-fpm 添加成功7、启动 php-fpm
# /etc/init.d/php-fpm start
出现 Starting php-fpm done OK 启动成功
# /etc/init.d/php-fpm status
php-fpm (pid 2306) is running... 检测开机自启动是否设置成功?
# shutdown -r now 重启服务器
# netstat -ntlp
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 156525/php-fpm: mas
出现了9000端口号说明可以开机自启动了

7、配置nginx支持php

# vim /usr/local/nginx/conf/nginx.conf 大约45行起

修改内容下图:

然后释放如下图

在 /usr/local/nginx/html/目录创建 index.php 文件

# 重启nginx
# systemctl restart nginx.service

 再次访问站点:

OK ,nginx站点支持PHP了


 附录:PHP重要文件目录 和常用命令

/usr/local/php7/ 安装目录
/usr/local/php7/bin/ 可执行目录, php 环境变量位于此目录
/usr/local/php7/bin/phpize 可执行目录
/usr/local/php7/etc/php.ini PHP配置文件
/etc/init.d/php-fpm php-fpm启动文件/etc/init.d/php-fpm start 开启服务
/etc/init.d/php-fpm stop 停止服务
/etc/init.d/php-fpm status 查看状态
/etc/init.d/php-fpm restart 重启服务
/etc/init.d/php-fpm reload 平滑重启加入系统服务以后可以使用
service php-fpm start/stop/status/restart/reload


推荐阅读
author-avatar
手机用户2502936007
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有