【nginx,apache】thinkphp ,laravel,yii2开发运行环境搭建
2017-02-19 21:40
656 查看
缘由
经常会有人问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开发运行环境搭建
- 【nginx,apache】thinkphp ,laravel,yii2开发运行环境搭建
- Windows下的PHP开发环境搭建——PHP线程安全与非线程安全、Apache版本选择,及详解五种运行模式。
- 搭建LNAMP(Linux+Apache+Nginx+MySQL+PHP)前后端Web(PHP)开发环境
- Mac下快速搭建PHP开发环境,Apache,Nginx,MySQL
- Windows下的PHP开发环境搭建——PHP线程安全与非线程安全、Apache版本选择,及详解五种运行模式。
- 转:Windows下的PHP开发环境搭建——PHP线程安全与非线程安全、Apache版本选择,及详解五种运行模式。
- 用docker搭建php+nginx+laravel的开发环境
- php开发环境搭建——laravel框架,apache服务器,git版本控制
- laravel开发环境下的apache和nginx 配置文件
- Apache HTTP 及 PHP 开发及运行环境的搭建 (Windows)
- Windows下的PHP开发环境搭建——PHP线程安全与非线程安全、Apache版本选择,及详解五种运行模式。
- HHvm Apache 2.4 Nginx建站环境搭建方法安装运行WordPress博客
- Windows下的PHP开发环境搭建——PHP线程安全与非线程安全、Apache版本选择,及详解五种运行模式。
- php开发笔记-windows-linux-thinkphp开发环境搭建
- Eclipse下搭建Hadoop开发环境,并运行第一个实例
- php开发环境搭建 Apache+PHP+MySQL
- 伟哥教您Windows下手动搭建Laravel5.2开发环境Nginx+Php+MySQL
- Tomcat、Apache、IIS这三种Web服务器来讲述3种搭建JSP运行环境的方法
- windows搭建laravel开发环境