美文网首页
CentOS编译安装PHP7

CentOS编译安装PHP7

作者: Captain_tu | 来源:发表于2017-07-28 17:31 被阅读240次
  1. 下载包

     wget http://php.net/get/php-7.1.7.tar.gz/from/this/mirror
     mv mirror php-7.1.7.tar.gz
     tar -zxvf php-7.1.7.tar.gz
     cd php-7.1.7.tar.gz
    
  2. 创建用户和用户组

     groupadd php
     useradd php -g php
    
  3. 扩展库安装

     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 libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
    
     #安装libmcrypt
     wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
     tar -zxvf libmcrypt-2.5.7.tar.gz && cd libmcrypt-2.5.7
     ./configure --prefix=/usr/local/related/libmcrypt
     make & make install
    
     #安装mhash
     wget http://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2
     tar -jxvf mhash-0.9.9.9.tar.gz & cd mhash-0.9.9.9
     ./configure --prefix=/usr/local/related/mhash
     make & make install
    
     #安装mcrypt-2.6.8
     wget https://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
     mv download mcrypt-2.6.8.tar.gz
     tar -zxvf mcrypt-2.6.8.tar.gz
     cd mcrypt-2.6.8
     export LD_LIBRARY_PATH=/usr/local/related/libmcrypt/lib:/usr/local/related/mhash/lib
     export LDFLAGS="-L/usr/local/related/mhash/lib -I/usr/local/related/mhash/include/"
     export CFLAGS="-I/usr/local/related/mhash/include/"
     ./configure --prefix=/usr/local/related/mcrypt --with-libmcrypt-prefix=/usr/local/related/libmcrypt
     make && make install
    
  4. 编译参数的配置

    ./buildconf --force    #1. 生成配置文件
     
    ./configure \
    --prefix=/usr/local/php7 \                           [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 \          [PHP7的配置目录]
    --with-mysql-sock=/var/run/mysql/mysql.sock \          [PHP7的Unix socket通信文件]
    --with-mcrypt=/usr/include \
    --with-mhash \
    --with-openssl \
    --with-mysql=shared,mysqlnd \                        [PHP7依赖mysql库]             
    --with-mysqli=shared,mysqlnd \                       [PHP7依赖mysql库]
    --with-pdo-mysql=shared,mysqlnd \                     [PHP7依赖mysql库]
    --with-gd \
    --with-iconv \
    --with-zlib \
    --enable-zip \
    --enable-inline-optimization \
    --disable-debug \
    --disable-rpath \
    --enable-shared \
    --enable-xml \
    --enable-bcmath \
    --enable-shmop \
    --enable-sysvsem \
    --enable-mbregex \
    --enable-mbstring \
    --enable-ftp \
    --enable-gd-native-ttf \
    --enable-pcntl \
    --enable-sockets \
    --with-xmlrpc \
    --enable-soap \
    --without-pear \
    --with-gettext \
    --enable-session \                                  [允许php会话session]
    --with-curl \                                      [允许curl扩展]
    --with-jpeg-dir \
    --with-freetype-dir \
    --enable-opcache \                                  [使用opcache缓存]
    --enable-fpm \
    --enable-fastcgi \
    --with-fpm-user=nginx \                             [php-fpm的用户]
    --with-fpm-group=nginx \                            [php-fpm的用户组]
    --without-gdbm \
    --with-mcrypt=/usr/local/related/libmcrypt \           [指定libmcrypt位置]
    --disable-fileinfo
    
    make & make install
    
     cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
     mv ~/php-fpm.conf /usr/local/php7/etc/php-fpm.conf && mv ~/www.conf /usr/local/php7/etc/php-fpm.d/www.conf
     #启动php-fpm
     php-fpm
    
  5. 配置nginx+php-fpm+laravel

    1. 修改php-fpm的用户
      vim /usr/local/php7/etc/php-fpm.d/www.conf

       user=nginx
       group=nginx
      
    2. 修改nginx.conf
      vim /usr/local/nginx/conf/nginx.conf

       user nginx nginx;
       worker_processes  1;
      
       pid logs/nginx.pid;
       events {
           worker_connections  1024;
       }
      
       http {
           include       mime.types;
           default_type  application/octet-stream;
      
           sendfile on;
           tcp_nopush on;
      
           keepalive_timeout  65;
           gzip on;
      
           server
           {
               listen 80;
               server_name localhost;
               root /home/nginx/project/lavue/public;
               index index.html index.htm index.php;
      
               location ~ .*\.(php|php5)?$
               {
                   fastcgi_pass 127.0.0.1:9000;
                   fastcgi_index index.php;
                   include fastcgi.conf;
               }
      
               location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
               {
                   expires 30d;
               }
      
               location ~ .*\.(js|css)?$
               {
                   expires 1h;
               }
      
               location /{
                   index index.php;
               }
             }
         }
      

相关文章

网友评论

      本文标题:CentOS编译安装PHP7

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