# 環境設定 ### Git mac 安裝方式: * 參考網站 https://git-scm.com/download/mac https://gitbook.tw/chapters/environment/install-git-in-mac.html * 先安裝 Homebrew 在 Terminal 執行以下命令: ``` /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ``` ``` brew --version ``` 檢查是否安裝完成。 Homebrew 安裝完後,就可以下指令讓 Homebrew 來安裝 Git 了。 * Git 安裝 ``` brew install git ``` ## ### iTerm2 安裝方式: 雖然不是必要,內建的 Terminal 也可以,不過 iTerm2 還是比較好用。 * 參考網站 https://medium.com/statementdog-engineering/prettify-your-zsh-command-line-prompt-3ca2acc967f http://huli.logdown.com/posts/402147-iterm2-zsh-better-environment * 安裝方式 如果沒有用過 brew cask 需要先跑這行 ``` brew tap caskroom/cask ``` 安裝 iTerm2 ``` brew cask instal iterm2 ``` 安裝好後,接下來就可以修改許多設定,文字、顏色等等。 修改方式 Profiles > Edit Profiles > 選取需要修改的... ![](https://i.imgur.com/aN6gseq.jpg) ## ### powerline font 安裝方式: 因為我們要用的 theme 會用到很多的特殊 icon,所以 iTerm2 選用的字型必需要支援這種特殊 icon font。這類型的字體統稱為 powerline font(另外還有加強版支援更多特殊 icon 的叫的 nerd font) 沒有安裝的話,遇到 icon 會變框框問號。 ![](https://i.imgur.com/m1Ls9t7.png) 裝完並設定新字型後的效果: ![](https://i.imgur.com/y6IfpmK.png) * 安裝 powerline font 先執行這行,才能用 homebrew 安裝字型。曾經執行過的人可以跳過這個指令。 ``` brew tap caskroom/fonts ``` * 選擇想要安裝的文字安裝: ``` brew cask install font-sourcecodepro-nerd-font ``` * brew 上面也有很多字型可以選擇。 關鍵字是 nerd: ``` brew cask search nerd ``` ![](https://i.imgur.com/MuQK6Ko.jpg) 裝完後,記得修改 iTerm2 字型設定否則不會生效。請改成 SauceCodePro Nerd Font 或你自己下載的字型。 ![](https://i.imgur.com/wAvhg8H.png) ## ### zsh安裝方式: zsh 是可以用來取代 bash 的工具,建議安裝。 上面已把 iterm2 安裝完畢後,就可以使用 iterm2 來下指令。 * 安裝 zsh: ``` brew install zsh ``` * 把預設的shell改成ZSH ``` sudo sh -c "echo $(which zsh) >> /etc/shells" ``` ``` chsh -s $(which zsh) ``` * 重啟iterm2,輸入指令確認是否成功把預設的shell改成zsh ``` echo $SHELL ``` 會看到顯示 /usr/local/bin/zsh ,代表成功。 ![](https://i.imgur.com/bPo5lKK.png) ## ### oh-my-zsh 安裝: 是 zsh 的 framework ,現在幾乎所有 zsh 好用的工具都有支援 oh-my-zsh ,也提供了許多外掛及主題可以使用。 * 安裝 oh-my-zsh: ``` sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" ``` 執行完以後如果沒有出現什麼錯誤訊息就代表成功了,預設的主題(theme)是robbyrussell,如果不喜歡,可以打開.zshrc更改主題。 * 開啟.zshrc: ``` open ~/.zshrc ``` * 或是用vscode開啟: ``` code . ~/.zshrc ``` 找到ZSH_THEME後輸入喜歡的主題,把原本 ZSH_THEME=”robbyrussell” 改成你想要的。 ![](https://i.imgur.com/q7VSY12.png) ## ### drupal 環境建立: 需要安裝composer與drush,首先來安裝composer。 * 參考網站 composer: https://www.youtube.com/watch?v=nl9S21lCW3g https://qiita.com/vc7/items/373362ffca15d5a70b64 drush: https://www.drush.org/install/ https://www.youtube.com/watch?v=Rirrsr7RhtE <br/><br/> > **composer 安裝** * 需要安裝在/usr/local/bin中: ``` cd /usr/local/bin ``` * 安裝指令: ``` php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('sha384', 'composer-setup.php') === 'e5325b19b381bfd88ce90a5ddb7823406b2a38cff6bb704b0acc289a09c8128d4a8ce2bbafcd1fcbdc38666422fe2806') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');" ``` * 檢查是否安裝成功: ``` php composer ``` 出現以下畫面代表成功。 ![](https://i.imgur.com/TGYXi9l.png) 接下來繼續設定 * 更改系統路徑與環境變數: ``` vi ~/.bash_profile ``` 輸入後會進到該畫面(裡面原本都沒有設定,此圖是已經設定好的) ![](https://i.imgur.com/uU3c3a4.png) <br/> 請輸入 alias composer="hp ~/composer.phar",然後按 esc 後輸入 :wq 。 * 執行以下指令讓剛剛修改的環境生效: ``` source ~/.bash_profile ``` * 再度確認是否成功: ``` php composer ``` <br/><br/> > **Drush 安裝:** * 需要安裝在/usr/local/bin中: ``` cd /usr/local/bin ``` * 安裝指令: ``` composer require drush/drush ``` * 檢查是否安裝成功: ``` ~/vendor/drush/drush/drush ``` 看到以下畫面代表安裝成功。 ![](https://i.imgur.com/qHlIqEp.png) 接下來繼續設定。 * 更改系統路徑與環境變數: ``` vi ~/.bash_profile ``` 跟 compores 一樣,需要多輸入 alias drush="~/vendor/drush/drush/drush",然後按 esc 後輸入 :wq 。 ![](https://i.imgur.com/aZxCNgq.png) * 執行以下指令讓剛剛修改的環境生效: ``` source ~/.bash_profile ``` * 確認是否成功: ``` drush ``` ## ### MAMP 設定 * 下載網址:https://www.mamp.info/en/downloads/ > 基本設定 ![](https://i.imgur.com/F1HFTNr.png) ![](https://i.imgur.com/urBn44q.png) > 設定 MAMP: * 首先cd 到 MAMP 的 extra 中: ``` cd /Applications/MAMP/conf/apache/extra ``` * 用 VScode 開啟文件: ``` code . ``` ## ### ssh key 設定 參考網址: https://sinyilin.github.io/git/20191024/1014042378/ https://dotblogs.com.tw/as15774/2018/04/30/174737 * 首先確認電腦裡是否有 id_rsa.pub 這個檔案 ``` cd ~/.ssh ``` ``` ls ``` * 建SSH key ``` ssh-keygen -t rsa -C "yourEmail@example.com" ``` 執行完後會讓你輸入一個檔名,用於儲存剛才生成的 SSH key 程式碼 ![](https://i.imgur.com/oDm91zY.png) 檔名可以不輸入,或是輸入想要的名稱。(ex:id_rsa_aaa_github) 再來就是設定私鑰的密碼,這邊就直接Enter兩次跳過。完成如下 ![](https://i.imgur.com/YJ4afxB.png) * 複製 SSH key ``` ~/.ssh/ ``` ``` cat ~/.ssh/id_rsa.pub ``` ![](https://i.imgur.com/BiBKRp0.png) 再來就是將公鑰放到公司開的 gitlab 帳號中。 ![](https://i.imgur.com/s7lPNX6.png) 把剛剛複製的那串SSH key 貼上與填寫該 SSH Key名稱即可。 ## ### drupal 專案設定 參考網址: https://www.opencli.com/linux/fix-warning-unprotected-private-key-file 首先把有 drupal 的專案 clone 下來,用 VScode 開啟。 * 每個branch都要記得要下composer install * 在 docroot => sites => default 中建立新的文件 settings.local.php。 * 注意!!!如果.gitignore有這個檔案,就要新增它。 ![](https://i.imgur.com/rBPxgtV.png) ![](https://i.imgur.com/HG893ii.png) * 在文件中放入以下內容: ```php <?php // @codingStandardsIgnoreFile /** * @file * Local development override configuration feature. * * To activate this feature, copy and rename it such that its path plus * filename is 'sites/default/settings.local.php'. Then, go to the bottom of * 'sites/default/settings.php' and uncomment the commented lines that mention * 'settings.local.php'. * * If you are using a site name in the path, such as 'sites/example.com', copy * this file to 'sites/example.com/settings.local.php', and uncomment the lines * at the bottom of 'sites/example.com/settings.php'. */ /** * Assertions. * * The Drupal project primarily uses runtime assertions to enforce the * expectations of the API by failing when incorrect calls are made by code * under development. * * @see http://php.net/assert * @see https://www.drupal.org/node/2492225 * * If you are using PHP 7.0 it is strongly recommended that you set * zend.assertions=1 in the PHP.ini file (It cannot be changed from .htaccess * or runtime) on development machines and to 0 in production. * * @see https://wiki.php.net/rfc/expectations */ assert_options(ASSERT_ACTIVE, TRUE); \Drupal\Component\Assertion\Handle::register(); /** * Enable local development services. */ $settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml'; /** * Show all error messages, with backtrace information. * * In case the error level could not be fetched from the database, as for * example the database connection failed, we rely only on this value. */ $config['system.logging']['error_level'] = 'verbose'; /** * Disable CSS and JS aggregation. */ $config['system.performance']['css']['preprocess'] = FALSE; $config['system.performance']['js']['preprocess'] = FALSE; /** * Disable the render cache. * * Note: you should test with the render cache enabled, to ensure the correct * cacheability metadata is present. However, in the early stages of * development, you may want to disable it. * * This setting disables the render cache by using the Null cache back-end * defined by the development.services.yml file above. * * Only use this setting once the site has been installed. */ # $settings['cache']['bins']['render'] = 'cache.backend.null'; /** * Disable caching for migrations. * * Uncomment the code below to only store migrations in memory and not in the * database. This makes it easier to develop custom migrations. */ # $settings['cache']['bins']['discovery_migration'] = 'cache.backend.memory'; /** * Disable Internal Page Cache. * * Note: you should test with Internal Page Cache enabled, to ensure the correct * cacheability metadata is present. However, in the early stages of * development, you may want to disable it. * * This setting disables the page cache by using the Null cache back-end * defined by the development.services.yml file above. * * Only use this setting once the site has been installed. */ # $settings['cache']['bins']['page'] = 'cache.backend.null'; /** * Disable Dynamic Page Cache. * * Note: you should test with Dynamic Page Cache enabled, to ensure the correct * cacheability metadata is present (and hence the expected behavior). However, * in the early stages of development, you may want to disable it. */ # $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null'; /** * Allow test modules and themes to be installed. * * Drupal ignores test modules and themes by default for performance reasons. * During development it can be useful to install test extensions for debugging * purposes. */ # $settings['extension_discovery_scan_tests'] = TRUE; /** * Enable access to rebuild.php. * * This setting can be enabled to allow Drupal's php and database cached * storage to be cleared via the rebuild.php page. Access to this page can also * be gained by generating a query string from rebuild_token_calculator.sh and * using these parameters in a request to rebuild.php. */ $settings['rebuild_access'] = TRUE; /** * Skip file system permissions hardening. * * The system module will periodically check the permissions of your site's * site directory to ensure that it is not writable by the website user. For * sites that are managed with a version control system, this can cause problems * when files in that directory such as settings.php are updated, because the * user pulling in the changes won't have permissions to modify files in the * directory. */ $settings['cache']['bins']['render'] = 'cache.backend.null'; $settings['twig_debug'] = TRUE; $settings['skip_permissions_hardening'] = TRUE; $databases['default']['default'] = array ( 'database' => 'eastech', 'username' => 'root', 'password' => 'root', 'prefix' => '', 'host' => 'localhost', 'port' => '3306', 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql', 'driver' => 'mysql', ); $config['config_split.config_split.local']['status'] = TRUE; $config['config_split.config_split.dev']['status'] = FALSE; $config['environment_indicator.indicator']['bg_color'] = '#FEA'; $config['environment_indicator.indicator']['fg_color'] = '#565656'; $config['environment_indicator.indicator']['name'] = 'Local'; ``` ![](https://i.imgur.com/ZrHeirr.png) * database 的設定,需要先到網站建立該專案的 table: 網址:http://localhost/phpmyadmin/server_databases.php?server=1 進入網站前要先開啟 MAMP 點選 servers,Apache 和 MySQL 亮綠燈代表成功。 ![](https://i.imgur.com/snYESEX.png) 新增專案需要的 table。 ![](https://i.imgur.com/T7dWS0q.png) * 把 database 指向該專案的 database中(帳號與密碼先設定root到時再詢問主管): ![](https://i.imgur.com/8coyCfN.png) ## ### 設定 MAMP 的 drupal 相關設定 * hosts 設定: ``` code /etc ``` 增加一行 code : ``` 127.0.0.1 自行設定的網址名稱 ``` ![](https://i.imgur.com/1cFkBmX.png) * 建立虛擬主機 ``` /Applications/MAMP/conf/apache ``` 在 #Virtual hosts 把 Include 那段註解拿掉。 ![](https://i.imgur.com/y4rwMEs.png) * 設定虛擬主機文件 ``` /Applications/MAMP/conf/apache/extra ``` 在 httpd-vhosts.conf 最後一段貼上以下 ``` <VirtualHost *:80> DocumentRoot "Desktop/git/zigong/docroot" ServerName zigong.len.tw </VirtualHost> ``` 並把剛剛貼上的最後一段修改 DocumentRoot ,路徑修改該專案的位置,ServerName 修改自行設定的網址名稱。 ![](https://i.imgur.com/bpBTXto.png) * 再來把該database中資料清空(如果剛該基本上都不會有資料,以防萬一還是輸入以下指令清空): ``` drush sql-drop -y ``` * 同步database ``` drush sql:sync @remote @self -y ``` 注意!!!!有可能會出現以下錯誤。 ![](https://i.imgur.com/BVAxHvz.png) 該錯誤是說,需要設定一個 ssh key 的權限,不能權限全開。 * 權限設定: ``` chmod 600 /對應該檔案位置 ``` 看到以下代表成功 ![](https://i.imgur.com/qHOEDas.png) * 清快取與同步設定擋: ``` drush cr -y ``` ``` drush cim ``` * 多媒體檔同步: ``` drush rsync @remote.dev:%files @self:%files -y ``` * 最後要記得重啟 MAMP。 到這邊基本上 drupal 的專案可以開啟,開啟瀏覽器輸入前面所設定的網址名稱,網頁跑出來代表成功。 ## ### 幫 term 設定聚集來使用 同步資料庫等指令 * 先到 bin 中開啟 code。 ``` cd usr/local/bin ``` ``` code . ``` * 在 bin 中建立文件,在裡面建立要聚集的指令。 ![](https://i.imgur.com/oNqjqTu.png) ![](https://i.imgur.com/CNQ9GbM.png) * 在 term 中輸入建立文件的名稱,就會執行聚集。 ![](https://i.imgur.com/kASVGv2.png)