美文网首页
Debian8中用编译方式安装php7

Debian8中用编译方式安装php7

作者: co可丁 | 来源:发表于2017-02-10 16:27 被阅读644次

    php安装步骤:

    1. 下载php-7.0.14.tar.gz,并将其解压:
    $ tar -zvxf php-7.0.14.tar.gz
    
    2. 安装相关依赖包:
    $ apt-get install -y libxml2 libxml2-dev openssl libcurl4-gnutls-dev libjpeg-dev libpng12-dev libfreetype6-dev
    
    3. 执行:ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib

    注:否则会报错:configure: error: Cannot find OpenSSL's libraries

    4. 编译:
    $ cd php-7.0.14
    $ ./configure --with-openssl --with-mysqli=shared,mysqlnd --with-pdo-MySQL=shared,mysqlnd \
    --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-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap \
    --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm \
    --enable-fastcgi --without-gdbm --disable-fileinfo
    
    5. 安装:
    $ make && make install
    

    成功:

    php安装成功

    php-fpm配置

    • $ cd php-7.0.14
      $ cp php.ini-production /usr/local/etc/php.ini
      在php.ini中添加一行:cgi.fix_pathinfo=0

    • $ cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
      $ cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf

    • $ vi /usr/local/etc/php-fpm.d/www.conf
      将group = nobody修改为 group = ,即将nobody删除。否则在后面执行service php-fpm start时会报错,即Starting php-fpm [10-Feb-2017 06:32:10] ERROR: [pool www] cannot get gid for group 'nobody'
      (可直接执行:sed -i "s/group = nobody/group = /g" /usr/local/etc/php-fpm.d/www.conf

    • $ vi /usr/local/etc/php-fpm.conf
      将php-fpm.conf最后一行的include=NONE/etc/php-fpm.d/.conf修改为include=etc/php-fpm.d/.conf
      (注:此时可以使用命令进行测试:
      $ /usr/local/sbin/php-fpm -t
      输出:NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful 即配置正确)

    • $ cp /root/php-7.0.14/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
      $ chmod 755 /etc/init.d/php-fpm
      $ service php-fpm start
      输出:Starting php-fpm done

    测试是否能解析php文件:

    注:先要安装nginx,具体步聚见http://www.jianshu.com/p/6b70db035b95

    1. 在/usr/local/nginx/html/文件夹下创建一个用于测试的php文件,如test.php:
    <?php
        phpinfo()
    ?>
    
    1. 启动nginx(需要对脚本做修改),在浏览器中输入http://localhost/test.php,看到以下页面即成功。
    test.php页面

    遇到的问题及解决方法

    1. .编译时报错:configure: error: Cannot find OpenSSL's libraries
      解决方法:
      apt-get install openssl
      apt-get install libssl
      find / -name libssl.so
      输出:/usr/lib/x86_64-linux-gnu/libssl.so
      执行:ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib
    2. 编译时报错:configure: error: Please reinstall the libcurl distribution -
      easy.h should be in <curl-dir>/include/curl/
      解决方法:apt-get install libcurl4-gnutls-dev
    3. 编译时报错:configure: error: jpeglib.h not found.
      解决方法:apt-get install libjpeg-dev
    4. 编译时报错:configure: error: png.h not found.
      解决方法:apt-get install libpng12-dev
    5. 编译报错:configure: error: freetype-config not found.
      解决方法:apt-get install libfreetype6-dev
    6. 执行/web/php/etc/php-fpm -t报错 :
      root@ng1:~/php-7.0.14# /web/php/sbin/php-fpm -t
      [10-Feb-2017 10:29:10] WARNING: Nothing matches the include pattern '/web/php/etc/php-fpm.d/*.conf' from /web/php/etc/php-fpm.conf at line 125.
      [10-Feb-2017 10:29:10] ERROR: No pool defined. at least one pool section must be specified in config file
      [10-Feb-2017 10:29:10] ERROR: failed to post process the configuration
      [10-Feb-2017 10:29:10] ERROR: FPM initialization failed
      解决方法:cd /web/php/etc/php-fpm.d
      cp www.conf.default www.conf

    相关文章

      网友评论

          本文标题:Debian8中用编译方式安装php7

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