zoukankan      html  css  js  c++  java
  • Ubuntu安装php

    Ubuntu安装php
    记录下主要的流程和遇到的坑。

    首先官网下载php,http://php.net/downloads.php,我用的是5.6.25的版本:

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

    下载后,解压到服务器随意目录

    tar xzvf php-5.6.25.tar.gz

    // 添加www用户

    groupadd www

    useradd -g www www 

    完了后,configure编译,如下:

    # ./configure 
    --prefix=/usr/local/php56 
    --with-config-file-path=/usr/local/php56/etc 
    --enable-inline-optimization 
    --disable-debug 
    --disable-rpath 
    --enable-shared 
    --enable-opcache 
    --enable-fpm 
    --with-fpm-user=www 
    --with-fpm-group=www 
    --with-mysql=mysqlnd 
    --with-mysqli=mysqlnd 
    --with-pdo-mysql=mysqlnd 
    --with-gettext 
    --enable-mbstring 
    --with-iconv 
    --with-mcrypt 
    --with-mhash 
    --with-openssl 
    --enable-bcmath 
    --enable-soap 
    --with-libxml-dir 
    --enable-pcntl 
    --enable-shmop 
    --enable-sysvmsg 
    --enable-sysvsem 
    --enable-sysvshm 
    --enable-sockets 
    --with-curl 
    --with-zlib 
    --enable-zip 
    --with-bz2 
    --with-readline
     

    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline --with-gd --enable-gd-native-ttf --enable-gd-jis-conv
     

    这个时候有可能会出现下列错误:
    mcrypt.h not found. Please reinstall libmcrypt
    原因:centos源不能安装libmcrypt-devel,由于版权的原因没有自带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

    此时可能会出现如下错误:

    configure: error: C++ compiler cannot create executables

    靠谱的解决方法是:

    yum install gcc gcc-c++ gcc-g77
    然后重新执行,问题应该就解决了。

    make
    make install

    然后重新configure,此时可能会遇到下列错误:
    error: Don't know how to define struct flock on this system, set --enable-op
    靠谱的解决方法是:

    sudo ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/lib/ 
    sudo ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

    export LD_LIBRARY_PATH=/lib/:/usr/lib/:/usr/local/lib:/usr/local/mysql/lib

    再执行,应该不会报错了。
    make 
    make install

    注:在低配置的服务器比如小于1gb时,有可能make时出现如下错误:

    make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

    解决办法

    这是由于内存小于1G所导致.

    在./configure加上选项:

    --disable-fileinfo

    Disable fileinfo support 禁用 fileinfo

    或者,重新make可能会过去。

    [root@dev3 bin]# ./php -version
    PHP 5.6.28 (cli) (built: Nov 18 2016 13:02:58) 
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

    配置php

    [root@dev3 php-5.6.28]#

    cp php.ini-development /usr/local/php56/etc/php.ini

    配置php-fpm 服务

    # cp /usr/local/php56/etc/php-fpm.conf.default /usr/local/php56/etc/php-fpm.conf
    # cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm56
    # chmod +x /etc/init.d/php-fpm56

    启动 php-fpm

    # service php-fpm56 start
    Starting php-fpm done

    到此为止,php本身的安装和配置就完成了,如何验证呢。。。。

    很重要的一点是:php本身并不是一个web服务器,只是一个web服务器后面的cgi实现,就像java本身并不提供http服务一样,前台有个tomcat。
    所以php要依赖于nginx或者apache作为前置,因为我们一直用nginx,所以以nginx为例。
    首先,我不得不说nginx自带的nginx.conf中配置php的示例代码是坑。。。
    读者直接参考php官方给的即可,http://php.net/manual/zh/install.unix.nginx.php。亲测,没有问题的。
  • 相关阅读:
    状态压缩 + 暴力 HDOJ 4770 Lights Against Dudely
    简单几何(推公式) UVA 11646 Athletics Track
    简单几何(四边形形状) UVA 11800 Determine the Shape
    简单几何(求交点) UVA 11437 Triangle Fun
    计算几何模板
    简单几何(相对运动距离最值) UVA 11796 Dog Distance
    简单几何(求划分区域) LA 3263 That Nice Euler Circuit
    覆盖的面积 HDU
    Desert King 最小比率生成树 (好题)
    约会安排 (区间合并)毒瘤题
  • 原文地址:https://www.cnblogs.com/wwlww/p/8413603.html
Copyright © 2011-2022 走看看