centos7源码编译php7.2.5

  • by
  • 6 评论

centos7源码编译php7.2.5,php7性能提高很多,建议安装php7最新稳定版。

一、在php官网www.php.net下载最新稳定版。

二、php7.2源码编译依赖包安装。

yum -y install make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs

autoconf\kernel-devel libjpeg libjpeg-devel libpng

yum install -y gd gd-devel freetype freetype-devel libxml* libxml2-devel zlib

zlib-devel

yum install -y glib2 glib2-devel bzip2 bzip2-devel libevent* libevent-devel

ncurses ncurses-devel

yum install -y curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel

libidn libidn-devel

yum install -y openssl openssl-devel gettext gettext-devel ncurses-devel

gmp-devel pspell-devel

yum install -y unzip libcap lsof libpng-devel libpng10 libpng10-devel

yum install  -y gdbm-devel  openldap openldap-devel

yum -y   install libxslt libxslt-devel

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

php7.2源码编译依赖包yum安装完毕。

三、添加用户、编译安装

groupadd -r nginx

useradd -r nginx -g nginx -s /sbin/nologin

tar xf  php-7.2.5.tar.gz

./configure \–prefix=/usr/local/php7 \–exec-prefix=/usr/local/php7 \–bindir=

/usr/local/php7/bin \–sbindir=/usr/local/php7/sbin \–includedir=/usr/local

/php7/include \–libdir=/usr/local/php7/lib/php \–mandir=/usr/local/

php7/php/man \–with-config-file-path=/usr/local/php7/etc \–with-mysql-

sock=/var/run/mysql/mysql.sock \-with-libxml-dir=/usr   \–with-iconv-dir  \–

with-mhash \–with-openssl \–with-mysqli=shared,mysqlnd \–with-pdo-

mysql=shared,mysqlnd \–with-gd \–with-iconv \–with-zlib \–enable-zip \–

with-ldap=shared  \–with-ldap-sasl  \–enable-inline-optimization \–disable-

debug \–disable-rpath \–enable-shared \–enable-xml \–enable-bcmath \–

enable-shmop \–enable-sysvsem \–enable-mbregex \–enable-mbstring \–

enable-ftp \–enable-pcntl \–enable-sockets \–with-xmlrpc \–enable-soap \–

without-pear \–with-gettext \–enable-session \–with-curl \–with-jpeg-dir \–

with-freetype-dir \–enable-opcache \–enable-fpm \–with-fpm-user=nginx \–

with-fpm-group=nginx \–with-gdbm \–enable-fileinfo  \–with-xsl –enable-

exif

根据具体情况修改安装目录以及mysql目录,就可以开始编译安装php7.2.5了。

make && make install

php7.2.5源码编译完成后,查看安装目录如下:

ll  /usr/local/php7/lib/php/extensions/no-debug-non-zts-20170718/

复制配置文件:

mv /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-

fpm.conf

cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-

fpm.d/www.conf 

cp php.ini-production  /usr/local/php7/etc/php.ini  

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm  #复制php-fpm启动脚本到

init.d

chmod +x /etc/init.d/php-fpm    #赋予执行权限

生产环境用这个:cp php.ini-production     /usr/local/php7/etc/php.ini

直接使用编译后未经优化处理的配置

开发环境用这个:cp php.ini-development   /usr/local/php7/etc/php.ini

开机启动脚本

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

设置全局的php命令

vim /etc/profile

在文件最后添加:export PATH=$PATH:/usr/local/php7/bin

source  /etc/profile

修改配置文件 vim /usr/local/php7/etc/php.ini

######避免PHP信息暴露在http头中

expose_php = Off

######避免暴露php调用mysql的错误信息

display_errors = Off

######在关闭display_errors后开启PHP错误日志(路径在php-fpm.conf中配置)

log_errors = On

######设置PHP的扩展库路径extension_dir = “/usr/local/php7/lib/php/extensions/no-debug-non-zts-20170718/”

######设置PHP的opcache和mysql动态库

zend_extension=opcache.so

extension=mysqli.so

extension=pdo_mysql.so

extension=ldap.so

######设置PHP的时区

date.timezone = PRC

######开启opcache

[opcache]

opcache.enable=1

######设置PHP脚本允许访问的目录(需要根据实际情况配置)

open_basedir = /etc/nginx/html;

开机启动PHP7

chkconfig php-fpm on

service php-fpm start


《centos7源码编译php7.2.5》有6个想法

  1. Greate pieces. Keep writing such kind of information on your blog.
    Im really impressed by your blog.
    Hi there, You have done an excellent job. I will definitely digg it and in my opinion suggest to my
    friends. I am sure they’ll be benefited from this site.

发表评论

电子邮件地址不会被公开。 必填项已用*标注

15 − 8 =