PHP编译安装
一、前言
(一)、概述
PHP(外文名:PHP:Hypertext Preprocessor,中文名:"超文本预处理器")是一种通用开源脚本语言,语法吸收了C语言、Java和Perl的特点;主要适用于Web开发领域;执行编译代码之后,可以达到加密和优化代码运行,使代码运行更快;
(二)、预处理
配置环境
OS:CentOS 7.5 64bit
PHP版本:7.2.8
hostname:php-1-1
ip:10.18.43.141
[root@php-1-1 ~]# systemctl stop firewalld
[root@php-1-1 ~]# sed -ri '/^SELINUX=*/cSELINUX=disabled' /etc/selinux/config
[root@php-1-1 ~]# setenforce 0
[root@php-1-1 ~]# mkdir -p /date/php
二、安装
(一)、PHP编译
依赖环境库下载
[root@php-1-1 ~]# yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libxslt libxslt-devel
源码包获取及编译
[root@php-1-1 ~]# wget -P /data/php/ http://cn2.php.net/distributions/php-7.2.8.tar.bz2 [root@php-1-1 ~]# cd /data/php/ [root@php-1-1 php]# tar xf php-7.2.8.tar.bz2
[root@php-1-1 php]# cd php-7.2.8/
[root@php-1-1 php-7.2.8]#./configure \
--prefix=/usr/local/php \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-ldap \
--with-gettext \
--with-iconv-dir \
--with-jpeg-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-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip \
--with-fpm-group=nginx \
--with-fpm-user=nginx
执行编译
make -j 2 && make install
三、配置启动
(一)、基础配置
[root@php-1-1 php-7.2.8]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
[root@php-1-1 php-7.2.8]# cp /usr/local/php/etc/{php-fpm.conf.default,php-fpm.conf}
[root@php-1-1 php-7.2.8]# cp /usr/local/php/etc/php-fpm.d/www.conf{.default,}
[root@php-1-1 php-7.2.8]# cp php.ini-production /usr/local/php/lib/php.ini
(二)、参数配置
[root@php-1-1 php-7.2.8]# sed -i '/date.timezone =/s/.*/date.timezone = PRC/g' /usr/local/php/lib/php.ini
[root@php-1-1 php-7.2.8]# sed -n '869p' /usr/local/php/lib/php.ini
[root@php-1-1 php-7.2.8]# sed -i '/opcache]/azend_extension=opcache.so' /usr/local/php/lib/php.ini
[root@php-1-1 php-7.2.8]# sed -i '/;opcache.enable=1/s/;//g' /usr/local/php/lib/php.ini
[root@php-1-1 php-7.2.8]# sed -i '/opcache.enable_cli=/s/.*/opcache.enable_cli=1/g' /usr/local/php/lib/php.ini
[root@php-1-1 php-7.2.8]# echo "vm.nr_hugepages = 200" >> /etc/sysctl.conf
[root@php-1-1 php-7.2.8]# sysctl -p
[root@php-1-1 php-7.2.8]# sed -i '/;opcache.huge_code_pages/s/;//g' /usr/local/php/lib/php.ini
[root@php-1-1 php-7.2.8]# sed -i '/opcache.memory_consumption=/s/.*/opcache.memory_consumption=512/g' /usr/local/php/lib/php.ini
[root@php-1-1 php-7.2.8]# sed -i '/opcache.fast_shutdown=/s/.*/opcache.fast_shutdown=1/g' /usr/local/php/lib/php.ini
[root@php-1-1 php-7.2.8]# sed -i '/opcache.validate_timestamps=/s/.*/opcache.validate_timestamps=1/g' /usr/local/php/lib/php.ini
[root@php-1-1 php-7.2.8]# sed -i '/opcache.revalidate_freq=/s/.*/opcache.revalidate_freq=2/g' /usr/local/php/lib/php.ini
[root@php-1-1 php-7.2.8]# sed -i '/listen = 127.0.0.1/s/=.*/= 0.0.0.0:9000/g' /usr/local/php/etc/php-fpm.d/www.conf
此段可以编写为脚本
#!/bin/sh sed -i '/date.timezone =/s/.*/date.timezone = PRC/g' /usr/local/php/lib/php.ini sed -n '869p' /usr/local/php/lib/php.ini sed -i '/opcache]/azend_extension=opcache.so' /usr/local/php/lib/php.ini sed -i '/;opcache.enable=1/s/;//g' /usr/local/php/lib/php.ini sed -i '/opcache.enable_cli=/s/.*/opcache.enable_cli=1/g' /usr/local/php/lib/php.ini echo "vm.nr_hugepages = 200" >> /etc/sysctl.conf sysctl -p sed -i '/;opcache.huge_code_pages/s/;//g' /usr/local/php/lib/php.ini sed -i '/opcache.memory_consumption=/s/.*/opcache.memory_consumption=512/g' /usr/local/php/lib/php.ini sed -i '/opcache.fast_shutdown=/s/.*/opcache.fast_shutdown=1/g' /usr/local/php/lib/php.ini sed -i '/opcache.validate_timestamps=/s/.*/opcache.validate_timestamps=1/g' /usr/local/php/lib/php.ini sed -i '/opcache.revalidate_freq=/s/.*/opcache.revalidate_freq=2/g' /usr/local/php/lib/php.ini sed -i '/listen = 127.0.0.1/s/=.*/= 0.0.0.0:9000/g' /usr/local/php/etc/php-fpm.d/www.conf
(三)、启动使用
[root@php-1-1 php-7.2.8]# systemctl start php-fpm.service
[root@php-1-1 php-7.2.8]# systemctl enable php-fpm.service
您的资助是我最大的动力!
金额随意,欢迎来赏!