PHP 开发环境搭建
一、使用寶塔安裝環(huán)境:
php7.2
iis10.0
mysql5.5
安裝完成后,web站點(diǎn)的目錄為:D:/wwwroot
二、也可手動(dòng)安裝
1 安裝php7.2
2 安裝apache服務(wù)器
下載安裝文件Welcome! - The Apache HTTP Server Project??
解壓到D:\BtSoft目錄,
打開httpd.conf,本機(jī)的安裝目錄為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"?//當(dāng)前 apache的安裝目錄
Listen 8889???//修改端口號(hào)
添加如下代碼:
#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運(yùn)行C:\Users\lzwjsb>httpd -t ??運(yùn)行結(jié)果:Syntax OK ?//測(cè)試配置文件是否合法
安裝apache主服務(wù)
以管理員身份運(yùn)行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.
命令行啟動(dòng)net start/stop apache,也可以手動(dòng)啟動(dòng).
利用命令啟動(dòng)
httpd -k start: 不會(huì)提示詳細(xì)的錯(cuò)誤信息。
httpd -k start -n apache: 會(huì)提示詳細(xì)的錯(cuò)誤信息,其中的"apache"修改為你的Apache服務(wù)名,可以到計(jì)算機(jī)服務(wù)里找。
httpd -k restart -n apache: 重啟。
net start apache: 利用Windows托管服務(wù)命令。
檢查服務(wù)器是否啟動(dòng)正常http://127.0.0.1:8889
查看端口狀態(tài):
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應(yīng)用,在httpd.conf中修改:
#TODO changed serverWebRoot
#DocumentRoot "${SRVROOT}/htdocs"
#<Directory "${SRVROOT}/htdocs">
DocumentRoot "D:/wwwroot"
<Directory "D:/wwwroot">
3 安裝iis服務(wù)器
安裝略
配置:
控制面板--系統(tǒng)安全---管理工具
寶塔創(chuàng)建的web站點(diǎn)的默認(rèn)路徑為:C:\inetpub\wwwroot
4 安裝nginx服務(wù)器
直接下載http://nginx.org/en/download.html
解壓到指定目錄,啟動(dòng)nginx,cmd -----start nginx.exe
nginx.exe -s stop ??????????????????//停止nginx
nginx.exe -s reload ???????????????//重新加載nginx
nginx.exe -s quit ????????????????????//退出nginx
查看啟動(dòng)的ngixn進(jìn)程
tasklist /fi "imagename eq nginx.exe"
配置文件,本機(jī)目錄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
啟動(dòng)php ,cmd到php安裝目錄,執(zhí)行如下命令:
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
配置完成后,瀏覽器測(cè)試http://localhost/tp5/public/
三 下載安裝?thinkPhp框架
安裝composer,在D:\BtSoft\composer(自已創(chuàng)建文件夾)
cmd進(jìn)入該目錄,
執(zhí)行php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
該條命令下載composer-setup.php腳本,
執(zhí)行 php composer-setup.php ????//執(zhí)行安裝過程
執(zhí)行 php -r "unlink('composer-setup.php');"????//刪除安裝角本
全局安裝:
進(jìn)行php 的安裝目錄D:\BtSoft\php\72,將composer.phar放到該目錄,即與php.exe為同一級(jí)目錄,然后在php安裝目錄下新建composer.bat文件,添加如下內(nèi)容:
@php "%~dp0composer.phar" %*
然后進(jìn)入命令行窗口執(zhí)行:composer --version查看當(dāng)前版本號(hào)
ThinkPhp的安裝,可以通過composer進(jìn)行安裝,
如果是第一次安裝composer create-project topthink/think=5.1.* tp5//安裝目錄
如果安裝過,可以執(zhí)行下面命令更新
也可以通過git進(jìn)行安裝,composer update topthink/framework
git的安裝略
thinkPhp分為應(yīng)有和核心兩個(gè)庫(kù)
應(yīng)用項(xiàng)目:https://github.com/top-think/think
核心框架:https://github.com/top-think/framework
分別下載兩個(gè)庫(kù):本機(jī)用的安裝目錄是D:\BtSoft\php
git clone https://github.com/top-think/think tp5//應(yīng)用項(xiàng)目
出現(xiàn)如下錯(cuò)誤 :
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 中執(zhí)行如下命令
$ git config --global http.sslVerify "false"
也可以將http換成git
切換到tp5目錄下,執(zhí)行如下命令:
git clone https://github.com/top-think/framework thinkphp
============================================================================
四 簡(jiǎn)單布署應(yīng)用
在寶塔的目錄中使用tp創(chuàng)建一個(gè)簡(jiǎn)單項(xiàng)目,本機(jī)的應(yīng)用目錄為D:\wwwroot,uq
將下載好的tp5目錄放到該目錄下
本機(jī)使用的是iis服務(wù)器,在iis上創(chuàng)建網(wǎng)站,添加虛擬目錄D:\wwwroot\tp5\public
在瀏覽器中訪問http://localhost/public/
出現(xiàn)如下問題 :
1 使用iis配置web應(yīng)用時(shí),禁用匿名身份驗(yàn)證,開啟基本信息驗(yàn)證
訪問public目錄下的?index.php時(shí)出現(xiàn)如下錯(cuò)誤
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 進(jìn)行更新
在更新過程中,
[ErrorException]
??proc_get_status() has been disabled for security reasons
2 在php的安裝目錄下,本機(jī)的是D:\BtSoft\php\72找到php.ini文件,將禁用的函數(shù)取消即可
; 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
然后執(zhí)行更新命令:composer update
============================================================================
五 vs code
Vs code 下載安裝略
VIM ??--- 喜歡用VIM操作的小伙伴可以加上這個(gè),不要用amVIM(用得不爽,好多vim功能都沒有)
Better Align ?--- 對(duì)齊用的,設(shè)置一下快捷鍵 Ctrl + Alt + =,對(duì)塊自動(dòng)等號(hào)對(duì)齊
Auto Close Tag ???自動(dòng)標(biāo)簽閉合
Auto Rename Tag ?自動(dòng)標(biāo)簽重命名
Code Outline ???函數(shù)變量列表 ?(目前有點(diǎn)小問題,顯示的函數(shù)列表是雙份的)
ftp-simple ?????FTP遠(yuǎn)程同步工具 ?
HTML CSS Support ???????CSS支持工具
HTML Snippets ????HTML小片段工具
IntelliSense for CSS class names ??CSS類名工具
JavaScript code snippets ???
JS-CSS-HTML Formatter
jshint ?????js代碼檢查工具
MetaGO ???類是easymotion ,可以用鍵盤快速移動(dòng)的工具
npt Intellisense ??????其他軟件需要這個(gè)輔助工具,(具體不是很清楚)
Path Intellisense ????路徑管理工具
PHP ?Debug
PHP Extension ?Pack ?PHP擴(kuò)展包
PHP Intellisense ??????PHP自動(dòng)補(bǔ)全工具
PHP Intellisense -Crane ??PHP自動(dòng)補(bǔ)全工具
Project Manager ????多個(gè)項(xiàng)目之間切換的工具
Typing Installer ???不是很清楚,但很有用
vscode-icons ?????給不同的文件類型添加圖標(biāo)
快捷鍵
可以通過 File -> Preference -> Settings中 ??vim.useCtrlKeys 選項(xiàng)設(shè)置為 false
Vs code中自定義文件注釋和函數(shù)注釋
Php 語法學(xué)習(xí)
總結(jié)
以上是生活随笔為你收集整理的PHP 开发环境搭建的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【实用工具指南 一】OCR图片识别自动翻
- 下一篇: 动态规划算法php,php算法学习之动态