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。亲测,没有问题的。
  • 相关阅读:
    Android Java执行Shell命令
    ArrayList和LinkedList的几种循环遍历方式及性能对比分析
    Android利用Fiddler进行网络数据抓包
    Android常用的工具类
    单例模式的标准写法、注意事项、作用及测试
    性能优化之Java(Android)代码优化
    性能优化之数据库优化
    Android性能优化之布局优化
    Android ListView滑动过程中图片显示重复错乱闪烁问题解决
    滚动到底部加载更多及下拉刷新listview的使用
  • 原文地址:https://www.cnblogs.com/wwlww/p/8413603.html
Copyright © 2011-2022 走看看