PHP Advent Calendar 2020 - Day 2

銇点亞銇涖倱馃巿 FU-SEN 銇ㄧ敵銇椼伨銇欍
Qiita Advent Calendar 銇銆呫仾銇ㄣ亾銈嶃伀鍙傚姞銇椼仸銇勩倠銇仹銇欍亴銆
PHP 銇亾銈屻亴鍒濆弬鍔犮倝銇椼亜銇с仚銆傘亗銈岋紵
銇娿仢銈夈亸鍙傚姞銇椼倛銇嗐仺鎬濄仯銇︺仚銇с伀鍩嬨伨銇c仸銇熴伄銇犮仺鎬濄亜銇俱仚銇屸︹

PHP 銇叡鐢ㄣ儸銉炽偪銉偟銉笺儛銇с倐瀵惧繙銇椼仸銇勩倠浜嬨亴澶氥亸銆
姣旇純鐨勫嫊浣溿仚銈嬨偟銉笺儛銇屽銇勩儣銉偘銉┿儫銉炽偘瑷瑾炪亱銇ㄦ濄亜銇俱仚銇屻
灏戙仐銇с倐瀹夊ゃ仹妲嬬瘔銇椼仸鍏枊銇椼仸銇娿亶銇熴亜浜恒倐銇勩倠銇嬨仺鎬濄亜銇俱仚銆
銈撱仒銈冦佺劇鏂欍仹 PHP 銇屼娇銇堛倠銇ㄣ亾銈嶃倰绱逛粙銇椼伨銇椼倗銇嗐 鈻睼ercel 銇с仚銆


鈻睼ercel 锛

Develop. Preview. Ship. For the best frontend teams 鈥 Vercel

鐭ャ倝銇亜锛熲︹︺亪銇c仺銇с仚銇亣銆2020 骞村悕绉般亴澶夈倧銇c仧銈点兗銉撱偣銇с仐銇︺
浠ュ墠銇祫绻斿悕銇 ZEIT锛堛儎銈°偆銉堬級銆併偟銉笺儞銈瑰悕銇 Now 銇ㄣ亜銇嗗悕鍓嶃仹銇椼仧銆
銇撱倢銇с倧銇嬨仯銇熶汉銇屻亜銈嬨亱銈傘仐銈屻伨銇涖倱銆傗柌 銇綋鍒濄亱銈変娇銈忋倢銇︺亜銇俱仚銇仹銆

Now 銇ㄣ仐銇﹀叕闁嬨仌銈屻仧褰撳垵銇潤鐨勩偝銉炽儐銉炽儎銇伩銇с仐銇熴亴銆
寰屻伄 Now v2 銇ф寮忓嫊鐨勩偝銉炽儐銉炽儎銇嫊浣溿伀瀵惧繙銇椼伨銇椼仧銆
浠娿伅鍕曠殑銈炽兂銉嗐兂銉勩伀浣裤倧銈屻倠鐢ㄩ斻伄鏂广亴澶氥亜銈撱仒銈冦仾銇勩亱銇ㄦ濄亜銇俱仚銆

Pricing 鈥 Vercel

鐒℃枡銇т娇銇堛倠绡勫洸銇屻仺銇︺倐搴冦亜銇с仚銆 闁嬬櫤鑰呫亴瀹熼〒鐨勩仾銈炽兂銉嗐兂銉勩仩銇c仧銈娿
銇傘倠绋嬪害銇枊鐧恒仌銈屻仧銈炽兂銉嗐兂銉勩伅鐒℃枡銇т娇鐢ㄣ仹銇嶃倠浠曠祫銇裤伀銇椼仸銇傘倞銇俱仚銆
Let’s Encrypt 銇 SSL 鍖栥倐銇椼伨銇欍仐銆佺嫭鑷儔銉°偆銉炽倐閬╃敤銇с亶銇俱仚銆

Vercel in Tokyo 鈥 Vercel

銈点兗銉愩亴涓栫晫涓伀銇傘倞銆併仢銇竴銇ゃ仺銇椼仸鏉变含銇ō缃仐銇︺亗銈娿伨銇欍
銈€偢銈㈠垵銆乂ercel 鍐呫仹銈 5 銉舵墍鐩伀瑷疆銇椼仸銇勩伨銇欍
銇濄伄浠曠祫銇裤伅锛熲︹﹀疅銇 AWS 銈 GCP 銈掍娇鐢ㄣ仐銇︺亗銇c仸銆
浣跨敤鐘舵硜銇倛銇c仸銈点兗銉愩倰鍕曠殑銇鍖栥仌銇涖仸銇勩倠銈忋亼銇с仚銆
銈儵銈︺儔銈点兗銉撱偣銈掋儠銉椿鐢ㄣ仐銇︺亜銈嬨倱銇с仚銇

Download Vercel CLI 鈥 Vercel

鍏枊鏂规硶銇 CLI 銈掔敤銇勩仸 vercel 銈炽優銉炽儔銇у叕闁嬨仚銈嬨亱鈥︹

Git - Vercel Documentation

