zoukankan      html  css  js  c++  java
  • nginx下配置php5和php7

    用的是lnmp 一键安装的
    php5.6版本网上百度Ubuntu安装多版本PHP就行
    

      

    参考文章原链接:http://blog.csdn.net/21aspnet/article/details/47658127
    
    1.首先不用去修改原来的已经安装好的php
    2.先下载你要安装的另外一个版本的php压缩包
    3.tar zxvf ...解压压缩包
    4. 执行当前目录下的configure文件 ./configure --prefix=/opt/modules/php5.4 --with-mysql -with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath  --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex  --enable-fpm  --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-ftp --enable-soap --enable-sockets --enable-zip --with-libdir=lib64 
    其中要注意的是安装路径.--prefix
    这里以安装php5.4为例,我们打算把它安装到目录 /opt/modules/php5.4,于是在php5.4目录执行带选项的脚本./configure --prefix=/opt/modules/php5.4,执行成功后再编译、安装(make,make install);安装完成将自动生成目录php5.4,而且该软件所有的文件都被复制到这个目录。为什么要指定这个安装目录?是为了以后的维护方便,如果没有用这个选项,安装过程结束后,该软件所需的软件被复制到不同的系统目录下,很难弄清楚到底复制了那些文件、都复制到哪里去了—基本上是一塌糊涂。
    
    用了—prefix选项的另一个好处是卸载软件或移植软件。当某个安装的软件不再需要时,只须简单的删除该安装目录,就可以把软件卸载得干干净净;移植软件只需拷贝整个目录到另外一个机器即可(相同的操作系统)。
    
    5.然后make makeinstall
    6.将解压包里的这三个文件分别复制到对应的文件目录下:
    cp -R ./sapi/fpm/php-fpm.conf /opt/modules/php5.4/etc/php-fpm.conf
    cp php.ini-development /opt/modules/php5.4/lib/php.ini
    cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm5.4
    7.修改php-fpm.conf的侦听端口为9001(此处应该修改/opt/modules/php5.4/etc/php-fpm.conf),因为主版本5.2.17是侦听9000。
    8.启动php-fpm
    /etc/init.d/php-fpm5.4
    9.php安装成功查看进程
    ps aux|grep php
    这样就已经起好php-fpm了.
    10.重启nginx
    
    /usr/local/nginx/sbin/nginx -s reload
    或者/etc/init.d/nginx restart
    11.然后配置文件.
    如果你的配置文件是用的nginx/vhosts下面的具体文件配置.
    server
    {
        listen  80;
        server_name newweb.my;
        root /home/wwwroot/papersvn/newci/web;
        index index.php index.shtml index.html index.htm;
    
        access_log /home/weblogs/jingpin.log for_cookie;
        error_log /home/weblogs/jingpinerror.log;
    
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9001;
            fastcgi_index  index.php;
        }
    
    
        location ~* /(css|js|img) {
            expires 12h;
            break;
        }
    
        if (!-f $request_filename) {
            rewrite ^/$ /index.php last;
            rewrite ^/(?!(index.php|public|app|third_party|favicon.ico|32-favicon.ico))(.*)$ /index.php?$1$2 last;
            rewrite ^/index.php(.*)$ /index.php?$1 last;
            break;
        }
    }
    
    其他配置项基本不变,需要把php配置fastcgi_pass改成127.0.0.1:9001,调用9001接口.
    
    
    测试是否成功,查看phpinfo()

     下面这里是对于lnmp的配置

       lnmp的vhost php7的配置如下:

    server
        {
            listen 80;
            #listen [::]:80;
            server_name wordpass.my wordpass;
            index index.html index.htm index.php default.html default.htm default.php;
            root  /home/wwwroot/wordpass/wordpress;
    
            include other.conf;
            #error_page   404   /404.html;
    
            # Deny access to PHP files in specific directory
            #location ~ /(wp-content|uploads|wp-includes|images)/.*.php$ { deny all; }
    
            include enable-php.conf;  //这个里面配置了 php的启动和一些配置路径 PHP7用的是cgi的
    
            location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }
    
            location ~ .*.(js|css)?$
            {
                expires      12h;
            }
    
            location ~ /.well-known {
                allow all;
            }
    
            location ~ /.
            {
                deny all;
            }
    
            access_log  /home/wwwlogs/wordpass.my.log;
        }
    ~                                 
     include enable-php.conf 如果使用php5.6的 htpp模式启动
    在/usr/local/nginx/conf/创建一个enable-php5.conf(自己命名)
    配置如下:

    PHP5.6--------
    location ~ [^/].php(/|$) { try_files $uri =404; fastcgi_pass 127.0.0.1:9001; //这里是PHP5.6的 http模式 fastcgi_index index.php; include fastcgi.conf; set $fastcgi_script_name2 $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+.php)(/.+)$") { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; }
         这里是php7的  

    location ~ [^/].php(/|$) { try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; set $fastcgi_script_name2 $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+.php)(/.+)$") { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; } ~ ~

    Vhost里面引用

    server
        {
            listen 80;
            #listen [::]:80;
            server_name dede.my dedes;
            index index.html index.htm index.php default.html default.htm default.php;
            root  /home/wwwroot/zhi/de/uploads;
    
            include other.conf;  
            #error_page   404   /404.html;
    
            # Deny access to PHP files in specific directory
            #location ~ /(wp-content|uploads|wp-includes|images)/.*.php$ { deny all; }
        include enable-php5.conf;  //引用的5.6
    
            location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }
    
            location ~ .*.(js|css)?$
            {
                expires      12h;
            }
    
            location ~ /.well-known {
                allow all;
            }
    
            location ~ /.
            {
                deny all;
            }
    
            access_log  /home/wwwlogs/dede.my.log;
        }
     
  • 相关阅读:
    牛客网 二叉树的镜像 JAVA
    牛客网 反转链表 JAVA
    牛客网 调整数组顺序使奇数位于偶数前面 JAVA
    Integer to Roman LeetCode Java
    Valid Number leetcode java
    Longest Common Prefix
    Wildcard Matching leetcode java
    Regular Expression Matching
    Longest Palindromic Substring
    Add Binary LeetCode Java
  • 原文地址:https://www.cnblogs.com/mengluo/p/9021522.html
Copyright © 2011-2022 走看看