去官网下载php7.2安装包,选择一个结点下载:
http://php.net/downloads.php

下载:
wget -ivh http://cn.php.net/distributions/php-7.2.12.tar.gz
解压源码包:
tar -zxf php-7.2.12.tar.gz

安装编译php需要的依赖包:
yum install gcc autoconf gcc-c++
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
yum install systemd-devel
yum install openjpeg-devel

添加www用户:
创建群组:groupadd www
创建一个用户,不允许登陆和不创主目录:useradd -s /sbin/nologin -g www -M www

编译参数:

开发环境:
    --enable-phpdbg\
    --enable-dtrace\
生产环境:
    --disable-phpdbg\
    --disable-dtrace\

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--with-gd \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--disable-fileinfo

执行编译:
make && make install

php-ini:
源码包里面有配置文件:
    php.ini-development     测试开发环境
    php.ini-production         生产环境

复制一份到指定的目录下(根据自己的情况选用,自己可以对比下这两个文件的差异):
cp php.ini-production /usr/local/php/etc/php.ini

php-fpm复制一份新的php-fpm配置文件: 
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf

配置错误日志:error_log = /usr/local/php/var/php-fpm.log
配置pid文件:pid = /usr/local/php/var/run/php-fpm.pid
保存退出
cd /usr/local/php/etc/php-fpm.d
cp www.conf.default  www.conf

管理php-fpm配置:

cd /usr/local/src/php-7.2.4
cp ./sapi/fpm/php-fpm.service 到 /usr/lib/systemd/system/下

也执行以下命令启动php-fpm服务:
cp sapi/fpm/php-fpm.service /usr/local/php/bin/
/usr/local/bin/php-fpm
启动完毕之后,php-fpm服务默认使用9000端口,使用 netstat -tln | grep 9000 可以查看端口使用情况:

配置开机启动php-fpm:
systemctl enable php-fpm

启动php-fpm:
systemctl start php-fpm

查看状态:
systemctl status php-fpm

添加环境变量:
vim  /etc/profile

在末尾追加:
export PATH=$PATH:'/usr/local/php/bin/'

保存退出。
source /etc/profile

测试:
php -v

看到php版本信息就表示已经成功了。

如果需要区分web和cli环境,可以将 /usr/local/php/etc/php.ini 复制一份,重命名为php-cli.ini

cp /usr/local/php/etc/php.ini  /usr/local/php/etc/php-cli.ini

需要调整配置,就在各自的配置文件中进行调整即可。

设置nginx
nginx配置:
server {
listen 80;
server_name www.demo.com;

#charset koi8-r;
access_log /var/logs/nginx/access.log main;
error_log /var/logs/nginx/error.log;

root /wwwroot;
location / {
index index.php;
try_files $uri /index.php?_RW_=$uri;
}

#error_page 404 /404.html;

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

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# 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 /wwwroot$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

修改完这些保存并退出,然后重启nginx:
/usr/local/nginx/nginx -s stop
/usr/local/nginx/nginx
或者
/usr/local/nginx/nginx -s reload

访问网站,如果能正常打开页面,就证明设置成功了,有些时候会遇到一些权限问题,比如我就遇到了缓存目录没有写权限,chmod 755 cache修改目录的权限,然后程序就能正常运行了。

done!

centos7编译安装php7.2的更多相关文章

  1. Centos7 编译安装PHP7

    Centos7 编译安装PHP7 编译安装的方式可以让组件等设置更加合理,但需要你对PHP的代码及各种配置非常的熟悉,以下为大致的安装流程,大家可以参考 1.下载编译工具 yum groupinsta ...

  2. CentOS7编译安装php7.1配置教程详解

    这篇文章主要介绍CentOS7编译安装php7.1的过程和配置详解,亲测 ,需要的朋友可以参考. 1.首先安装依赖包: yum install libxml2 libxml2-devel openss ...

  3. CentOS7 编译安装 php7

    更新:2019-01-25 补充:CentOS 7.5 全新编译安装 PHP-7.3.1 ,补充内容接在原文之后 更新:2018-09-29 补充:新系统下编译安装PHP-7.2.5遇到的问题,补充内 ...

  4. CentOS7编译安装php7.1

    1.首先安装依赖包: yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl ...

  5. centos7 编译安装 php7.3.11

    1.安装依赖 yum install -y libxml2 *openssl* libcurl* libjpeg* libpng* freetype* libmcrypt* gcc gcc-c++ 2 ...

  6. centos7 编译安装 php7.4

    1. 下载安装编译工具 yum groupinstall 'Development Tools' 2.安装依赖包 yum install libxml2 libxml2-devel openssl o ...

  7. centos7编译安装PHP7已经把你逼到去安定医院看门诊的地步?请看此文

    本文援引自https://www.cnblogs.com/lamp01/p/10101659.html,亲测可行,特此鸣谢 地球上总有一群人是如此深爱PHP,但无奈的是编译安装的过程化特性,导致各种b ...

  8. CentOs7 编译安装PHP7.1.5

    1 创建php用户和用户组,并在github下载php7源码 #######新建php用户和php组 [root@typecodes ~]# groupadd -r www && us ...

  9. Centos7 编译安装PHP7.2

    yum install wget 在 /usr/local/src 目录下载php源码包 wget http://cn2.php.net/distributions/php-7.2.4.tar.gz ...

随机推荐

  1. python基础初识介绍以及安装

    python介绍 Python的创始人为Guido van Rossum.1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心开发一个新的脚本解释程序,做为ABC 语言的一种继承. ...

  2. Spring学习六(事物管理)

    参考链接 http://www.mamicode.com/info-detail-1248286.html http://www.cnblogs.com/wangdaqian/archive/2017 ...

  3. L248 词汇题 2006

    The audience, hostile at first, were greatly impressed by her excellent performance. He wanted to st ...

  4. 在线播放Video/PDF/JPG

    Label1.Text = Play(url, , ); public string Play(string url, int width, int height) { string strTmp = ...

  5. python day02作业

  6. 自动化测试-22.RobotFrameWork鼠标和键盘的操作针对出现window界面的处理

    键盘和鼠标的操作:使用AutoItLibrary模块 1.安装pywin32 http://sourceforge.net/projects/pywin32/files/pywin32/Build%2 ...

  7. 河南省第四届ACM省赛(T3) 表达式求值

    表达式求值 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Dr.Kong设计的机器人卡多掌握了加减法运算以后,最近又学会了一些简单的函数求值,比如,它知道函数min ...

  8. systemd设置静态IP

    /********************************************************************************* * systemd设置静态IP * ...

  9. 【重要】NOI-1.2-10-字符串大小

    10:Hello, World!的大小 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 还记得在上一章里,我们曾经输出过的“Hello, World!”吗? ...

  10. ZOJ 1006:Do the Untwist(模拟)

    Do the Untwist Time Limit: 2 Seconds      Memory Limit: 65536 KB Cryptography deals with methods of ...