CentOS7搭建LNMP--安装PHP7.2

下载PHP安装包

现在最新的PHP版本是8.0,但是如果想要下载之前的版本的话,要在官网的PHP博物馆里面找,网址是这个:https://museum.php.net/

下载PHP7.2.31

[root@ceshi ~]# wget https://museum.php.net/php7/php-7.2.31.tar.gz
[root@ceshi ~]# ls
php-7.2.31.tar.gz

安装依赖

[root@ceshi ~]# yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel

解压安装包,编写配置文件并安装

#解压安装包
[root@ceshi ~]# tar -xzf php-7.2.31.tar.gz 
[root@ceshi ~]# ls
php-7.2.31  php-7.2.31.tar.gz
[root@ceshi ~]# cd php-7.2.31

#编写配置文件
[root@ceshi php-7.2.31]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl

Generating files

configure: creating ./config.status

creating main/internal_functions.c

creating main/internal_functions_cli.c

+--------------------------------------------------------------------+

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

配置成功,现在开始安装(安装时间可能会比较长)

[root@ceshi ~]# make && make install

php-fpm的配置文件

/usr/local/php下的etc目录,是专门用于存放php-fpm启动或运行的配置文件的。

  1. php.ini                  #默认php配置文件(/root/php-7.2.31)php.ini文件负责开启PHP以后的所有扩展
  2. php-fpm.conf     #php-fpm相关配置(默认已存在)
  3. www.conf           #php-fpm主配置文件(默认已存在)

把php.ini移动到/usr/local/php/etc目录中

[root@ceshi local]# cp /root/php-7.2.31/php.ini-development /usr/local/php/etc/php.ini

加载php-fpm.conf主配置文件

[root@ceshi local]# cd php/etc
[root@ceshi etc]# pwd
/usr/local/php/etc


[root@ceshi etc]# cp php-fpm.conf.default php-fpm.conf
[root@ceshi etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d  php.ini

加载php-fpm子配置文件www.conf文件

[root@ceshi etc]# cp php-fpm.d/www.conf.default php-fpm.d/www.conf

添加php-fpm启动项

#把php-fpm添加到/etc/init.d目录下
[root@ceshi ~]# cp /root/php-7.2.31/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

#赋予该文件执行权限
[root@ceshi ~]# chmod +x /etc/init.d/php-fpm 

#启动php-fpm
[root@ceshi ~]# service php-fpm start
Starting php-fpm  done

#查看9000端口占用情况(Nginx中的PHP是以独立进程的方式运行,占用计算机的9000端口)
[root@ceshi ~]# netstat -naltp |grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      9220/php-fpm: maste 

#把php的bin目录添加到环境变量
[root@ceshi php]# echo 'export PATH=$PATH:/usr/local/php/bin' >> /etc/profile
[root@ceshi php]# source /etc/profile

#查看环境变量是否添加成功
[root@ceshi php]# cat /etc/profile|grep $PATH

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值