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

    安装

    云安装

    yum install php //安装php(云安装的版本php5,其他版本需要手动下载安装)

    手动安装: php版本 http://www.php.net/downloads.php

    // 下载
    wget http://cn2.php.net/distributions/php-7.0.30.tar.gz
    // 创建php目录
    cd /usr/local
    mkdir php

    安装php依赖库

    configure: error: xml2-config not found. Please check your libxml2 installation.   // 报错

    yum install libxml2

    yum install libxml2* -y  

    configure: error: png.h not found.   // 报错

    yum install libpng

    yum install libpng-devel

    configure: error: mcrypt.h not found. Please reinstall libmcrypt.  // 报错

    yum install -y epel-release
    yum install -y libmcrypt-devel
    两个不能一起安装,因为CentOs6默认的yum源没有 libmcrypt-devel这个包,只能借助epel的yum源,所以先安装epel,再安装
    libmcrypt。

    编译安装php

    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-mysqli --with-gd --with-zlib --with-mcrypt --enable-fpm
    
    
    make && make install

    安装完成后,别忘记 make test

    【注意:下载的php,容易出现解压报错和php地址不对】

    nginx配置php  路径/usr/local/nginx/conf/nginx.conf

    location / {
                root   html;
                index  index.html index.htm index.php;
            }

    2.

    cd /down/
    ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-libxml-dir=/usr/local/libxml2  //检测是否满足安装
    make  // 编译
    make install    // 安装

    方法二:

    // 优先装epel
    yum install -y epel-release

    两个不能一起安装,因为CentOs6默认的yum源没有 libmcrypt-devel这个包,只能借助epel的yum源,所以先安装epel,再安装
    libmcrypt。

    //须要安装须要的模块,直接yum一并安装依赖库
    yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel libmcrypt-devel
    // 配置
    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-mysqli --with-gd --with-zlib --with-mcrypt --enable-fpm
    
    // 编译安装
    make && make install

    方法三:

    // 优先装epel
    yum install -y epel-release
    // 安装依赖库
    yum install libxml2* libpng libpng-devel libmcrypt-devel 
    
    // 配置 (此操作必须要进入  cd /down/php-7.0.30 目录下)
    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-mysqli --with-gd --with-zlib --with-mcrypt --enable-fpm
    
    // 编译并且安装
    make && make install

    // 安装完成后会有提示让你make test
    make test

    // make test完成后 会提示

    Thank you for helping to make PHP better.

    方法四:

    // 优先装epel

    yum install -y epel-release

    yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel libmcrypt-devel
    // 配置 (此操作必须要进入  cd /down/php-7.0.30 目录下)
    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-mysqli --with-gd --with-zlib --with-mcrypt --enable-fpm

    make && make install

     

    方法五(已测试):

    安装依赖库

    yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel

    注意:安装php7beta3的时候有几处配置只是去,须要yum一下。如今php-7.0.2已经不用这样了。
    # yum -y install curl-devel
    # yum -y install libxslt-devel

    如果提示 可以安装curl-devel

    configure: error: cURL version 7.10.5 or later is required to compile php with cURL support

    配置

    ./configure   --help
     
     ./configure --prefix=/usr/local/php 
     --with-curl 
     --with-freetype-dir 
     --with-gd 
     --with-gettext 
     --with-iconv-dir 
     --with-kerberos 
     --with-libdir=lib64 
     --with-libxml-dir 
     --with-mysqli 
     --with-openssl 
     --with-pcre-regex 
     --with-pdo-mysql 
     --with-pdo-sqlite 
     --with-pear 
     --with-png-dir 
     --with-xmlrpc 
     --with-xsl 
     --with-zlib 
     --enable-fpm 
     --enable-bcmath 
     --enable-libxml 
     --enable-inline-optimization 
     --enable-gd-native-ttf 
     --enable-mbregex 
     --enable-mbstring 
     --enable-opcache 
     --enable-pcntl 
     --enable-shmop 
     --enable-soap 
     --enable-sockets 
     --enable-sysvsem 
     --enable-xml 
     --enable-zip

    // 编译 & 安装

    make && make install

    配置文件

    # cp php.ini-development /usr/local/php/lib/php.ini
    # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
    # cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
    # cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
     
    须要注意的是php7中www.conf这个配置文件配置phpfpm的端口号等信息,假设你改动默认的9000端口号需在这里改,再改nginx的配置
    启动
    #  /etc/init.d/php-fpm
     
    配置nginx.conf
    #location ~ .php$ {        找到
      # root   html;
      # fastcgi_pass 127.0.0.1:9000;
      # fastcgi_index index.php;
      # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
      # include  fastcgi_params;
      #}
    location ~ .php$ {        改为
       root   html;
       fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include  fastcgi_params;
      }

    建立index.php 内容为

    <?php
    phpinfo()
    ?>

    最后重启

    service nginx restart    或者./nginx -s reload  重启nginx      

    service php-fpm restart 或者 /etc/init.d/php-fpm  重启 php-fpm

    报错:

    Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
    You may want to add: /usr/local/php/lib/php to your php.ini include_path
    /down/php-7.0.30/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
    ln -s -f phar.phar /usr/local/php/bin/phar
    Installing PDO headers: /usr/local/php/include/php/ext/pdo/

    参考:https://blog.csdn.net/sayyy/article/details/78556860?locationNum=3&fps=1

    故障:

    重启nginx报错,提示: 
    [emerg] open() “/var/run/nginx/nginx.pid” failed (2: No such file or directory) 
    解决:在var/run/下建立一个文件夹命名为nginx,然后: 
    [root@localhost ~]# /usr/local/nginx/sbin/nginx 
    [root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload 

    或者

    解决方法:
    1. 重新运行一下 sudo /usr/share/nginx/sbin/nginx

    2. 重启nginx:sudo /usr/share/nginx/sbin/nginx -s reload

  • 相关阅读:
    rest framework Genericview
    rest framework Views
    rest framework Response
    rest framework Request
    C# Unity 依赖注入
    C# 缓存
    使用 Log4Net 做日志
    ORM 与 数据持久化
    Mycat 配置 笔记
    .NET自我进阶以及第一个框架搭建(二)
  • 原文地址:https://www.cnblogs.com/wesky/p/9062091.html
Copyright © 2011-2022 走看看