centos7环境php7安装

本文详细记录了从下载到成功安装配置PHP7.2的全过程,包括解决libxml2、OpenSSL、cURL、libxslt等依赖库缺失问题,以及Nginx配置以支持PHP。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载
链接:https://pan.baidu.com/s/1kVENjV7Z7SJOYm0-OhodUA
提取码:e167

安装操作指令

## 文件目录,个人喜好选择
[root@iZm5eealoheq9oyr6fvfk6Z src] cd /usr/local/src/
## 解压
[root@iZm5eealoheq9oyr6fvfk6Z src] tar -zxvf mirror
## 进入
[root@iZm5eealoheq9oyr6fvfk6Z src] cd php-7.2.10/
## 配置
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] ./configure --prefix=/usr/local/php  --with-curl  --with-freetype-dir  --with-gd  --with-gettext  --with-iconv-dir  --with-kerberos  --with-libdir=lib64  --with-libxml-dir  --with-mysqli  --with-openssl  --with-pcre-regex  --with-pdo-mysql  --with-pdo-sqlite  --with-pear  --with-png-dir  --with-xmlrpc  --with-xsl  --with-zlib  --enable-fpm  --enable-bcmath  --enable-libxml  --enable-inline-optimization  --enable-gd-native-ttf  --enable-mbregex  --enable-mbstring  --enable-opcache  --enable-pcntl  --enable-shmop  --enable-soap  --enable-sockets  --enable-sysvsem  --enable-xml  --enable-zip
## 遇到错误如下:
configure: error: libxml2 not found. Please check your libxml2 installation.
## 缺少libxml2,所以安装libxml2, 由于libxml2安装需要一些依赖库,所以如下一并安装
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel
...
Complete! // 
## 然后继续执行之前的配置命令
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] ./configure --prefix=/usr/local/php  --with-curl  --with-freetype-dir  --with-gd  --with-gettext  --with-iconv-dir  --with-kerberos  --with-libdir=lib64  --with-libxml-dir  --with-mysqli  --with-openssl  --with-pcre-regex  --with-pdo-mysql  --with-pdo-sqlite  --with-pear  --with-png-dir  --with-xmlrpc  --with-xsl  --with-zlib  --enable-fpm  --enable-bcmath  --enable-libxml  --enable-inline-optimization  --enable-gd-native-ttf  --enable-mbregex  --enable-mbstring  --enable-opcache  --enable-pcntl  --enable-shmop  --enable-soap  --enable-sockets  --enable-sysvsem  --enable-xml  --enable-zip
## 然后又遇到错误如下:
configure: error: Cannot find OpenSSL's <evp.h>
### 缺少OpenSSL,所以安装OpenSSL
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] yum install openssl openssl-devel
...
Complete! // 
## 然后继续
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] ./configure --prefix=/usr/local/php  --with-curl  --with-freetype-dir  --with-gd  --with-gettext  --with-iconv-dir  --with-kerberos  --with-libdir=lib64  --with-libxml-dir  --with-mysqli  --with-openssl  --with-pcre-regex  --with-pdo-mysql  --with-pdo-sqlite  --with-pear  --with-png-dir  --with-xmlrpc  --with-xsl  --with-zlib  --enable-fpm  --enable-bcmath  --enable-libxml  --enable-inline-optimization  --enable-gd-native-ttf  --enable-mbregex  --enable-mbstring  --enable-opcache  --enable-pcntl  --enable-shmop  --enable-soap  --enable-sockets  --enable-sysvsem  --enable-xml  --enable-zip
## 然后又遇到错误如下:
checking for cURL 7.10.5 or greater... configure: error: cURL version 7.10.5 or later is required to compile php with cURL support
## 安装curl-devel
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] yum -y install curl-devel
...
Complete!
## 然后继续
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] ./configure --prefix=/usr/local/php  --with-curl  --with-freetype-dir  --with-gd  --with-gettext  --with-iconv-dir  --with-kerberos  --with-libdir=lib64  --with-libxml-dir  --with-mysqli  --with-openssl  --with-pcre-regex  --with-pdo-mysql  --with-pdo-sqlite  --with-pear  --with-png-dir  --with-xmlrpc  --with-xsl  --with-zlib  --enable-fpm  --enable-bcmath  --enable-libxml  --enable-inline-optimization  --enable-gd-native-ttf  --enable-mbregex  --enable-mbstring  --enable-opcache  --enable-pcntl  --enable-shmop  --enable-soap  --enable-sockets  --enable-sysvsem  --enable-xml  --enable-zip
## 然后又遇到错误如下:
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
## 安装libxslt-devel
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] yum -y install libxslt libxslt-devel
...
Complete!
## 然后继续
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] ./configure --prefix=/usr/local/php  --with-curl  --with-freetype-dir  --with-gd  --with-gettext  --with-iconv-dir  --with-kerberos  --with-libdir=lib64  --with-libxml-dir  --with-mysqli  --with-openssl  --with-pcre-regex  --with-pdo-mysql  --with-pdo-sqlite  --with-pear  --with-png-dir  --with-xmlrpc  --with-xsl  --with-zlib  --enable-fpm  --enable-bcmath  --enable-libxml  --enable-inline-optimization  --enable-gd-native-ttf  --enable-mbregex  --enable-mbstring  --enable-opcache  --enable-pcntl  --enable-shmop  --enable-soap  --enable-sockets  --enable-sysvsem  --enable-xml  --enable-zip
## 编译配置完成(终于好了),接着开始编译安装
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] make && make install
## 配置PHP
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] cp php.ini-development /usr/local/php/lib/php.ini
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
## 启动
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] /etc/init.d/php-fpm
## 确认一下是否进程启动
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] ps -ef|grep php
root     19116     1  0 19:29 ?        00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody   19117 19116  0 19:29 ?        00:00:00 php-fpm: pool www
nobody   19118 19116  0 19:29 ?        00:00:00 php-fpm: pool www
root     19120 30461  0 19:29 pts/1    00:00:00 grep --color=auto php
## PHP安装完成

Nginx配置

## 修改nginx配置
[root@iZm5eealoheq9oyr6fvfk6Z php-7.2.10] vim /usr/local/nginxconf/nginx.conf
## 找到server项, 新增如下配置
location ~ \.php?.*$ {
   root           html;
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
   include        fastcgi_params;
}
## 测试配置
[root@iZm5eealoheq9oyr6fvfk6Z sbin] ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
## 重启Nginx
[root@iZm5eealoheq9oyr6fvfk6Z sbin] ./nginx -s reload
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值