[Nginx, apache] thinkphp, laravel, yii2 run development environment to build

reason

Xx frame often asked how to configure the operating environment, where I'll put Lucky Sambo (Yii2, Laravel5, Thinkphp5) of Nginx and Apache configuration, for your reference


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 in nginx support this is not good enough, because tp framework needs to rely on a service variable path_info, nginx this variable is no longer used, so the need to define


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 code is as follows

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 code is as follows

<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 code is as follows

<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>

At last

I hope everyone has to help


Original Address: [nginx, apache] thinkphp, laravel, yii2 run development environment to build
Tags: nginx    MVC    thinkphp    TP    Yii    yii2    Laravel    artists    apache    operating environment    development environment   

Intelligent Recommendation

Reproduced in: https: //my.oschina.net/54php/blog/841713

Guess you like

Origin blog.csdn.net/weixin_34254823/article/details/91634747