zoukankan      html  css  js  c++  java
  • php7.0编译安装

    php7.0的编译安装

    环境说明:VMware12搭建 centos6.5
    已经安装了nginx1.6和mysql5.7

    1    配置编译环境
    https://segmentfault.com/a/1190000009875949
    yum -y update && yum -y upgrade
    yum groupinstall "Development Tools"
    yum -y install gcc gcc-c++ pcre openssl gd-devel* zlib-devel pcre-devel libxml2-devel curl-devel

    wget https://svwh.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
    tar -zxvf libmcrypt-2.5.8.tar.gz
    cd libmcrypt-2.5.8
    ./configure
    make && make install
    编辑 vim /etc/ld.so.conf 末行添加
    /usr/local/lib
    并执行:ldconfig


    1    配置编译环境(方法二)
    https://www.cnblogs.com/da-guang/p/6973868.html
    编译安装 libmcrypt, mhash, mcrypt 二进制源码包
    这里之所以编译安装libmcrypt,原因是yum安装的貌似会报错,

    编译安装libmcrypt-2.5.7
    tar zxvf libmcrypt-2.5.7.tar.gz
    cd libmcrypt-2.5.7
    ./configure --prefix=/usr/local/related/libmcrypt
    make && make install


    编译安装mhash-0.9.9.9
    tar zxf 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
    tar zxf 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


    其他的yum依赖安装
    yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel

    php7编译安装
    wget http://cn2.php.net/distributions/php-7.0.14.tar.gz
    tar -zxf php-7.0.14.tar.gz
    cd php-7.0.14

    ./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=/data/mysql/mysql.sock --with-mcrypt=/usr/include --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --enable-sockets --enable-soap --enable-session --with-curl --enable-opcache --enable-fpm --enable-fastcgi --with-fpm-user=www --with-fpm-group=www --disable-fileinfo
    用./configure --help 查看configure的正确语法
    make clean &&make && make install

    prefix=/usr/local/php7                              php7安装的根目录
    -with-config-file-path=/usr/local/php7/etc      php7的配置目录
    --with-mysql-sock=/data/mysql/mysql.sock
    --with-mysql=shared,mysqlnd                             php7依赖的mysql库
    --with-mysqli=shared,mysqlnd
    --with-pdo-mysql=shared.mysqlnd
    --enable-session                                                [允许php会话session]
    --with-curl                                                           [允许curl扩展]
    --enable-opcache                                               [使用opcache缓存
    --with-fpm-user=www                                           php-fpm的用户
    --with-fpm-group=www

    编译时会发生--with-mysql和--enable-fastcgi不能识别,正常
    make test时会有一个报错,正常

    需要和MySQL进行通信,需要特别查看PHP7安装后的lib扩展库目录
    usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
    确保至少存在mysql.so pdo_mysql.so两个动态库文件
    ls -lrt /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/


    方法一编译安装后未经处理的配置
    cd php-7.0.14
    cp php.ini-production /usr/local/php7/etc/php.ini
    cp /sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    cp /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
    下面这个可以不要,在配置文件php-fpm.conf中可以配置include


    方法二:使用https://github.com/lizer2014/mylnmp/tree/master/PHP文中的配置
    [root@localhost php-7.0.0]# mv ~/php.ini /usr/local/php7/etc/php.ini && mv ~/php-fpm /etc/init.d/php-fpm
    [root@localhost php-7.0.0]# mv ~/php-fpm.conf /usr/local/php7/etc/php-fpm.conf && mv ~/www.conf /usr/local/php7/etc/php-fpm.d/www.conf

    修改php.ini配置中的参数,extension_dir改为自己的
    extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
    在/etc/init.d/php-fpm中在start函数的守护进程前必须有make /var/run/php-fpm命令,否则重启服务器会导致启动失败,nginx中配置也有这个问题

    添加php的环境变量
    echo -e ' export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH ' >> /etc/profile
     source /etc/profile

    设置php-fpm进程目录的用户和用户组为nginx,并创建php会话session目录
     groupadd -r www && useradd -r -g www -s /bin/false -M www
     mkdir -p /var/log/php-fpm/ &&
     mkdir -p /var/run/php-fpm &&
     cd /var/run/ &&
     chown -R www:www php-fpm
    chmod +x /etc/init.d/php-fpm
    chkconfig --add php-fpm
    chkconfig php-fpm on
    php-fpm -t试PHP的配置文件是否正确合法
    service php-fpm start
    ps -aux|grep php


    配置文件
    /usr/local/php7/etc/php.ini
    /usr/local/php7/etc/php-fpm.d/www.conf


    生产情况下,可以直接更改php的配置文件内容
    vi /usr/local/php7/etc/php-fpm.conf

    [global]
    pid = /usr/local/php/var/run/php-fpm.pid
    error_log = /usr/local/php/var/log/php-fpm.log
    log_level = notice

    [www]
    listen = /tmp/php-cgi.sock   此处的配置和nginx中的fastcgi_pass中配置一样 unix:/tmp/php-cgi.sock
    listen.backlog = -1
    listen.allowed_clients = 127.0.0.1
    listen.owner = www
    listen.group = www
    listen.mode = 0666
    user = www
    group = www
    pm = dynamic
    pm.max_children = 300
    pm.start_servers = 30
    pm.min_spare_servers = 30
    pm.max_spare_servers = 60
    request_terminate_timeout = 0
    request_slowlog_timeout = 0
    slowlog = var/log/slow.log
    pm.status_path = /status


    nginx中配置
         36 location ~ .*.(php|php7)?$ {
         37
         38         root           /var/www/html/;
         39         fastcgi_pass   unix:/tmp/php-cgi;        
         40         fastcgi_index  index.php;
         41         fastcgi_param  HTTPS   on;
         42         fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
         43         include        fastcgi_params;
         44
         45         #new line
         46         include fastcgi.conf;
         47 }


    39行和php.conf里面的配置文件相同
    如果重启的时候报错:
    Starting php-fpm [14-Aug-2015 11:29:31] ERROR: An another FPM instance seems to already listen on /tmp/php-fcgi.sock
    [14-Aug-2015 11:29:31] ERROR: FPM initialization failed
    failed

    检查是否启动:ps aux |grep php-fpm
    如果有进程就杀死:killall php-fpm
    如果没有进程:    直接删除/tmp/php-fcgi.sock然后再启动。


  • 相关阅读:
    SpringCloud微服务基础学习
    EF6 + MySql 建立项目引用失败
    Forword(请求转发)与Redirect(重定向)区别
    Java 中 Hashtable与HashMap的区别
    cookie和session
    configparser模块的简单使用
    列表中的陷阱
    Python3面向对象编程总结
    Python---RabbitMQ的使用
    Django的template自定义函数的创建和使用
  • 原文地址:https://www.cnblogs.com/fengzhongzhuzu/p/8670268.html
Copyright © 2011-2022 走看看