温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Centos6.6编译安装PHP7.0详解

发布时间:2020-07-04 20:07:12 来源:网络 阅读:2104 作者:ntw1990 栏目:web开发

                                             Centos6.6编译安装PHP7.0.13详解

      1: Yum源更改为阿里的镜像源

     #mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

     #wget -O /etc/yum.repos.d/CentOS-Base.repo 

       http://mirrors.aliyun.com/repo/Centos-   6.repo

      #yum clean all 

      #yum makecache


      2: 安装php所必要的依赖包

      #yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y

      #yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel -y

      libiconv-devel   默认的yum源中没有需要编译安装

      #wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

      #cd libiconv-1.14 

      #./configure --prefix=/usr/local/libiconv

      #make && make install


      3:安装mhash和mcrypt算法

      一:下载相应的软件包

      1:下载libmcrypt安装mcrypt需要此软件包

#wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz  

       2:下载mhash安装mcrypt需要此软件包

     #wget https://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz

      3:下载mcrypt

     #wget https://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz

     二、安装软件包

      1、安装libmcrypt 

      cd /usr/local/src  #进入软件包存放目录

tar zxvf libmcrypt-2.5.8.tar.gz  #解压

cd libmcrypt-2.5.8  #进入安装目录

./configure  #配置

make  #编译

make install  #安装

2、安装mhash

cd /usr/local/src

tar zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9

./configure

make

make install

3、安装mcrypt

cd /usr/local/src

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8

ln -s   /usr/local/bin/libmcrypt_config   /usr/bin/libmcrypt_config  #添加软连接

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH  #添加环境变量

./configure

make

make install


4:安装编译php7.0.13

#wget http://cn2.php.net/distributions/php-7.0.13.tar.gz

#cd php-7.0.13

#./configure --prefix=/application/php-7.0.13/ --with-mysqli=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --disable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-zend-signals --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd  

#make

#make install

到源码包目录把PHP的配置文件copy到php的安装目录

#cd /home/ntw1990/tools/php-7.0.13

# cp php.ini-production /application/php-7.0.13/etc/

将 php 的 bin 和 sbin 加入环境变量:

#echo "export PATH=$PATH:/application/php-7.0.13/bin:/application/php-7.0.13/sbin" >>           /etc/profile

#source /etc/profile

# cd /application/php-7.0.13/etc/

#cp php-fpm.conf.default php-fpm.conf

# /application/php-7.0.13/sbin/php-fpm            ( 启动php进程)

#ps -ef | grep php-fpm                                           (检测下php-fpm进程)


5:测试php与nginx和mysql的通信正常与否

1:测试和nginx的通信是否正常                   (随意编辑一个虚拟主机,本人的如下配置)

# vim /application/nginx/conf/extra/blog.conf 

      server {
      listen                 80;
      server_name            blog.niutianwen.org;
      root                   /application/nginx/html/blog;
      index                  index.php  index.html  index.htm;
      location /  {
      }
       location ~ \.(php|php5)?$ {
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           include        fastcgi.conf;
        }
     }


    # 在测试虚拟主机的网站首页写一个php的测试脚本

    # mkdir /application//nginx/html/blog -p      创建网站根目录

    # cd /application//nginx/html/blog

    # echo "<?php phpinfo(); ?>" >test_info.php


    打开firefox测试效果:

    1:首先做好主机名和ip的对应

    #vim /etc/hosts

    本机ip地址     blog.niutianwen.org

    2:在浏览器中打开http://blog.niutianwen.org/test_info.php   

    如出现以下界面表示php和nginx的通信是正常的!

  Centos6.6编译安装PHP7.0详解


     2:测试和Mysql的通信是否正常 

      # cd /application//nginx/html/blog   

      # vim mysql_connect.php

     

 <?php
      $link = mysqli_connect('127.0.0.1', 'root', 'niutianwen');
       if (!$link) {
       echo "Error: Unable to connect to MySQL." . PHP_EOL;
       echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
       echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
       exit;
      }
     echo "Success: A proper connection to MySQL was made! The my_db database is great." .          PHP_EOL;
     echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
     mysqli_close($link);
     ?>


    2:在浏览器中打开http://blog.niutianwen.org/mysql_connect.php  

     如出现下面红线标的那一行表示php连接Mysql是正常的!

     Centos6.6编译安装PHP7.0详解


  6:使用centos6.6系统默认的进程管理方式启动php-fpm

         #vim /etc/init.d/php-fpm

    #! /bin/sh
    # Comments to support chkconfig on CentOS
    # chkconfig: 2345 65 37
    #
    set -e
    
    #PATH=/application/php-7.0.13/sbin:/application/php-7.0.13/bin
    DESC="php-fpm daemon"
    NAME=php-fpm
    
    #php-fpm命令的路径
    DAEMON=/application/php-7.0.13/sbin/$NAME
    
    #php-fpm的配置文件
    CONFIGFILE=/application/php-7.0.13/etc/php-fpm.conf
    
    #php-fpm的pid文件
    PIDFILE=/application/php-7.0.13/var/run/$NAME.pid
    
    SCRIPTNAME=/etc/init.d/$NAME
    
    # Gracefully exit if the package has been removed.
    test -x $DAEMON || exit 0
    
    function_start() { 
      [ -f $PIDFILE ] && rm -rf $PIDFILE 
      $DAEMON -y $CONFIGFILE -g $PIDFILE && echo  "Php-fpm is started"
    }
    
    function_stop() { 
      netstat -tunlp  | grep $NAME | grep -v -e grep -e vim  | awk -F'/' '{print $1}' |awk '{print $NF}' | xargs -I {} kill -QUIT {} 2> /dev/null 
      [ $? -eq 0 ] && echo  " Php-fpm is stopped"
    }
    
    function_reload() 
    {
      [ `netstat -tunlp | grep 9000|wc -l` -eq 0 ] && echo "$DESC is not startup!" && exit 0
      PID=`ps -ef | grep $NAME | grep -v -e grep -e vim | grep master | awk '{print $2}'`
      echo $PID
      kill -USR2 $PID  && echo  "php-fpm is reloaded!"
    }
    
    case "$1" in
      start)
            echo -n "Starting $DESC....----->>>>"    
            function_start
     
           ;;
      stop)
            echo -n "Stopping $DESC....---->>>>"
            function_stop
            ;;
      reload)
            echo -n "Reloading $DESC configuration....---->>>>"
            function_reload
            echo "reloaded."
      ;;
      restart)
            echo -n "Restarting $DESC....---->>>>"
            function_stop
            sleep 3
            function_start
            ;;
      *)
             echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
             exit 3
            ;;
    esac

 至此。centos6.6编译安装PHP7.0.12就OK了!


  




   


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI