javck
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: laravel,套件 --- # 官方套件 Valet 介紹 ![](https://i.imgur.com/2LZOfG7.png) ## 教學文章 ### 前言 大家好,我是每天在空中陪著你的哥布林工程師,今天想要為大家分享你該如何去安裝Valet 或許有些人看到標題,不曉得甚麼是Valet,Valet是一個專為Mac開發者所做的Laravel開發環境,我自己使用上最方便的感受有兩點 * 第一 自動建立同名本地端網址 比如你新增一個名為blog的專案,那valet將會自動為你生成專案網址 http://blog.test * 第二 支援https 你或許會覺得奇怪,本地開發為什麼需要https。首先方便你測試整個應用在https協定下會不會有問題,接著當要測試臉書的社群登入串接,也是要求用https的。而Valet讓你不需要有任何負擔或太多的設定,就能開啟https協定 另外也省去你去安裝 Vagrant,也不需要設定 /etc/hosts檔案。你甚至能夠使用 local tunnels 來把你的網站對外分享,真的超讚! Laravel Valet會調校你的Mac環境,使之在機器開啟後就會在背景執行Nginx。接著,使用 DnsMasq,Valet會將網域類似 *.test的請求都指向到本機,這就是剛談到第一點的由來 換句話說,這一個高效的Laravel開發環境只需用到大約7MB的記憶體。Valet並非作為取代Vagrant或Homestead的替代方案,只是提供給你一個新的選項,假如你要的是較為簡單的功能,需要更快的速度,或者是在記憶體不多的開發機器。當然還有好多好多的好處,說也說不完 > 那Valet沒有缺點嗎?當然還是有 它最大的缺點就是目前只支援 Mac 作業系統,所以如果你是使用Windows作業系統的朋友,可以上一頁返回離開了。但是如果你真的很想體驗Valet,或許你可以考慮購買 Apple M1,網路風評效能很不錯呢! ### 開始打造Valet 接著我將用九個步驟來引導你一步步地把 Laravel Valet 安裝到你的Mac電腦上面,以下指令都需要你開啟Terminal視窗來進行輸入 #### Step 1.安裝/更新 Homebrew 等會安裝PHP會用到,所以沒裝過[Homebrew](https://brew.sh/index_zh-tw)的朋友要先進行安裝 開啟Terminal,貼上下面這段指令 `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"` 如果已經裝過brew,可以在現在順便做個更新,指令如下: `brew update` #### Step 2.安裝 PHP `brew install php` #### Step 3.安裝 Composer Composer是幫你管理PHP套件的工具,必須安裝。如果想更多的了解Composer,請參考[這裡](https://getcomposer.org/) 同樣開啟Terminal,輸入以下指令: `curl -sS https://getcomposer.org/installer | php` `mv composer.phar /usr/local/bin/composer` 為了方便之後在任何路徑都能夠順利地呼叫Composer,所以有必要將Composer執行檔路徑給放入環境變數PATH中,做法如下: 同樣開啟Terminal,輸入以下指令,將會跳出這個檔案的編輯視窗: `touch ~/.bash_profile; open ~/.bash_profile` 在.bash_profile檔案內加入以下內容,完成之後請按Command + Q 存檔離開: `export PATH=~/.composer/vendor/bin:/usr/local/bin:$PATH` 同樣開啟Terminal,輸入以下指令來執行剛編輯的設定而不需要重新開機 `source ~/.bash_profile` #### Step 4.下載 Valet 透過Composer來下載Valet,請確保~/.composer/vendor/bin有位在$PATH的環境變數裡頭,否則將出現找不到composer指令的錯誤 `composer global require laravel/valet` #### Step 5.安裝 Valet 在Terminal輸入以下指令來調校與安裝 Valet 和 DnsMasq,之後每次重新開機 Valet都會自動啟動開發所需的相關服務 `valet install` #### Step 6.確認安裝是否成功 透過測試DnsMasq能否生效來確認安裝有無問題,正常的話所有*.test的網域都會指向到本機 在 Terminal 輸入以下指令 `ping laravel.test`(laravel可替換為任何字) #### Step 7.安裝 MySql 資料庫 Laravel 8 的官網是推薦使用 DBngin ,但我使用上覺得不是很順,以下還是推薦使用 brew 來進行安裝,在 Terminal 輸入以下指令: `brew install mysql@5.7` > 如果你選擇使用 DBngin,可能會出現服務順利開啟但是無法連入的問題,這是因為密碼編碼的問題,可在連接上mysql之後使用以下指令: `ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';` #### Step 8.開啟 MySql 資料庫 在 Terminal 輸入以下指令: `brew services start mysql@5.7` 連接資料庫的相關口令為 127.0.0.1 root/空密碼 #### Step 9.指定網頁伺服器根目錄 切換到你將用來存放所有網頁應用的資料夾,例如 htdocs 或 sites 之類的。完成這個動作之後像是 pandalab.test 這樣的網址就會指向到 park 資料夾裏頭的 pandalab 專案 在 Terminal 輸入以下指令: `valet park` > park 支持子網域,比如 http://doc.pandalab.test 整個安裝流程就到這裡結束 ### 進階玩法 以下整理一些我認為你會用到的技巧 #### Valet升級 開啟 Terminal ,輸入以下指令: `composer global update` 最好順便再做一次 Valet install 以便把設定檔案做個更新 `valet install` #### 啟用TLS 如果你想要使用 HTTP/2 來讓某個專案網址支援 TLS,比如網址為pandalab.test,開啟 Terminal ,輸入以下指令: `valet secure pandalab` 如果想關閉 TLS 回到一般的 HTTP,開啟 Terminal ,輸入以下指令: `valet unsecure laravel` #### 將本地專案提供給外部人員訪問 這邊說明如何透過[Ngrok](https://ngrok.com/)來進行分享本地專案到全世界,但請特別注意 Ngrok 免費版本只支持到1分鐘上限40個請求,因此 Livewire 專案就不太適合用這個,沒用幾下就爆了 開啟 Terminal ,將路徑切換到你要分享的專案資料夾,輸入以下指令: `valet share` 如果要取消分享,只要按下 `Control + C` 即可 ##### 問題排除:出現連線被拒的處理方式 修改~/.composer/vendor/laravel/valet/cli/valet.php file 檔案如下: ``` $app->command('tld [tld]', function ($tld = null) { if ($tld === null) { - return info(Configuration::read()['tld']); + return output(Configuration::read()['tld']); } ``` 以下就是 Valet 開發環境安裝的相關內容,希望對使用 Mac 的朋友有幫助,不需要再使用 XAMPP 了。如果有任何疑問歡迎留言讓我知道,或者是透過上方的社群連結來與我聯絡,喜歡這篇文章的話也拜托用右下角的分享按鈕幫我分享出去,幫助更多使用 Mac 在進行開發的朋友 我是每天在空中陪著你成長的哥布林工程師,我們下個單元見 ### 參考資料 [Laravel官方文件](https://laravel.com/docs/8.x/valet) ## 介紹 Valet 是一個專為Mac開發者所做的Laravel開發環境。 不需要 Vagrant,也不需要 /etc/hosts檔案。你甚至能夠使用 local tunnels 來把你的網站對外分享,真的超讚! Laravel Valet會調校你的Mac環境,使之在機器開啟後就會在背景執行Nginx。接著,使用 DnsMasq,Valet會將網域類似 *.test的請求都指向到本機。 換句話說,這一個高效的Laravel開發環境只需用到大約7MB的記憶體。Valet並非作為取代Vagrant或Homestead的替代方案,只是提供給你一個新的選項,假如你要的是較為簡單的功能,需要更快的速度,或者是在記憶體不多的開發機器。 ## 安裝流程 Step 1.[安裝或更新Homebrew](https://brew.sh/index_zh-tw) `brew update` Step 2.安裝PHP7.4 `brew install php` Step 3.安裝[Composer](https://getcomposer.org/) `curl -sS https://getcomposer.org/installer | php` `mv composer.phar /usr/local/bin/composer` `touch ~/.bash_profile; open ~/.bash_profile` 在.bash_profile檔案內加入以下內容: `export PATH=~/.composer/vendor/bin:/usr/local/bin:$PATH` (完成之後按Command + Q 存檔離開) `source ~/.bash_profile`(執行剛才編輯的設定) Step 4.透過Composer來安裝Valet,確保~/.composer/vendor/bin位在$PATH的環境變數裡頭 `composer global require laravel/valet` Step 5.調校與安裝 Valet和DnsMasq `valet install` Step 6.確認DnsMasq能否生效,正常的話所有*.test的網域都會指向到本機 `ping laravel.test`(laravel可替換為任何字) Step 7.安裝MySql資料庫 `brew install mysql@5.7` Step 8.開啟MySql資料庫 `brew services start mysql@5.7`(連接資料庫 127.0.0.1 root/空密碼) Step 9.將專案所在資料夾指向到網域 切換到該專案的上層資料夾,執行valet park ## 將專案分享給其他人 valet share 出現連線被拒的處理方式 修改~/.composer/vendor/laravel/valet/cli/valet.php file 檔案如下: ``` $app->command('tld [tld]', function ($tld = null) { if ($tld === null) { - return info(Configuration::read()['tld']); + return output(Configuration::read()['tld']); } ``` ## 如果連不了資料庫 是因為密碼編碼的問題,可在連接上mysql之後使用以下指令: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully