缘由

经常会有人问xx框架怎么配置运行环境,这里我就给贴出吉祥三宝(Yii2,Laravel5,Thinkphp5 )的Nginx和Apache的配置,供大家参考

Nginx

Yii2

server {    
    charset utf-8;    
    client_max_body_size 128M;    
    listen 80;    
    server_name yii.local.test;    
    root  /home/www/yii2/web;    
    index  index.php;    
    
    location ~* \.(eot|otf|ttf|woff)$ {    
        add_header Access-Control-Allow-Origin *;    
    }    
    
    location / {    
        try_files $uri $uri/ /index.php?$args;    
    }   
     
    location ~ \.php$ {    
        include   fastcgi_params;
        fastcgi_index    index.php;
        fastcgi_param    SCRIPT_FILENAME    $document_root$fastcgi_script_name;    
        fastcgi_pass   127.0.0.1:9000;    
        try_files $uri =404;    
    }    
}

Laravel5

server {    
    charset utf-8;    
    client_max_body_size 128M;    
    listen 80;    
    server_name laravel.local.test;    
    root  /home/www/laravel/public;    
    index  index.php;    
    
    location ~* \.(eot|otf|ttf|woff)$ {    
        add_header Access-Control-Allow-Origin *;    
    }    
    
    location / {    
        try_files $uri $uri/ /index.php?$args;    
    }   
     
    location ~ \.php$ {    
        include   fastcgi_params;
        fastcgi_index    index.php;
        fastcgi_param    SCRIPT_FILENAME    $document_root$fastcgi_script_name;    
        fastcgi_pass   127.0.0.1:9000;    
        try_files $uri =404;    
    }    
}

ThinkPHP5

server {    
    charset utf-8;    
    client_max_body_size 128M;    
    listen 80;    
    server_name tp5.local.test;    
    root  /home/www/tp5/public;    
    index  index.php;    
    
    location ~* \.(eot|otf|ttf|woff)$ {    
        add_header Access-Control-Allow-Origin *;    
    }    
    
    location / {    
        index    index.html index.php;    
        if ( -f $request_filename) {    
            break;    
        } 
       
        if ( !-e $request_filename) {    
            rewrite ^/(.*)$ /index.php/$1 last;    
            break;    
        }    
    }    
    
    location ~ \.php {    
        set $script $uri;    
        set $path_info "";    
        if ($uri ~ "^(.+\.php)(/.+)") {    
            set $script $1;    
            set $path_info $2;    
        }    
    include   fastcgi_params;    
    fastcgi_index    index.php?IF_REWRITE=1;    
    fastcgi_pass   127.0.0.1:9000;    
    fastcgi_param    PATH_INFO    $path_info;    
    fastcgi_param    SCRIPT_FILENAME    $document_root$fastcgi_script_name;    
    fastcgi_param    SCRIPT_NAME    $script;    
    try_files $uri =404;    
    }    
}

PS:tp5在nginx支持这块做的不够好,因为tp框架需要依赖一个服务变量 path_info ,这个变量nginx已经不再使用了,所以需要自己定义

Apache

Yii2

<VirtualHost *:8888>    
    ServerName yii.local.test    
    DocumentRoot /home/www/yii2/web    
    #<Directory "/home/www/yii2/web">    
            #RewriteEngine on    
            #RewriteCond %{REQUEST_FILENAME} !-f    
            #RewriteCond %{REQUEST_FILENAME} !-d    
            #RewriteRule . index.php    
    #</Directory>       
</VirtualHost>

PS: .htaccess 代码如下

RewriteEngine on    
# If a directory or a file exists, use it directly    
RewriteCond %{REQUEST_FILENAME} !-f    
RewriteCond %{REQUEST_FILENAME} !-d    
# Otherwise forward it to index.php    
RewriteRule . index.php

Laravel5

<VirtualHost *:8888>    
        ServerName laravel.local.test    
        DocumentRoot /home/www/laravel/public    
        #<Directory "/home/www/laravel/public">    
            #RewriteEngine on    
            #RewriteCond %{REQUEST_FILENAME} !-f    
            #RewriteCond %{REQUEST_FILENAME} !-d    
            #RewriteRule . index.php    
        #</Directory>    
</VirtualHost>

PS: .htaccess 代码如下

<IfModule mod_rewrite.c>    
    <IfModule mod_negotiation.c>    
        Options -MultiViews    
    </IfModule>    
    RewriteEngine On    
    # Redirect Trailing Slashes If Not A Folder...    
    RewriteCond %{REQUEST_FILENAME} !-d    
    RewriteRule ^(.*)/$ /$1 [L,R=301]    
    # Handle Front Controller...    
    RewriteCond %{REQUEST_FILENAME} !-d    
    RewriteCond %{REQUEST_FILENAME} !-f    
    RewriteRule ^ index.php [L]    
</IfModule>

ThinkPHP5

<VirtualHost *:8888>    
    ServerName tp5.local.test    
    DocumentRoot /home/www/tp5/public/     
</VirtualHost>

PS: .htaccess 代码如下

<IfModule mod_rewrite.c>    
    Options +FollowSymlinks -Multiviews    
    RewriteEngine On    
    RewriteCond %{REQUEST_FILENAME} !-d    
    RewriteCond %{REQUEST_FILENAME} !-f    
    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]    
</IfModule>

最后

希望对大家有帮助