銇俱仧銇 GitHub銉籊itlab銉籅itbucket 銇倛銈 Git 閫e嫊銇屼娇鐢ㄣ仹銇嶃伨銇欍
闁嬬櫤鑰呫倝銇椼亸銈枫偋銉兓銈裤兗銉熴儕銉亱銈夈偝銉炪兂銉夈仹绨″崢銇叕闁嬨仚銈嬩簨銇屻仹銇嶃伨銇欍


鈻睼ercel 銇 PHP 銈掑嫊銇嬨仚鏂规硶

銆屻亗銈岋紵銇с倐 Vercel 銇c仸 PHP 銇蹇溿仐銇︺仾銇勩倱銇樸們銇亜銇紵銆

Supported Languages for Serverless Functions - Vercel Documentation

銇堛亪銆佸叕寮忋伀銇銇蹇溿仾銇仹銇欍

  • Node.js
  • Go
  • Python
  • Ruby

銇撱倢銇倝 PHP 銈傚蹇溿仐銇︺仸銈傘亰銇嬨仐銇忋仾銇曘仢銇嗐仾銇仹銇欍亴銆
鍏紡銇伅瀵惧繙銇椼仸銇勩伨銇涖倱銆

銇с倐銇斿畨蹇冦倰銆 Community Runtimes 銇ㄣ仐銇 PHP 銇屽嫊浣溿仚銈嬩粫绲勩伩銇屻亗銈嬨倱銇с仚銆

聽PHP Runtime for Vercel - juicyfx/vercel-php | GitHub

鍕曘亱銇欍仧銈併伀銇仭銈囥仯銇ㄥ伐澶亴蹇呰銇с仚銆
鍏枊銇欍倠銉囥偅銉偗銉堛儶銉汇儠銈┿儷銉銈掔敤鎰忋仐銇俱仚銆傘仢銇洿涓嬨伄 vercel.toml 銈掍綔鎴愩仐銆
娆°伄銉嗐偔銈广儓銈掑叆銈屻伨銇欍

{
  "regions": ["hnd1"],
  "functions": {
    "api/*.php": {
      "runtime": "vercel-php@0.3.1"
    }
  },
  "routes": [
    { "src": "/(.*)", "dest": "/$1" },
    { "handle": "filesystem" },
    { "src": "/.*", "dest": "/404.html" }
  ]
}

regions 銇澅浜偟銉笺儛 hnd1 銈掕ō瀹氥仐銇俱仚銆傛棩鏈弬鐓у悜銇戙仹銇欍伃銆
鐒℃枡銇у嫊鐨勩偝銉炽儐銉炽儎銇牬鍚堛伅 1 銉舵墍鎸囧畾銇仾銈嬨仧銈併佹寚瀹氥仐銇︺亰銇忋仺鑹亜銇с仚銆

functionsapi/ 鍐呫伀銇傘倠 .php 銉曘偂銈ゃ儷銇 PHP 銈掑疅琛屻仐銇俱仚銆
鍕曠殑銉曘偂銈ゃ儷銇 api/ 鍐呫仹銇疅琛屻亴蹇呴爤銇ㄣ仾銈娿伨銇欍

routes 銇儠銈°偆銉亴銇亜鍫村悎銇 404.html 銈掕〃绀恒仚銈嬭ō瀹氥仹銇欍
渚嬨亪銇 404.html 銇唬銈忋倞銇 api/index.php 銇ㄣ仚銈嬩簨銈傘仹銇嶃伨銇欍

vercel.json 銇 Apache 銇 .htaccess 銇浉褰撱仚銈嬮儴鍒嗐仹銆
HTTP 銉樸儍銉銇拷鍔犮倓杌㈤併仾銇┿佺窗銇嬨亸鍒跺尽銇屽彲鑳姐仹銇欍

api/ 銉囥偅銉偗銉堛儶锛堛儠銈┿儷銉锛夈倰浣滄垚銇椼佹洿銇仢銇腑銇 phpinfo.php 銈掍綔鎴愩仐銆
銇濄伄涓伀鍏ャ倢銇俱仚銆

<?php
phpinfo();

銇с伅鍏枊銇椼仸銇裤伨銇椼倗銇嗐
鍏枊銇欍倠銇伅 CLI 銇у叕闁嬨仚銈嬨亱銆丟it 銇搞伄鍏枊銇仾銈娿伨銇欍
Git 銇搞伄鍏枊銇儣銉偢銈с偗銉堛倰閫f惡銇曘仜銇熺姸鎱嬨仹 git push 銇ф洿鏂般仚銈屻伆鑹亜銇仹銆
vercel.json 銇屽叆銇c仸銇勩倠蹇呰銇屻亗銈娿伨銇欙級
銇撱亾銇с伅 CLI 銈掔垂浠嬨仐銇︺亰銇嶃伨銇椼倗銇嗐

vercel --prod

銇ㄣ仐銇俱仚銆--prod 銇屻仾銇勫牬鍚堛伅鍏枊鍓嶃伄纰鸿獚鍚戙亼銇с仚銆

vercel –prod 銈掑疅琛

