laravel 5 增加一組route group 設定

我今天要增加一組route controller與 route檔案
名字叫ajax
要到 class RouteServiceProvider 修改
1.增加namespace
protected $cust_namespace = ‘App\Http\Controllers\ajax’;
2.
去map route增加一組設定
$this->mapAjaxRoutes();
3.增加method mapAjaxRoutes

protected function mapAjaxRoutes()
{
Route::prefix(‘ajax’)
->middleware(‘ajax’)
->namespace($this->cust_namespace)
->group(base_path(‘routes/ajax.php’));
}

 

完整設定會是這樣

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php 
namespace App\Providers; 
use Illuminate\Support\Facades\Route; 
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; 
class RouteServiceProvider extends ServiceProvider { 
/** * This namespace is applied to your controller routes. * * In addition, it is set as the URL generator's root namespace. * * @var string */ 
    protected $namespace = 'App\Http\Controllers'; 
    protected $cust_namespace = 'App\Http\Controllers\ajax'; /** * Define your route model bindings, pattern filters, etc. * * @return void */ 
 
     public function boot() { // parent::boot(); } 
 
     /** * Define the routes for the application. * * @return void */ 
    public function map() { $this->mapApiRoutes();
        $this->mapAjaxRoutes();
        $this->mapWebRoutes();
 
        //
    }
 
    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }
 
    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }
    /**
     * Define the "Ajax" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapAjaxRoutes()
    {
        Route::prefix('ajax')
            ->middleware('ajax')
            ->namespace($this->cust_namespace)
            ->group(base_path('routes/ajax.php'));
    }
}

apache php-fpm Primary script unknown\n

一直遇到這個問題 AH01071: Got error ‘Primary script unknown\n

搞了很久

基本上大致解決方向有三種

1.document_root路徑設定錯誤

2.php-fpm 的權限問題

-查php-fpm的user 與 group是否與apache相同

3.selinux || firwall等系統權限問題

4.ProxyPassMatch

這個坑真的很坑….

apache 2.4設定php-fpm

可以用的設定應該只有

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://0.0.0.0:9000/webroot/phptest/$1

大部分的網上文件多半說明需要配合此設定檔的DocumentRoot
but…並不完全是這樣的
apache的DocumentRoot是給apache用的
但是給fcgi後面的root,是要看你fcgi機器上的路徑
這件事情通常會是在docker上面發生
舉個例子
我已經在host 上面跑了apache+php 5.4 ,但我今天有一個網站要跑php 7.1
我考慮使用docker 跑php-fpm ,讓apache對連
這時候fcgi://host:port/{path} 裏頭的{path}是docker container內的路徑
如果你在host沒有共享DocumentRoot給docker內的container使用
你就顆顆了
ProxyPassMatch後面的路徑設定如果跟DocumentRoot不一致,那就會以ProxyPassMatch後面的路徑為主
你根本可不用設定DocumentRoot…

vmware在nat下的靜態ip設定-以centos7為例

1.找到Virtual Network Editor

在vmwere下找 vmnetcfg.exe

2.看dhcp與nat的範圍與他的geteway, 注意 geteway 的ip並非是你想的那個,看工具最準

或者用指令

ip route show

看geteway ip
再來 以centos 7 為例

1.檢查 Network Manager 是否啟動

systemctl status NetworkManager.service 

2.檢查使用的網卡

ip route show 

3.進入 nmtui 設定網路,若沒有則安裝

yum install NetworkManager-tui

 

4.重啟網路

systemctl restart network.service

5.ping google.com

安裝 php v8js in centos 7

為了完整性 建議手動安裝

1.先安裝工具包

yum groupinstall ‘Development Tools’

2.安裝git  python libglib2.0-dev

3.安裝depot_tools

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

export PATH=`pwd`/depot_tools:”$PATH”

4.下載v8

fetch v8 cd v8

5.設定 GN

tools/dev/v8gen.py -vv x64.release

echo is_component_build = true >> out.gn/x64.release/args.gn

6.編譯

ninja -C out.gn/x64.release/

7.安裝編譯好的檔案

sudo mkdir -p /opt/v8/lib

sudo mkdir -p /opt/v8/include

sudo cp out.gn/x64.release/lib*.so out.gn/x64.release/*_blob.bin /opt/v8/lib/

sudo cp -R include/* /opt/v8/include/

 

9.安裝v8js

git clone https://github.com/phpv8/v8js.git

cd v8js phpize ./configure –with-v8js=/opt/v8

make ; make install

10設定so

vim /etc/php.d/v8js.ini

extension=v8js.so

 

參考文件

 

https://github.com/phpv8/v8js/blob/master/README.Linux.md

 

 

nginx ssl 設定

這採用兩階段設定
第一步先拿到80 port 然後轉 443
話不多說 直接看設定檔

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
server {
  listen 80 ;
    server_name example.shop;
 
    # redirects both www and non-www to https
    return 301 https://$server_name$request_uri;
 
}
 
server {
 
    listen 443 ssl;
    server_name  example.shop;
 
    #ssl 設定
    ssl on;
    #ssl 認證 ,憑證中心發給的crt檔
    ssl_certificate /etc/nginx/ssl/example.shop.crt;
    #產生ssl的認證前 所使用的private key
    ssl_certificate_key /etc/nginx/ssl/example.shop.key;
    root   /var/www/public_html/;
    index  index.php index.html index.htm;
 
    error_log  /var/log/nginx/example.shop_error.log  warn;
 
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
 
    location ~ \.php$ {
        fastcgi_read_timeout 3600;
        fastcgi_pass   php-fpm-sock;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }
 
}

laravel validator note – unique與exists

laravel validator 這兩個功能非常的強大阿~~~

unique >輸入值必須是唯一值

exists >輸入值必須存在

他可以透過orm的方式讀取db資料,然後判斷輸入的值是否存在於資料表中,根本是大神級的好用阿

範例
id值必須存在否則輸出錯誤
exists:table名稱,欄位名稱

1
2
3
4
5
6
7
8
9
10
11
12
$info['id']=10; 
$validator = Validator::make(
            $info,
            [
                'id' => 'exists:table_name,id',
 
            ]
        );
if ($validator->fails()) {
            return response()->json(['status'=>422,'message'=>'Validate Error','errors'=>$validator->errors()],422,[],JSON_UNESCAPED_UNICODE);
 
}

範例
帳號是否存在,存在則輸出錯誤
unique :table名稱,欄位名稱

1
2
3
4
5
6
7
8
9
10
11
12
$info['username']='Mike'; 
$validator = Validator::make(
            $info,
            [
                'id' => 'unique :table_name,username',
 
            ]
        );
if ($validator->fails()) {
            return response()->json(['status'=>422,'message'=>'Validate Error','errors'=>$validator->errors()],422,[],JSON_UNESCAPED_UNICODE);
 
        }