# PHP (Windows環境建置)
## PHP安裝(7.4.30)
#### 1.下載php封包(https://www.php.net/downloads.php)
* 若使用 Apache 必須選 Thread Safe 版本
#### 2.解壓縮後重新命名資料夾(php-7.4.30)並建立環境變數
環境變數修改 設定>關於>進階系統設定>環境變數>Path(編輯)
C:\AMP\php-7.4.30
#### 3.設定php.ini檔
選擇
「php.ini-development」(開發環境)
或
「php.ini-production」(生產環境)
(兩者的設定差別:https://qiita.com/ucan-lab/items/86f1498de569f4a5e16b)
擇一改名為**php.ini**作為基礎設定
#### 開啟功能(line914)
extension=curl ;使用cURL實現Get和Post請求的方法
extension=mbstring ;多字節字符串(用於切中文字)
extension=openssl ;[SSL配置](https://www.cainiaojc.com/php/php-openssl-functions.html)
#### 新增功能 phalcon v4.1.2
extension=[php_psr.dll](https://pecl.php.net/package/psr)
extension=[php_phalcon.dll](https://github.com/phalcon/cphalcon/releases)
#### 設定時區(line962)
date.timezone = Asia/Taipei
#### [opcache]設定[xdebug](https://www.youtube.com/watch?v=3PCQ1YOGcCU&list=PLFbELsxCUfgXPGfAB_-wrqK9Dvav0hk4s&index=1)(line1770)
zend_extension = "C:/AMP/php-7.4.30/ext/php_xdebug.dll"
xdebug.mode = debug
xdebug.start_with_request = yes
.ini設定參考(https://ithelp.ithome.com.tw/articles/10284851?sc=pt)
設定完後用 php -m 可確認功能是否開啟及是否有缺.dll檔
(.dll檔放在php根目錄的ext中)
------------------------
## Apache2.4安裝
#### 1.下載Apache封包(https://www.apachelounge.com/download/)
#### 2.解壓縮後重新命名資料夾(Apache24)
#### 3.修改Apache24\conf\httpd.conf檔案
修改路徑(line37)
Define SRVROOT "c:\AMP\Apache24" #資料夾位置
設定dir_module(line285)
DirectoryIndex index.html index.php #設定.php可被讀取
新增php類型(line423)
AddType application/x-httpd-php .php
新增php路徑(最後)
PHPIniDir "C:\AMP\php-7.4.30\php.ini" # php.ini位置
LoadModule php7_module "C:\AMP\php-7.4.30\php7apache2_4.dll"
#### 4.開啟mod_rewrite URL重寫功能
4-1.LoadModule rewrite_module modules/mod_rewrite.so (line423)
4-2.修改Directory(line234)
<Directory />
Options FollowSymLinks # 不顯示出目錄
AllowOverride All # 讓.htaccess可被修改(安全性問題)
Require all denied # 全部來訪的都通過
</Directory>
4-3.修改Directory路徑為專案路徑(line253)
DocumentRoot "${SRVROOT}/htdocs/專案資料夾"
<Directory "${SRVROOT}/htdocs/專案資料夾">
Options FollowSymLinks # 不顯示出目錄
AllowOverride All # 讓.htaccess可被修改(安全性問題)
Require all denied # 全部來訪的都通過
</Directory>
4-4.找到所有的“AllowOverride None”行將其更改為“AllowOverride All”
#### 5.安裝Apache (windows)
用管理員開cmd 並cd到Apache目錄中的bin(C:\AMP\Apache24\bin)
輸入安裝指令
httpd -k install
#### 6.啟動Apache
電腦管理>服務>Apache右鍵啟動
* 當httpd.conf有修改時要重啟服務才會套用新設定。
Apache設定參考
(https://httpd.apache.org/docs/2.4/mod/core.html#options)
(https://ithelp.ithome.com.tw/articles/10225101)
#### [7.設定Phalcon](https://hackmd.io/@a000058556/ryKyFq6xj)
詳見(https://docs.phalcon.io/4.0/en/webserver-setup)
------------------------