LNMP安装教程:安装php

  1. 首先需要安装几个依赖包

    • libmcrypt

        wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/download
        tar -jxvf libmcrypt-2.5.8.tar.bz2   # 这个包是bz2的  使用-j参数解压
        cd libmcrypt-2.5.8
        ./configure
        make
        make install
      
    • mhasd

        wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download
        tar -jxvf mhash-0.9.9.9.tar.bz2
        cd mhash-0.9.9.9
        ./configure
        make
        make install
      

      上述两个包安装完成后要把动态链接库做一个软连接到/usr/lib,以为接下来的mcrypt依赖于这两个包

        ln -s /usr/local/lib/libmcrypt* /usr/lib
        ln -s /usr/local/lib/libmhash.* /usr/lib/
        ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
      
    • mcrypt

        wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
        tar -zxvf mcrypt-2.6.8.tar.gz
        cd mcrypt-2.6.8
        export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
        ./configure
        make
        make install        
      
  2. 安装php

    • 下载php

        wget http://cn2.php.net/distributions/php-5.6.9.tar.gz
      
    • 安装依赖

        yum –y install libxml2-devel curl-devel libpng-devel openldap-devel mysql.sever-devel
      
    • 编译

        ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-zlib --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --with-curl --with-curlwrappers --enable-fpm --enable-fastcgi --with-mcrypt --with-gd --with-openssl --with-mhash --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc -enable-zip --enable-soap --with-libdir=lib64
      

      因为我的是centos是64位,所以在后面加上(32位的不需要)

        --with-libdir=lib64
      

      但在编译过程中遇到以下问题:
      问题1(应该64位才有)

        checking for MySQL UNIX socket location... no
        configure: error: Cannot find libmysqlclient under /usr/local/mysql/.
        Note that the MySQL client library is not bundled anymore!
      

      解决办法:

        cd /usr/local/mysql/
        ln -s lib lib64 
      

      问题2

        checking for sysvipc shared memory support... no
        checking for mmap() using MAP_ANON shared memory support... no
        checking for mmap() using /dev/zero shared memory support... no
        checking for mmap() using shm_open() shared memory support... no
        checking for mmap() using regular file shared memory support... no
        checking "whether flock struct is linux ordered"... "no"
        checking "whether flock struct is BSD ordered"... "no"
        configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no 
      

      就这样开始了悲惨的debug…

      上网找解决办法

      • (1)安装 development tools –>没解决

          yum groupinstall "Development tools" 
        
      • (2)修改 /etc/ld.so.conf.d/local.conf –>没解决

          vim /etc/ld.so.conf.d/local.conf     # 编辑库文件
          /usr/local/lib                       # 添加该行 64位的写/usr/local/lib64
          :wq                                  # 保存退出
          ldconfig -v                          # 使之生效
        
      • (3)google找了个,可以解决了

        I had the same error, while compiling PHP (5.6.4, but that does not matter, because I tried als PHP 5.6.3 and was reproducable) on Debian GNU/Linux. I saw that problem when I forgot to set LD_LIBRARY_PATH environment variable.

        So doing it like that solved my problem:

          $ export LD_LIBRARY_PATH=/usr/local/mysql/lib
          $ ./configure --enable-fpm --with-mcrypt --with-zlib --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 --enable-sockets --enable-zip --with-fpm-user=www-data --with-fpm-group=www-data --with-mysql=/usr/local/mysql/
          $ make
          $ make test
          # export LD_LIBRARY_PATH=/usr/local/mysql/lib
          # make install
        
    • 安装

        make
        make test
        make install
      
    • 配置

        cp php.ini-production /usr/local/php/php.ini # 如果是开发就复制php.ini-development
        cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
        ln -s /usr/local/php/bin/php /usr/bin/
      

      修改/usr/local/php/etc/php-fpm.conf文件

        # 将;pid = run/php-fpm.pid前的;去掉并修改为
        pid = /usr/local/php/var/run/php-fpm.pid    
      

      启动php-fpm

        /usr/local/php/sbin/php-fpm
      

      修改vi /usr/local/nginx/conf/nginx.conf,支持php

           server {
            listen       80;
            server_name  localhost;
      
            #charset koi8-r;
      
            #access_log  logs/host.access.log  main;
      
                location / {
                    root   html;
                    index  index.php index.html index.htm;         # 添加index.php的首页文件
                }
      
                # 添加下面内容
                location ~ \.php$ {
                    fastcgi_pass        127.0.0.1:9000;
                    fastcgi_index       index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
                    include fastcgi_params;
                    include fastcgi.conf;
                }
            }
      

      修改完毕后保存退出重启nginx:

        pkill -9 nginx
        /usr/local/nginx/sbin/nginx
      

      然后在/usr/local/nginx/html下创建index.php,

        vi /usr/local/nginx/html/index.php
      

      添加下面内容:

        <?php  
        phpinfo();  
        ?>  
      

      保存退出后访问127.0.0.1:80/index.php(下面是我用在主机上访问虚拟机的地址10.211.55.5)

《LNMP安装教程:安装php》 屏幕快照 2015-06-03 下午1.23.52 (2).png

    原文作者:Mklaus
    原文地址: https://www.jianshu.com/p/0d6d188c2ddc
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