欧阳简之 > centos7.4 源码安装 PHP7.2

热爱代码,对每一行代码保持一颗敬畏之心。

安装环境:CentOS Linux release 7.4 (Core)

安装依赖

yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel

下载源码

cd /root/
wget http://am1.php.net/distributions/php-7.2.8.tar.gz
tar xvf php-7.2.8.tar.gz
cd php-7.2.8

cp -frp /usr/lib64/libldap* /usr/lib/

编译安装

./configure --prefix=/data/app/php \
    --with-config-file-path=/data/app/php/etc \
    --with-freetype-dir \
    --with-openssl \
    --enable-fpm \
    --with-fpm-user=nginx \
    --with-fpm-group=nginx \
    --enable-mysqlnd \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --enable-mbstring \
    --with-gd \
    --with-iconv \
    --with-zlib \
    --enable-xml \
    --enable-shmop \
    --enable-sysvsem \
    --enable-inline-optimization \
    --enable-mbregex \
    --enable-sockets \
    --enable-zip \
    --enable-soap \
    --with-gettext \
    --enable-session \
    --with-curl \
    --enable-opcache \
    --with-mhash \
    --enable-ftp \
    --with-jpeg-dir \
    --with-png-dir \
    --with-libxml-dir \
    --enable-bcmath \
    --enable-intl \
    --enable-pcntl \
    --with-xmlrpc \
    --enable-exif

make -j 4 && make install

附:PHP核心配置选项

配置

添加nginx用户

groupadd -r nginx
useradd -r -g nginx nginx
chown -R nginx.nginx /data/app/php

复制配置文件

cp php.ini-development /data/app/php/etc/php.ini
cp /data/app/php/etc/php-fpm.conf.default /data/app/php/etc/php-fpm.conf
cp /data/app/php/etc/php-fpm.d/www.conf.default /data/app/php/etc/php-fpm.d/www.conf

配置php.ini

vi /data/app/php/etc/php.ini
expose_php = Off
short_open_tag = ON
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 32M
date.timezone = Asia/Shanghai
disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru

配置php-fpm.conf

vi /data/app/php/etc/php-fpm.conf
pid = /data/app/php/var/run/php-fpm.pid

添加服务

cat > /usr/lib/systemd/system/php-fpm.service << EOF
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/data/app/php/var/run/php-fpm.pid
ExecStart=/data/app/php/sbin/php-fpm --nodaemonize --fpm-config /data/app/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target
EOF

完成

启动服务
systemctl start php-fpm.service
查看服务状态
systemctl status php-fpm.service 
设置开机启动
systemctl enable php-fpm.service
tagged by linux php