用的是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;
}
 

nginx下配置php5和php7的更多相关文章

  1. 如何在Nginx下配置PHP程序环境

    1.nginx与PHP的关系 首先来看nginx与php的关系, FastCGI的关系(而不是像apache那样安装成nginx的模块) FastCGI的意思是, 快速的通用网关接口:CGI Comm ...

  2. NGINX下配置404错误页面的方法分享

    NGINX下配置自定义的404页面是可行的,而且很简单,只需如下几步,需要的朋友可以参考下   1. 创建自己的404.html页面 2.更改nginx.conf在http定义区域加入: fastcg ...

  3. Ubuntu Nginx下配置网站ssl实现https访问

    最近在看  HTTP权威指南   看到介绍了HTTPS的ssl,自己就动手测试了下,将步骤记录下 HTTPS简介 什么是HTTPS?百科是这样解释的.HTTPS(全称:Hyper Text Trans ...

  4. codeigniter(ci)在nginx下返回404的处理方法即codeigniter在nginx下配置方法

    codeigniter(ci)在nginx下返回404的处理方法即codeigniter在nginx下配置方法 进入nginx的配置文件 加上一句(本来就有这句,只需要修改一下就行了) locatio ...

  5. tpadmin的坑收集 nginx下配置tp5失败

    如下: 1.ADMIN模块如要关联查询,model的函数名一定不要有“_”下划线,否则找不到 /common/model/**.php 如果把函数名file写成“**_file”,调用时,$vo.** ...

  6. nginx下配置多个web服务

    参考 nginx配置详解  nginx反向代理与负载均衡详解 一.nginx简介: Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能 ...

  7. Nginx下配置ThinkPHP的URL Rewrite模式和pathinfo模式支持

    前面有关于lnmp环境的搭建,在此就不在赘述.下面就简述thinkPHP如何在nginx下开启url_rewrite和pathinfo模式支持 主要有两个步骤: 一.更改php.ini将;cgi.fi ...

  8. nginx下配置二级域名指向子目录

    今天终于把nginx的二级域名配置搞定了,哎之前在测试服务器上弄过一次,不过那个是在本地解析的hosts,把ip指向到域名上就ok,再在nginx.conf里改了下配置就好了,用同样的方法改了正式服务 ...

  9. Nginx下配置虚拟主机的三种方法

    Nginx下,一个server标签就是一个虚拟主机. 1.基于域名的虚拟主机,通过域名来区分虚拟主机——应用:外部网站 2.基于端口的虚拟主机,通过端口来区分虚拟主机——应用:公司内部网站,外部网站的 ...

随机推荐

  1. c++ 十进制、十六进制和BCD的相互转换,与打印printf,与函数调用

    转载: https://blog.csdn.net/sjhuangx/article/details/49947179   c++ 十进制.十六进制和BCD的相互转换 https://blog.csd ...

  2. 使用HTML的基本结构创建网页

    1.       网页的扩展名--html或htm 2.       如何新建网页? 步骤1: 在电脑的空白处,右键选择-->新建--文本文档 步骤2: 把txt的扩展名,改成html或htm, ...

  3. Jmeter之连接数据库

    1.下载mysql驱动文件 2.移动到Jmeter目录下的lib中 3.在配置文件中使用 jdbc:mysql://127.0.0.1:3306/fns_test_bak?useUnicode=tru ...

  4. 启动VNC Shell扩展

    下载source files - 18.3 Kb Introduction 我们使用RealVNC来远程控制我们的网络中的pc机,VNC是一个伟大的产品,但如果不记住计算机名称,它可以是乏味的,在网络 ...

  5. 多测师讲解rf _基本使用002_高级讲师肖sir

      在你安装好RF-ride之后,桌面就会生成一个RIDE图标.双击启动,界面如下:  

  6. 比特币PoW

    比特币区块头结构 字段 大小(Byte) 说明 nVersion 4 区块版本号,表示本区块遵守的验证规则 hashPrevBlock 32 前一区块的哈希值,使用SHA256(SHA256(父区块头 ...

  7. COMET —— 常识Transformer用于自动知识图构建

    <COMET:Commonsense Transformers for Automatic Knowledge Graph Construction> 论文地址 论文源码 任务 目的层面 ...

  8. MySQL数据库基础-3-SQL 基本概念

    SQL 基本概念 约束:constraint,表中的数据要遵守的限制 主键:一个或多个字段的组合,填入的数据必须能在本表中唯一标识本行:必须提供数据,即NOT NULL,一个表只能有一个 惟一键:一个 ...

  9. Java进阶--Java动态代理

    JDK version: 1.8 动态代理中所说的"动态", 是针对使用Java代码实际编写了代理类的"静态"代理而言的, 它的优势不在于省去了编写代理类那一点 ...

  10. JavaWeb学习笔记(六)jsp

    第六章.jsp 1.什么是jsp jsp:java server pages,java的服务器页面 作用:代替Servlet回传HTML页面的数据 因为Servlet程序回传HTML页面的数据很繁琐, ...