原文地址:【nginx,apache】thinkphp ,laravel,yii2开发运行环境搭建
标签:nginx   mvc   thinkphp   tp   yii   yii2   laravel   艺术家   apache   运行环境   开发环境

智能推荐

【nginx,apache】thinkphp ,laravel,yii2开发运行环境搭建的更多相关文章

  1. .net core 2.0学习笔记(一):开发运行环境搭建

    期待已久的.net core 2.0终于发布了!大家等的花儿都谢了. 不过比预期提前了一个多月,这在微软历史上还真的不多见.按照历史经验看,2.0版本应该比较靠谱,我猜这也是社区非常火爆的原因吧.下面 ...

  2. net core 2.0学习笔记(一):开发运行环境搭建 (转)

    期待已久的.net core 2.0终于发布了!大家等的花儿都谢了. 不过比预期提前了一个多月,这在微软历史上还真的不多见.按照历史经验看,2.0版本应该比较靠谱,我猜这也是社区非常火爆的原因吧.下面 ...

  3. PHP - CentOS下开发运行环境搭建(Apache+PHP+MySQL+FTP)

    本文介绍如何在 Linux下搭建一个 PHP 环境.其中 Linux 系统使用是 CentOS 7.3,部署在阿里云服务器上.   1,连接登录服务器 拿到服务器的 ip.初始密码以后.我们先通过远程 ...

  4. .net core 2.0小白笔记(一):开发运行环境搭建

    小白一枚,有任何不妥之处敬请指教 这里不讨论什么设计模式,什么架构,什么什么,就是入门,简单的入门,虽然能跨平台,但是这里还是在win的环境下进行,不扯的那么远 其实官网文档写的挺不错的了,就是偶尔有 ...

  5. windows安装React Native开发运行环境

    React Native是什么 React Native是facebook开源的一个用于开发app的框架.React Native的设计理念:既拥有Native (原生) 的用户体验.又保留React ...

  6. 【Hadoop离线基础总结】Apache Hadoop的三种运行环境介绍及standAlone环境搭建

    Apache Hadoop的三种运行环境介绍及standAlone环境搭建 三种运行环境 standAlone环境 单机版的hadoop运行环境 伪分布式环境 主节点都在一台机器上,从节点分开到其他机 ...

  7. Hadoop基础教程-运行环境搭建

    一.Hadoop是什么 一个分布式系统基础架构,由Apache基金会所开发.用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和存储. Hadoop实现了一个分布式 ...

  8. PHP学习(2)——运行环境搭建

    学习PHP首先要搞定PHP的运行环境.PHP的运行环境包括:PHP语言解析器本身以及Apache服务器.MySQL数据库等.因为只是学习嘛,尽快的搭建起来运行环境就好,到后期慢慢懂得多了再去想规范化搭 ...

  9. 高并发 Nginx+Lua OpenResty系列(1)——环境搭建

    OpenResty是一款基于Nginx的高性能负载均衡服务器容器,简单来说是Nginx+Lua.结合了Lua语言来对Nginx进行扩展,使得在Nginx上具有web容器功能. OpenResty运行环 ...

随机推荐

  1. linux每日命令(37):top命令

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法.top是一个动态显示过程,即可以通过用户按键来不断刷新 ...

  2. 【iCore4 双核心板_ARM】例程二十一:LWIP_TCP_SERVER实验——以太网数据传输

    实验现象: 核心代码: int main(void) { system_clock.initialize(); led.initialize(); adc.initialize(); delay.in ...

  3. 使用apktool.jar工具反编译和回编译Android APK 终端命令模式

    1.工具准备 工具可以网上搜索下载新版本,也可以从这里Download:https://github.com/FlymeOS/tools/blob/lollipop-5.1/reverses/apkt ...

  4. Git 审查更改

    但查看提交详细资料后,Jerry 实现字符串的长度不能为负数,所以他决定改变my_strlen函数的返回类型. Jerry 使用git日志命令来查看日志信息. [jerry@CentOS projec ...

  5. hdoj:2043

    #include <iostream> #include <string> using namespace std; bool judgeSize(string str) { ...

  6. (原创)Python文件与文件系统系列(1)—— file 对象

    本系列将从四个部分简单介绍Python对文件系统的操作与支持: 1. Python内置的 file 对象 2. Python的os模块对文件.文件系统操作的支持 3. Python的os.path模块 ...

  7. Mysql 查看连接数,状态 最大并发数 && 怎么设置才合理

    show status like '%max_connections%'; ##mysql最大连接数 set global max_connections=1000 ##重新设置 show varia ...

  8. U3D 垂直同步

    Unity3D中新建一个场景空的时候,帧速率(FPS总是很低),大概在60~70之间.一直不太明白是怎么回事,现在基本上明白了.我在这里解释一下原因,如有错误,欢迎指正.在Unity3D中当运行场景打 ...

  9. Python代码统计工具

    目录 Python代码统计工具 声明 一. 问题提出 二. 代码实现 三. 效果验证 Python代码统计工具 标签: Python 代码统计 声明 本文将对<Python实现C代码统计工具(一 ...

  10. 推荐一款好用的文件/文件夹对比工具 —— Beyond Compare

    推荐一款好用的文件/文件夹对比工具 —— Beyond Compare! 有需要的人,用了都说好: 不知道这个是干嘛用的,说再多也没用.