美文网首页
CentOS下,编译安装php 7.1.x

CentOS下,编译安装php 7.1.x

作者: 雾风 | 来源:发表于2017-12-02 14:32 被阅读0次
    一,准备篇
    1,安装nginx

    安装nginx

    2,升级软件
    yum -y update
    
    3,安装依赖
    yum -y install wget gcc gcc-c++ make autoconf pcre pcre-devel openssl openssl-devel zlib zlib-devel libxml2 libxml2-devel curl libcurl libcurl-devel libwebp libwebp-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel libXpm libXpm-devel freetype freetype-devel gd gd-devel
    
    二、安装篇
    1,下载php源码
    cd /usr/local/src && wget http://cn2.php.net/distributions/php-7.1.12.tar.gz && tar zxvf php-7.1.12.tar.gz && cd php-7.1.12
    
    2,生成编译配置
    ./configure \
    --prefix=/usr/local/php \
    --enable-fpm \
    --with-fpm-user=www \
    --with-fpm-group=www \
    --with-config-file-path=/usr/local/php/etc \
    --with-libxml-dir \
    --with-openssl \
    --with-zlib \
    --with-zlib-dir \
    --enable-bcmath \
    --with-curl \
    --with-pcre-dir \
    --with-gd \
    --with-jpeg-dir \
    --with-png-dir \
    --with-xpm-dir \
    --with-freetype-dir \
    --with-gettext \
    --with-mhash \
    --enable-mbstring \
    --enable-pcntl \
    --enable-shmop \
    --enable-soap \
    --enable-sockets \
    --enable-sysvsem \
    --with-xmlrpc \
    --with-iconv-dir \
    --enable-zip \
    --enable-mysqlnd \
    --with-pdo-mysql
    
    3,编译&安装
    make && make install
    
    4,拷贝&&修改配置文件
    cp php.ini-production /usr/local/php/etc/php.ini
    cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
    cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
    
    5,拷贝控制脚本
    cp /usr/local/src/php-7.1.12/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
    chmod +x /etc/rc.d/init.d/php-fpm && chkconfig php-fpm on
    
    service php-fpm start
    service php-fpm stop
    service php-fpm status
    service php-fpm force-quit
    service php-fpm restart
    service php-fpm reload
    service php-fpm configtest
    
    6,把php加入系统环境变量
    echo "export PATH=$PATH:/usr/local/php/bin" >> /etc/profile && source /etc/profile
    
    7,配置nginx支持php
    vi /usr/local/nginx/conf/nginx.conf   #修改nginx配置文件
    
    user www www;                         #修改nginx运行组为www www
    #取消FastCGI server部分location的注释,注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name
    location ~ \.php$ {
      root html;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
    }
    
    vi /usr/local/nginx/html/index.php     #新建index.php测试文件,调用phpinfo函数
    
    <?php
    phpinfo();
    ?>
    
    service nginx restart && service php-fpm restart
    
    三、优化篇
    1,安装redis扩展
    cd /usr/local/src && wget https://pecl.php.net/get/redis-3.1.4.tgz && tar zxvf redis-3.1.4.tgz && cd redis-3.1.4 && phpize && ./configure && make && make install
    
    vi /usr/local/php/etc/php.ini
    
    [redis]
    extension=redis.so
    
    service php-fpm restart
    
    2,开启opcache扩展
    vi /usr/local/php/etc/php.ini
    
    [opcache]
    zend_extension=opcache.so
    opcache.memory_consumption = 64
    opcache.interned_strings_buffer = 16
    opcache.max_accelerated_files = 4000
    opcache.validate_timestamps = 1
    opcache.revalidate_freq = 0
    opcache.fast_shutdown = 1
    
    service php-fpm restart
    

    相关文章

      网友评论

          本文标题:CentOS下,编译安装php 7.1.x

          本文链接:https://www.haomeiwen.com/subject/azdnbxtx.html