銇с伅 Web 銈点偆銉堛仹纰鸿獚锛侊紙銇撱亾銇с伅 api/info.php 銇仐銇︺亜銇俱仚锛

phpinfo 銈掕〃绀

phpinfo 銇屽叕闁嬨仌銈屻仸銇勩伨銇欍侾HP 銇屽嫊浣溿仐銇︺亜銈嬨伄銈掔⒑瑾嶃仹銇嶃伨銇椼仧銆

馃巿 Vercel锛坴ercel.com銉籿ercel.app锛 | 銇点亞銇涖倱馃巿 FU-SEN

銈傘亞銇°倗銇c仺瑭崇窗銇鏄庛伅銇撱仭銈夈仹瑷樿級銇椼仸銇傘倞銇俱仚銆


鐒℃枡銇сPHP 銇屼娇銇堛倠銈点兗銉撱偣銇粬銇倐銇傘倠銇仹銇欍亴鈥︹

  • Heroku
    鈫 鍏枊銈点兗銉愩亴娆х背銇с佺劇鏂欍伅鏈澶 1 銉椼儹銈搞偋銈儓甯告檪銆
  • Google App Engine锛圙oogle Cloud Platform锛
    鈫 銉愩兗銈搞儳銉炽亴鍙ゃ倎銇с佹皸銇屻仱銇戙伆瑾查噾銇曘倢銈嬪彲鑳芥с亴銇傘倠銆
  • Google Cloud Run锛圙oogle Cloud Platform锛
    鈫 App Engine 銈堛倞銈傝閲戙亴銇倓銇忋併儑銉椼儹銈ゃ伄鎵嬮枔銇屻亱銇嬨倠銆
  • Glitch銉籖eplit
    鈫 OS 銉戙儍銈便兗銈搞仢銇伨銇俱仹銉愩兗銈搞儳銉炽亴鍙ゃ亜銆

涓闀蜂竴鐭仾銇ㄣ亾銈嶃亴銇傘倞銇俱仚銆

Glitch銉籖eplit 銇娇鐢ㄧ祵楱撹呫亴灏戙仾銇勩仺鎬濄亜銇俱仚銆傜垂浠嬨儦銉笺偢銈掋儶銉炽偗銇椼仸銇娿亶銇俱仚銆

鈻睼ercel 銇亾銈屻倝銇瘮銇广倠銇ㄣ佹暦灞呫亴浣庛亸銇︺佹澅浜偟銉笺儛銈傘亗銈嬨伄銇с
浣裤亜銈勩仚銇勩仺鎬濄仯銇︺亜銇︺佷粖鍥炵垂浠嬨仐銇︺亜銇俱仚銆
姘椼伀銇倠浜恒伅涓娿伀绱逛粙銇椼仧銈点兗銉撱偣銈傝│銇椼仸銇裤仸涓嬨仌銇勩


杩藉姞 2021/02/26

PHP Advent Calendar 2020 銇с伅 PHP8 銇┍椤屻亴澶氥亱銇c仧銇仹銆
銇娿仢銈夈亸姘椼伀銇椼仸銇勩倠浜恒倐銇勩倠銇嬨仺鎬濄亜銇俱仚銆

聽Bump: v0.4.0 路 GitHub juicyfx/vercel-php@c2e01b5

2021骞1鏈2鏃 銇 vercel-php 銇 0.4.0 銇仾銇c仸銇勩仸銆
銇撱伄銈裤偆銉熴兂銈般仹 PHP8 銇у嫊浣滃彲鑳姐伀銇仯銇︺亜銇俱仚銆
鈥︹︺伅銇勩 銇欍仹銇 鈻睼ercel 銇 PHP8 銇屼娇銇堛伨銇欍

vercel.jsonruntime 銇ц杓夈仐銇︺亜銈
vercel-php 銇儛銉笺偢銉с兂銈掑鏇淬仐銇︿笅銇曘亜銆

{
  "functions": {
    "api/*.php": {
      "runtime": "vercel-php@0.4.0"
    }
  }
}

銇撱倢銇 vercel 銇欍倠浜嬨仹 PHP8 銇仾銇c仸銇勩倠銇仛銇с仚銆

phpinfo 銈掕〃绀

鈥︹ vercel --prod 銇c仸鍏ャ倢銇︺仾銇勭悊鐢便倧銇嬨倞銇俱仚銈堛伃锛
銇勩亶銇倞 PHP7 銇嬨倝 PHP8 銇銇堛仸銆佸嫊銇嬨仾銇勫彲鑳芥с亴銇傘倞銇俱仚銇嬨倝銇
銇俱仛銇垾銇 URL 銇ц〃绀恒仹銇嶃倠銈堛亞銇仐銇︺佸嫊浣溿倰纰鸿獚銇椼仸銇嬨倝
vercel --prod 銇ф湰鐣挵澧冦伀鍙嶆槧銇欍倠銇仹銇欍倛銆
鈻睼ercel 銇仢銇撱伨銇ц冦亪銇︿綔銈夈倢銇︺亗銈嬨倱銇с仚銆


PHP Advent Calendar 2020

聽PHP Advent Calendar 2020 | Qiita