zoukankan      html  css  js  c++  java
  • Centos7安装PHP7

    安装依赖

    yum update
    yum
    install gcc-c++ 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

    编译

    ./configure 
    --prefix=/usr/local/php 
    --with-config-file-path=/etc 
    --enable-fpm 
    --with-fpm-user=nginx 
    --with-fpm-group=nginx 
    --enable-inline-optimization 
    --disable-debug 
    --disable-rpath 
    --enable-shared 
    --enable-soap 
    --with-libxml-dir 
    --with-xmlrpc 
    --with-openssl 
    --with-mcrypt 
    --with-mhash 
    --with-pcre-regex 
    --with-sqlite3 
    --with-zlib 
    --enable-bcmath 
    --with-iconv 
    --with-bz2 
    --enable-calendar 
    --with-curl 
    --with-cdb 
    --enable-dom 
    --enable-exif 
    --enable-fileinfo 
    --enable-filter 
    --with-pcre-dir 
    --enable-ftp 
    --with-gd 
    --with-openssl-dir 
    --with-jpeg-dir 
    --with-png-dir 
    --with-zlib-dir 
    --with-freetype-dir 
    --enable-gd-native-ttf 
    --enable-gd-jis-conv 
    --with-gettext 
    --with-gmp 
    --with-mhash 
    --enable-json 
    --enable-mbstring 
    --enable-mbregex 
    --enable-mbregex-backtrack 
    --with-libmbfl 
    --with-onig 
    --enable-pdo 
    --with-mysqli=mysqlnd 
    --with-pdo-mysql=mysqlnd 
    --with-zlib-dir 
    --with-pdo-sqlite 
    --with-readline 
    --enable-session 
    --enable-shmop 
    --enable-simplexml 
    --enable-sockets 
    --enable-sysvmsg 
    --enable-sysvsem 
    --enable-sysvshm 
    --enable-wddx 
    --with-libxml-dir 
    --with-xsl 
    --enable-zip 
    --enable-mysqlnd-compression-support 
    --with-pear 
    --enable-opcache

    make
    make install

    出现 configure: error: mcrypt.h not found. Please reinstall libmcrypt时

    cd /usr/local/src
    wget http://softlayer.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz
    tar -zxvf libmcrypt-2.5.8.tar.gz
    cd /usr/local/src/libmcrypt-2.5.8
    ./configure --prefix=/usr/local
    make
    make install

    出现 Don't know how to define struct flock on this system, set --enable-opcache=no

    [root@localhost php-7.1.0]# vi /etc/ld.so.conf  
    include ld.so.conf.d/*.conf
    # 添加这行
    /usr/local/lib
    ~
    #保存后使之生效
    ldconfig -v

    安装完之后, 可以直接运行PHP内建的web server,

    # 使用/var/www/html/ 作为root目录, 使用php.ini作为环境配置
    php -S 0.0.0.0:80 -t /var/www/html -c php.ini
    # 后台运行, 且不保留任何输出
    nohup php -S 0.0.0.0:80 -t /var/www/html >/dev/null 2>&1 &
    # 后台运行, 将日志输出到当前路径下的phpd.log
    nohup php -S 0.0.0.0:80 -t /var/www/html >phpd.log 2>&1 &
    # 后台运行, 将日志输出到当前路径下的phpd.log, 使用bar.php作为路由脚本
    nohup php -S 0.0.0.0:80 -t /var/www/html bar.php >phpd.log 2>&1 &

    路由脚本: 每次请求都会先执行这个脚本。如果这个脚本返回 FALSE ,那么直接返回请求的文件(例如请求静态文件不作任何处理)。否则会把输出返回到浏览器

    配置php和php-fpm

    # 将默认的产品配置文件复制到配置目录
    cp /usr/src/php-7.1.0/php.ini-production /usr/local/php/etc/php.ini
    # 复制默认的php-fpm配置文件
    cd /usr/local/php/etc/
    mv php-fpm.conf.default php-fpm.conf
    mv php-fpm.d/www.conf.default php-fpm.d/www.conf
    # 将php-fpm添加到服务
    cd /usr/src/php-7.1.0/sapi/fpm/
    cp init.d.php-fpm /etc/init.d/php-fpm
    chmod +x /etc/init.d/php-fpm 
    chkconfig --add php-fpm
    chkconfig php-fpm on
    systemctl start php-fpm
    # 检查是否正常运行
    ps aux|grep php-fpm

    修改nginx配置文件支持PHP

    vi /opt/nginx/conf/nginx.conf
    
    # 把前面的#注释符号去掉,把script改为$document_root最终如下:
    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;
    }

    然后重新载入nginx配置, 安装就完成了

  • 相关阅读:
    LeetCode "Minimum Moves to Equal Array Elements"
    LeetCode "Third Maximum Number"
    LeetCode "Arranging Coins"
    LeetCode "Is Subsequence"
    HackerRank "Flatland Space Stations"
    LeetCode "Super Pow"
    LeetCode "Wiggle Subsequence" !
    HackerRank "Jumping on the Clouds"
    HackerRank "Fair Rations"
    HackerRank "Equal Stacks"
  • 原文地址:https://www.cnblogs.com/milton/p/6223813.html
Copyright © 2011-2022 走看看