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.基于端口的虚拟主机,通过端口来区分虚拟主机——应用:公司内部网站,外部网站的 ...
随机推荐
- 《C++primerplus》第4章练习题
注:略过部分题目,修改了题设要求,实现差不多的功能 1.使用字符数组.要求用户输入姓名,等第和年龄,输出其姓名和年龄,等第降一级(即字母高一级). #include<iostream> u ...
- Jmeter之『Xpath提取器』
1.使用Xpath提取时,有时候需要过滤标题,使用以下语句 //td[@class="r-count" and not(text()="回应")]
- JVM 第三篇:Java 类加载机制
本文内容过于硬核,建议有 Java 相关经验人士阅读. 1. 什么是类的加载? 类的加载指的是将类的 .class 文件中的二进制数据读入到内存中,将其放在运行时数据区的方法区内,然后在堆区创建一个 ...
- laravel 500错误的一种可能
报这个错误,我一度认为,再加上,百度,大家都说是配置有问题,经过我不断地问我学长,结果就是一个小错误,简直太丢人了. 居然是少了一个括号的问题,自闭了
- day64 Pyhton 框架Django 07
day67 内容回顾 视图 1. CBV 定义 from django.views import View class Addpub(View): def get(self,request): sel ...
- CentOS7克隆多个虚拟机
VMware+centos7克隆虚拟机 步骤一:打开虚拟机,右键选中已经配置好的虚拟机,选择manage下面的clone选项.这里有一个需要注意的地方,就是虚拟机在启动或者挂起的状态下是不能clone ...
- 这里有40条提升编程技能小妙招!还有TIOBE 7月份的编程语言排行榜
如何提高编程技能?恐怕很多开发者思考过这个问题.最近,拥有将近 15 年开发经验的软件工程师 Kesk -*- 写了一篇博客,列举了 40 条对其职业生涯有所帮助的事项. 或许,通过以下 40 个 ...
- centos8平台nginx服务配置打开文件限制max open files limits
一,nginx启动时提示打开文件数,ulimit的配置不起作用: 1, 2020/04/26 14:27:46 [notice] 1553#1553: getrlimit(RLIMIT_NOFILE) ...
- PHP SPL标准库-迭代器
通过某种统一的方式遍历链表或者数组中的元素的过程叫做迭代遍历,这种统一的遍历工具我们叫做迭代器. PHP中迭代器是通过Iterator 接口定义的. ArrayIterator迭代器 foreach ...
- 第三章 TCP/IP 模型
一.产生背景 1.伴随着计算机网络的飞跃发展,各大厂商根据自己的协议生产出了不同的硬件和软件 2.为了实现网络设备间的互相通讯,ISO和IEEE相继提出了OSI参考模型及其TCP/IP模型 二.TCP ...