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.基于端口的虚拟主机,通过端口来区分虚拟主机——应用:公司内部网站,外部网站的 ...
随机推荐
- Flink深入浅出: 应用部署与原理图解(v1.11)
往期推荐: Flink深入浅出:内存模型 Flink深入浅出:JDBC Source从理论到实战 Flink深入浅出:Sql Gateway源码分析 Flink深入浅出:JDBC Connector源 ...
- Springboot集成logback,控制台日志打印两次,并且是不同的线程打印的
背景 在搭建一个新项目的时候,从公司别的项目搞了个logback-spring.xml的配置过来,修改一下启动项目的时候发现 所有的日志都输出了两次 并且来自于不同的线程,猜测是配置重复了,但是仔细检 ...
- Redis使用RDB持久化和AOF持久化的区别 - 小白之所见
- bash 在指定目录查找包含特定关键字的文件
比如我们要在目录/usr/local/nginx/conf/vhost/下查找baidu.com这个关键字的文件 方法1: find /usr/local/nginx/conf/vhost/ -exe ...
- [论文阅读]阿里DIN深度兴趣网络之总体解读
[论文阅读]阿里DIN深度兴趣网络之总体解读 目录 [论文阅读]阿里DIN深度兴趣网络之总体解读 0x00 摘要 0x01 论文概要 1.1 概括 1.2 文章信息 1.3 核心观点 1.4 名词解释 ...
- SpringBoot整合日志log4j2
SpringBoot整合日志log4j2 一个项目框架中日志都是必不可少的,随着技术的更新迭代,SpringBoot被越来越多的企业所采用.这里简单说说SpringBoot整合log2j2日志. 一. ...
- Windows环境下vscode Live Server插件如何开启https
0x01 vscode http插件 Live Server如何开启https 在本机端的开发环境下,如果要测试一些需要HTTPS的功能可以使用mkcert给自己颁发凭证 0x02 安装步骤如下: 1 ...
- c# 误区系列(二)
前言 继续整理误区系列,可能会对刚入门的新手有些帮助,然后希望有错误的地方可以指出. 正文 关于泛型方法的确定 class Person<T> { public void add(T a) ...
- Linux入门到放弃之五《用户管理》
用户管理 1.创建新用户user123,以此用户登陆系统,在tmp下创建文件test123: 2.修改test123文件的所有者为root,所属组也为root: 需要先切换为root用户 3.修改te ...
- maven 获取pom.xml的依赖---即仓库搜索服务
常用仓库地址: http://repository.sonatype.org/ (https://repository.sonatype.org/)如下图: http://www.mvnrepo ...