PHP 开发环境搭建
一、使用寶塔安裝環境:
php7.2
iis10.0
mysql5.5
安裝完成后,web站點的目錄為:D:/wwwroot
二、也可手動安裝
1 安裝php7.2
2 安裝apache服務器
下載安裝文件Welcome! - The Apache HTTP Server Project??
解壓到D:\BtSoft目錄,
打開httpd.conf,本機的安裝目錄為D:\BtSoft\Apache24\conf
修改php.ini:
;TODO changed extension_dir = "ext"
extension_dir = "D:/BtSoft/php/72/ext"
;
;extension=curl
;extension=gd2
;extension=gettext
;extension=mbstring
;extension=mysqli
;extension=pdo_mysql
;extension=pdo_sqlite
;extension=sockets
配置如下:
Define SRVROOT "D:/BtSoft/Apache24"?//當前 apache的安裝目錄
Listen 8889???//修改端口號
添加如下代碼:
#TODO set serverName
ServerName localhost:80
# TODO enabled
Include conf/extra/httpd-vhosts.conf
#TODO AddLine
# php7 support
LoadModule php7_module D:/BtSoft/php/php7234/php7apache2_4.dll
AddType application/x-httpd-php .php .html .htm
#configure the path to php.ini
PHPIniDir ?D:/BtSoft/php/php7234
Cmd運行C:\Users\lzwjsb>httpd -t ??運行結果:Syntax OK ?//測試配置文件是否合法
安裝apache主服務
以管理員身份運行cmd ,
C:\WINDOWS\system32>httpd -k install -n Apache
Installing the 'Apache' service
The 'Apache' service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
命令行啟動net start/stop apache,也可以手動啟動.
利用命令啟動
httpd -k start: 不會提示詳細的錯誤信息。
httpd -k start -n apache: 會提示詳細的錯誤信息,其中的"apache"修改為你的Apache服務名,可以到計算機服務里找。
httpd -k restart -n apache: 重啟。
net start apache: 利用Windows托管服務命令。
檢查服務器是否啟動正常http://127.0.0.1:8889
查看端口狀態:
C:\Users\lzwjsb>netstat -aon | findstr "8889"
??TCP ???0.0.0.0:8889 ??????????0.0.0.0:0 ?????????????LISTENING ??????50664
??TCP ???[::]:8889 ?????????????[::]:0 ????????????????LISTENING ??????50664
布署tp5應用,在httpd.conf中修改:
#TODO changed serverWebRoot
#DocumentRoot "${SRVROOT}/htdocs"
#<Directory "${SRVROOT}/htdocs">
DocumentRoot "D:/wwwroot"
<Directory "D:/wwwroot">
3 安裝iis服務器
安裝略
配置:
控制面板--系統安全---管理工具
寶塔創建的web站點的默認路徑為:C:\inetpub\wwwroot
4 安裝nginx服務器
直接下載http://nginx.org/en/download.html
解壓到指定目錄,啟動nginx,cmd -----start nginx.exe
nginx.exe -s stop ??????????????????//停止nginx
nginx.exe -s reload ???????????????//重新加載nginx
nginx.exe -s quit ????????????????????//退出nginx
查看啟動的ngixn進程
tasklist /fi "imagename eq nginx.exe"
配置文件,本機目錄D:\software\nginx-1.21.3\conf
示例代碼如下:
#TODO disable
error_log ?logs/error.log;
error_log ?logs/error.log ?notice;
error_log ?logs/error.log ?info;
?location / { ??
????????????#root ??html;
????????????root ??D:/wwwroot;
????????????index ?index.html index.htm index.php default.php default.htm default.html;
????????}
??location ~ \.php$ {
????????????root ??????????D:/wwwroot;
????????????fastcgi_pass ??127.0.0.1:9000;
????????????fastcgi_index ?index.php;
????????????fastcgi_param ?SCRIPT_FILENAME ?D:/wwwroot/$fastcgi_script_name;
????????????include ???????fastcgi_params;
????????}
修改php.ini文件
enable_dl = On
cgi.force_redirect = 1\
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
date.timezone = Asia/Shanghai
啟動php ,cmd到php安裝目錄,執行如下命令:
php-cgi.exe -b 127.0.0.1:9000 -c php.ini
停止php-cgi和nginx ,可以將如下代碼制批處理文件:
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
Exit
配置完成后,瀏覽器測試http://localhost/tp5/public/
三 下載安裝?thinkPhp框架
安裝composer,在D:\BtSoft\composer(自已創建文件夾)
cmd進入該目錄,
執行php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
該條命令下載composer-setup.php腳本,
執行 php composer-setup.php ????//執行安裝過程
執行 php -r "unlink('composer-setup.php');"????//刪除安裝角本
全局安裝:
進行php 的安裝目錄D:\BtSoft\php\72,將composer.phar放到該目錄,即與php.exe為同一級目錄,然后在php安裝目錄下新建composer.bat文件,添加如下內容:
@php "%~dp0composer.phar" %*
然后進入命令行窗口執行:composer --version查看當前版本號
ThinkPhp的安裝,可以通過composer進行安裝,
如果是第一次安裝composer create-project topthink/think=5.1.* tp5//安裝目錄
如果安裝過,可以執行下面命令更新
也可以通過git進行安裝,composer update topthink/framework
git的安裝略
thinkPhp分為應有和核心兩個庫
應用項目:https://github.com/top-think/think
核心框架:https://github.com/top-think/framework
分別下載兩個庫:本機用的安裝目錄是D:\BtSoft\php
git clone https://github.com/top-think/think tp5//應用項目
出現如下錯誤 :
fatal: unable to access 'https://github.com/top-think/think/': OpenSSL SSL_read: Connection was reset, errno 10054
fatal: unable to access 'https://github.com/top-think/think/': OpenSSL SSL_connect: Connection was reset in connection to github.com:443
解決方法 : 在git bash 中執行如下命令
$ git config --global http.sslVerify "false"
也可以將http換成git
切換到tp5目錄下,執行如下命令:
git clone https://github.com/top-think/framework thinkphp
============================================================================
四 簡單布署應用
在寶塔的目錄中使用tp創建一個簡單項目,本機的應用目錄為D:\wwwroot,uq
將下載好的tp5目錄放到該目錄下
本機使用的是iis服務器,在iis上創建網站,添加虛擬目錄D:\wwwroot\tp5\public
在瀏覽器中訪問http://localhost/public/
出現如下問題 :
1 使用iis配置web應用時,禁用匿名身份驗證,開啟基本信息驗證
訪問public目錄下的?index.php時出現如下錯誤
Warning: require(D:\wwwroot\tp5\public/../vendor/autoload.php): failed to open stream: No such file or directory in D:\wwwroot\tp5\public\index.php on line 15
Warning: require(D:\wwwroot\tp5\public/../vendor/autoload.php): failed to open stream: No such file or directory in D:\wwwroot\tp5\public\index.php on line 15
Fatal error: require(): Failed opening required 'D:\wwwroot\tp5\public/../vendor/autoload.php' (include_path='.;C:\php\pear') in D:\wwwroot\tp5\public\index.php on line 15
?解決辦法:
D:\wwwroot\tp5\public/../vendor/autoload.php該 文件不存在,可使用composer 進行更新
在更新過程中,
[ErrorException]
??proc_get_status() has been disabled for security reasons
2 在php的安裝目錄下,本機的是D:\BtSoft\php\72找到php.ini文件,將禁用的函數取消即可
; http://php.net/disable-functions ????disable removed ???putenv, ???proc_open, ????proc_get_status,
disable_functions = passthru,system,chroot,chgrp,chown,shell_exec,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,exec
然后執行更新命令:composer update
============================================================================
五 vs code
Vs code 下載安裝略
VIM ??--- 喜歡用VIM操作的小伙伴可以加上這個,不要用amVIM(用得不爽,好多vim功能都沒有)
Better Align ?--- 對齊用的,設置一下快捷鍵 Ctrl + Alt + =,對塊自動等號對齊
Auto Close Tag ???自動標簽閉合
Auto Rename Tag ?自動標簽重命名
Code Outline ???函數變量列表 ?(目前有點小問題,顯示的函數列表是雙份的)
ftp-simple ?????FTP遠程同步工具 ?
HTML CSS Support ???????CSS支持工具
HTML Snippets ????HTML小片段工具
IntelliSense for CSS class names ??CSS類名工具
JavaScript code snippets ???
JS-CSS-HTML Formatter
jshint ?????js代碼檢查工具
MetaGO ???類是easymotion ,可以用鍵盤快速移動的工具
npt Intellisense ??????其他軟件需要這個輔助工具,(具體不是很清楚)
Path Intellisense ????路徑管理工具
PHP ?Debug
PHP Extension ?Pack ?PHP擴展包
PHP Intellisense ??????PHP自動補全工具
PHP Intellisense -Crane ??PHP自動補全工具
Project Manager ????多個項目之間切換的工具
Typing Installer ???不是很清楚,但很有用
vscode-icons ?????給不同的文件類型添加圖標
快捷鍵
可以通過 File -> Preference -> Settings中 ??vim.useCtrlKeys 選項設置為 false
Vs code中自定義文件注釋和函數注釋
Php 語法學習
總結
以上是生活随笔為你收集整理的PHP 开发环境搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【实用工具指南 一】OCR图片识别自动翻
- 下一篇: PHP开发环境搭建--Windows