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;
}
nginx下配置php5和php7的更多相关文章
- 如何在Nginx下配置PHP程序环境
1.nginx与PHP的关系 首先来看nginx与php的关系, FastCGI的关系(而不是像apache那样安装成nginx的模块) FastCGI的意思是, 快速的通用网关接口:CGI Comm ...
- NGINX下配置404错误页面的方法分享
NGINX下配置自定义的404页面是可行的,而且很简单,只需如下几步,需要的朋友可以参考下 1. 创建自己的404.html页面 2.更改nginx.conf在http定义区域加入: fastcg ...
- Ubuntu Nginx下配置网站ssl实现https访问
最近在看 HTTP权威指南 看到介绍了HTTPS的ssl,自己就动手测试了下,将步骤记录下 HTTPS简介 什么是HTTPS?百科是这样解释的.HTTPS(全称:Hyper Text Trans ...
- codeigniter(ci)在nginx下返回404的处理方法即codeigniter在nginx下配置方法
codeigniter(ci)在nginx下返回404的处理方法即codeigniter在nginx下配置方法 进入nginx的配置文件 加上一句(本来就有这句,只需要修改一下就行了) locatio ...
- tpadmin的坑收集 nginx下配置tp5失败
如下: 1.ADMIN模块如要关联查询,model的函数名一定不要有“_”下划线,否则找不到 /common/model/**.php 如果把函数名file写成“**_file”,调用时,$vo.** ...
- nginx下配置多个web服务
参考 nginx配置详解 nginx反向代理与负载均衡详解 一.nginx简介: Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能 ...
- Nginx下配置ThinkPHP的URL Rewrite模式和pathinfo模式支持
前面有关于lnmp环境的搭建,在此就不在赘述.下面就简述thinkPHP如何在nginx下开启url_rewrite和pathinfo模式支持 主要有两个步骤: 一.更改php.ini将;cgi.fi ...
- nginx下配置二级域名指向子目录
今天终于把nginx的二级域名配置搞定了,哎之前在测试服务器上弄过一次,不过那个是在本地解析的hosts,把ip指向到域名上就ok,再在nginx.conf里改了下配置就好了,用同样的方法改了正式服务 ...
- Nginx下配置虚拟主机的三种方法
Nginx下,一个server标签就是一个虚拟主机. 1.基于域名的虚拟主机,通过域名来区分虚拟主机——应用:外部网站 2.基于端口的虚拟主机,通过端口来区分虚拟主机——应用:公司内部网站,外部网站的 ...
随机推荐
- js 正则表达式 判断val是不是整数
function isIntNum(val){ var regPos = / ^\d+$/; // 非负整数 // var regNeg = /^\-[1-9][0-9]*$/; // 负整数 if( ...
- JVM 第五篇:命令行 JVM 故障处理工具
本文内容过于硬核,建议有 Java 相关经验人士阅读. 1. 引言 虽然我们前面介绍了各种图形化 JVM 故障处理工具,但是很多情况下,我们在处理问题的时候并没有图形化的操作环境可以使用,这时候,就需 ...
- Fabric1.4.4 多机solo共识搭建
简单记录一下fabric版本1.4.4的搭建部署,运行环境为CentOs7.8,如有错误欢迎批评指正.然后就是本编文章不对环境搭建做说明,基础环境搭建看这里. 1.总体设计 本案例部署一个排序(ord ...
- Python+Appium自动化测试(5)-appium元素定位常用方法
对于Android而言,查找appUI界面元素属性的工具有三种:appium desktop,uiautomatorviewer.bat,weditor.之前已经介绍过了weditor的使用,这里我将 ...
- 2017年 实验五 B2B模拟实验
实验五 B2B模拟实验 [实验目的] ⑴.掌握B2B中供应商的供求信息发布.阿里商铺开设和订单交易等过程. ⑵.掌握B2B中采购商的采购信息的发布.交易洽谈.网上支付和收货等过程. [实验条件] ⑴ ...
- day36 Pyhton 网络编程03
一.内容回顾 socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过"套接字"向网络发出请求或者应答网络请求. sock ...
- 基于SpringAop的鉴权功能
什么是 AOP 首先我们先了解一下什么是AOP,AOP(Aspect Orient Programming),直译过来就是面向切面编程.AOP是一种编程思想,是面向对象编程(OOP)的一种补充.面向对 ...
- sublime python配置运行
1.安装python环境 安装完成时,Win+R → 输入cmd → Enter → 调出来命令行,输入python确认安装是否成功. 2.安装sublime 3.打开sublime,选择工具--编译 ...
- 【纯水题】CF 833A The Meaningless Game
题目大意 洛谷链接 现在两个人做游戏,每个人刚开始都是数字\(1\),谁赢了就能乘以\(k^2\),输的乘以\(k\),现在给你最终这两个人的得分,让你判断是否有这个可能,有可能的话输出Yes,否则输 ...
- spring boot:方法中使用try...catch导致@Transactional事务无效的解决(spring boot 2.3.4)
一,方法中使用try...catch导致@Transactional事务无效的解决方法 1,问题的描述: 如果一个方法添加了@Transactional注解声明事务, 而方法内又使用了try catc ...