php7.2源码编译安装

.环境配置
安装前的环境准备:
##安装make,已安装,可省略
yum -y install gcc automake autoconf libtool make
##安装gcc g++ glibc库
yum -y install gcc gcc-c++ glibc
##安装所需的包
yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap-devel
2.php安装
下载源码编译安装
#下载源码
wget http://am1.php.net/distributions/php-7.2.2.tar.gz
##解压
tar -zxvf php-7.2.2.tar.gz
##创建安装目录
mkdir php7
mv php-7.2.2 php7
cd php7/php-7.2.2/
## 编译前配置
./configure --prefix=/app/php --with-config-file-path=/app/php/etc --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-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 \
--with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex \
--enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm \
--enable-xml --enable-zip --with-ldap
 
##编译时间略长,耐心等待
make -j 4
##安装
make install
3.配置php相关文件
##php.ini,编译配置时配在php7/etc目录下
cp php-7.2.2/php.ini-development ../etc/php.ini
##php-fpm.conf
cp ../etc/php-fpm.conf.default ../etc/php-fpm.conf

##www.conf
cp ../etc/php-fpm.d/www.conf.default ../etc/php-fpm.d/www.conf
修改配置
php.ini
原cgi.force_redirect = 1被注释,需要放开且修改为cgi.force_redirect = 0
php-fpm.conf
修改错误日志路径error_log = log/php-fpm.log
www.conf
修改用户和用户组选项user = nginx、group = nginx
4.#设置php环境变量
vim /etc/profile
##加上下面这句话
export PATH=/app/php/bin:/app/php/sbin:$PATH
source /etc/profile
php -v
#返回结果如下
PHP 7.2.2 (cli) (built: Feb 10 2018 16:13:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

启动php
/home/test/php7/sbin/php-fpm
##检查进程是否启动
ps -ef | grep php
root     41963     1  0 18:04 ?        00:00:00 php-fpm: master process (/home/test/php7/etc/php-fpm.conf)
nginx    41964 41963  0 18:04 ?        00:00:00 php-fpm: pool www
nginx    41965 41963  0 18:04 ?        00:00:00 php-fpm: pool www
##检查端口9000是否活着
netstat -anp | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      41963/php-fpm: mast
5.修改nginx配置
Nginx安装参考:Nginx源码安装
找到nginx配置nginx.conf,修改如下,修改后重启nginx:
server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
    
        location / {
            root   html;
            ##添加index.php
            index  index.php index.html index.htm;
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

         ##注意这里有关php的location注释要放开
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            ##注意脚本目录路径使用绝对路径更清晰
            fastcgi_param  SCRIPT_FILENAME  /home/test/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }

    }
6.测试
在nginx/html目录下建文件index.php,文件内容如下
<?php
    phpinfo();
?>

YYQ运维技术博客_运维的工作学习之路
飞翔沫沫情博客_一只运维狗的升级打怪之旅
https://www.yeyouqing.top
https://yeyouqing.top
yeyouqing.top
www.yeyouqing.top

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值