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
    5
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: laravel --- # Laravel開發環境建置 ![](https://i.imgur.com/lhPEb8j.png) ## Windows作業系統 ### Step 1.安裝XAMPP PHP + Apache + MariaDB懶人包 [下載網址](https://www.apachefriends.org/zh_tw/download.html) 請下載PHP 7.2.5以上版本,下載完後安裝,過程只需不斷按Next即可。 ### Step 2.安裝Visual Studio Code 由微軟提供,可免費使用的IDE [下載網址](https://code.visualstudio.com/download) ### Step 3.安裝Composer 用於管理所有PHP套件,包含Laravel [下載網址](https://getcomposer.org/download) PS:如之前已安裝過,需升級成新版本,可使用以下指令 `composer self-update` ### Step 4.下載Laravel安裝器 開啟Terminal,輸入以下指令 composer global require laravel/installer ### Step 5.建立Laravel專案 1. 開啟Terminal,切換到xampp的htdocs資料夾,輸入指令,路徑應根據您的狀況作調整 `cd c:\xampp\htdocs` 2.如果要建立的是最新Laravel版本的專案,請輸入指令 `laravel new app_name` 2.1 如果要建立指定Laravel版本的新專案,例如5.8,需使用composer,請輸入指令 `composer create-project --prefer-dist laravel/laravel app_name "5.8.*"` 3. 生成應用金鑰,開啟Terminal,切換到新建立的專案資料夾,請輸入指令 `php artisan key:generate` 4. 開啟專案,確定是否有.env檔案,如果找不到.env檔,可將.env.example檔案改名成.env ### Step 6.確認建置是否成功 ==請確保Apache服務和MySQL服務都有開啟== 1. 開啟瀏覽器,比如Google Chrome 2. 輸入網址 http://localhost/app_name/public ### Step 7.設定本地化網域(非必須) 1. 將所命名的網域指向到本機 127.0.0.1,作法是修改hosts,這裡以laravel.dev為例 ``` //C:\WINDOWS\system32\drivers\etc\hosts 127.0.0.1 laravel.dev #Laravel學習專案 ``` 2. 告訴此網域需要由哪個專案資料夾來接手,作法是修改httpd-vhost.conf,路徑應根據您的狀況作調整 ``` //XAMPP資料夾\apache\conf\extra\httpd-vhosts.conf <VirtualHost *:80> DocumentRoot "c:\xampp\htdocs\app_name\public" ServerName laravel.test <Directory "c:\xampp\htdocs\app_name\public"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> ``` 3. 要求Apache開啟時需讀取httpd-vhosts.conf,作法是修改 XAMPP資料夾\apache\conf\original\httpd.conf。找到httpd-vhosts.conf那一行,把前面的#註解移除。 4. 重開Apache服務,訪問http://laravel.test,看能否順利開啟 ## Mac 作業系統 ### Step 1.安裝XAMPP PHP + Apache + MariaDB懶人包 [下載網址](https://www.apachefriends.org/zh_tw/download.html) 請下載PHP 7.2.5以上版本,下載完後安裝,過程只需不斷按Next即可。 選擇相同版號容量較小的非VM版本 ### Step 2.安裝Visual Studio Code 由微軟提供,可免費使用的IDE [下載網址](https://code.visualstudio.com/download) ### Step 3.安裝Composer 用於管理所有PHP套件,包含Laravel 1. 進入Composer官網,複製指令 [指令複製網址](https://getcomposer.org/download) 2. 開啟Terminal,貼入以下指令並執行 ``` php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');" ``` 3. 搬移到指定位置,指令如下: `sudo mv composer.phar /usr/local/bin/composer` ==如果/usr/local/bin不存在,輸入指令來建立:sudo mkdir /usr/local/bin== 4. 開啟.bash_profile來設定路徑,輸入指令: touch ~/.bash_profile;open ~/.bash_profile 4.1 加入以下程式碼 `export PATH=/usr/local/bin:$PATH` 5. 立即讀取路徑設定,輸入指令: source ~/.bash_profile ### Step 4.安裝Homebrew以下載缺少套件(非必須) ==可先跳到Step 5,如果安裝失敗再回來== 用於Mac環境安裝工具或套件,當執行composer時找不到必須套件,就需要使用Homebrew來下載 1. 開啟安裝Homebrew網站去複製指令,網址為https://brew.sh 2. 開啟Terminal,貼入以下指令並執行 `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"` 3. 開啟Terminal,輸入指令: ``` brew install php@7.4 brew link php@7.4 --force ``` ==PS: 7.4版本應替換為你所安裝XAMPP所採用的PHP版本== ### Step 5.下載Laravel安裝器 ==如果進行這個階段遇到錯誤,請先退回到Step4安裝完再回來。如果跳出需要命令列開發者工具,點安裝來安裝工具== 1. 開啟Terminal,輸入以下指令 `composer global require "laravel/installer"` 2. 開啟.bash_profile以設定路徑,輸入指令:`touch ~/.bash_profile;open ~/.bash_profile;` 2.1 修改完整程式碼如下: ` export PATH=$HOME/.composer/vendor/bin:/Applications/XAMPP/xamppfiles/bin:/usr/local/bin:$PATH` 3. 立即讀取路徑設定,指令為 `source ~/.bash_profile ` ### Step 6.建立Laravel專案 1. 開啟Terminal,切換到xampp的htdocs資料夾,輸入指令,路徑應根據您的狀況作調整 `cd /Applications/XAMPP/htdocs` 2. 如果要建立指定Laravel版本的新專案,例如5.8,需使用composer,請輸入指令 `composer create-project --prefer-dist laravel/laravel app_name "5.8.*"` 2.1(可選) 如果要建立的是最新Laravel版本的專案,請輸入指令 `laravel new app_name` 3. 生成應用金鑰,開啟Terminal,切換到新建立的專案資料夾,輸入指令 `php artisan key:generate` 4. 將storage資料夾權限全開,同樣在Terminal,路徑在專案資料夾,輸入指令 `sudo chmod -R 777 storage` 5. 開啟專案,確定是否有.env檔案,如果找不到.env檔,可將.env.example檔案改名成.env ### Step 7.確認建置是否成功 ==請確保Apache服務和MySQL服務都有開啟== 開啟瀏覽器,比如Google Chrome 輸入網址 http://localhost/app_name/public ### Step 8.設定本地化網域(非必須) 1. 將所命名的網域指向到本機 127.0.0.1,作法是修改hosts,這裡以laravel.dev為例 ``` //etc\hosts 127.0.0.1 laravel.test #Laravel學習專案 ``` 2. 告訴此網域需要由哪個專案資料夾來接手,作法是修改httpd-vhost.conf,加入以下設定,路徑應根據您的狀況作調整 ``` //XAMPP資料夾\etc\extra\httpd-vhosts.conf <VirtualHost *:80> DocumentRoot "/Applications/XAMPP/htdocs/app_name/public" ServerName laravel.test <Directory "/Applications/XAMPP/htdocs/app_name/public"> Require all granted Options All AllowOverride All Order deny,allow Allow from all </Directory> </VirtualHost> ``` 3. 要求Apache開啟時需讀取httpd-vhosts.conf,作法是修改//XAMPP資料夾\etc\httpd.conf。找到httpd-vhosts.conf那一行,把前面的#註解移除。 4. 重開Apache服務 5. 開啟瀏覽器,訪問http://laravel.test,看能否順利開啟 ## 專案設定 ### 主設定檔修改 修改config/app.php,設定timezone時區與locale語系 ``` //config/app.php 'locale' => 'zh_TW', 'timezone' => 'Asia/Taipei', ``` ### 隱私設定檔設定 修改.env檔案,所設的值不可以有空格 ``` //.env APP_NAME=Blog //專案名稱 APP_ENV=local //專案所在環境,local為本地端開發,production為正式上線環境 APP_KEY //應用金鑰,不得為空,可透過 php artisan key:generate來生成 APP_DEBUG=true //是否開啟除錯模式,正式上線環境建議關掉 APP_URL=http://localhost/blog/public //專案網域,須設定到public資料夾 DB_CONNECTION=mysql //所要連接的資料庫 DB_HOST=127.0.0.1 //資料庫Ip Address DB_PORT=3306 //資料庫port號 DB_DATABASE=blog //資料庫名稱 DB_USERNAME=root //資料庫帳號 DB_PASSWORD= //資料庫密碼 ``` ## 錯誤排除 ### 套件安裝錯誤 1.出現記憶體不足的錯誤導致安裝失敗 解決方案: 找到Apache資料夾內的php.ini(Windows版本在php資料夾內),找到裏頭的一行設定"memory_limit",將其值改成-1,即可不限定伺服器的記憶體空間 ### 套件安裝太慢 解決方案: 可能是Composer內核還是1.x版本,請升級到2.0.6以上,請開啟CMD輸入以下指令 `composer self-update --2` ### 資料庫連線錯誤 1. 出現1071 Specified key was too long; max key length is 767 bytes 解決方法: 開啟 app\Providers\AppServiceProvider.php 加入以下程式碼: ``` use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); } ``` ### 權限不足錯誤 1. Mac開發環境出現storage資料夾的 failed to open stream:Permission denied 解決方法: 開啟Terminal,切換到專案資料夾後,輸入以下指令 `sudo chmod -R 777 storage` ### 應用錯誤 1. 出現No application encryption key has been specified 錯誤原因是缺少應用的金鑰 解決方案: 開啟Terminal,切換到專案資料夾後,輸入以下指令 `php artisan key:generate`

    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