学习thinkPhp8遇到的坎和笔记
1、php8.5.4升级
thinkPhp8需要php>=8.0,我用的是wampserver服务器,就需要升级PHP到8.0以上,单独下载升级到php8.5.4(PHP: Downloads https://www.php.net/downloads.php),其中下载时windows选择了zip版只需要解压就可以,解压后放在wamp64\bin\php,设置系统变量。发现错误:PHP Warning: 'C:\WINDOWS\SYSTEM32\vcruntime140.dll' 14.20 is not compatible with this PHP build linked with 14.44 in Unknown on line 0 ,下载更新之后问题解决。更新包链接如下:https://aka.ms/vs/17/release/vc_redist.x64.exe。
2、wampserver服务器配置php8.5.4
(1)由于没有更新wampserver,所以就选择更新,更新时要将php.ini-development复制并更名为php.ini,同时打开进行一些设置,主要时打开ext;
(2)新建一个wampserver.conf文件,其输入如下:
<?php
$phpConf['phpIniDir'] = '.';
$phpConf['phpExeDir'] = '.';
$phpConf['phpConfFile'] = 'php.ini';
$phpConf['apache']['2.4']['LoadModuleName'] = 'php_module';
$phpConf['apache']['2.4']['LoadModuleFile'] = 'php8apache2_4.dll';
$phpConf['apache']['2.4']['AddModule'] = '';
?>
(3)向php8.5.4中添加phpForApache.ini,: 从其他版本中复制phpForApache.ini ,并对路径进行修改匹配。
3. Composer(https://getcomposer.org/download/)安装
安装时设计选择php.exe,会出现和php_pdo_firebird.dll有关的错误,解决办法在php.ini不加载pdo_firebird,成功安装。
4、thinkphp8安装
(1)安装过程出错,在命令行输入:composer create-project topthink/think 项目名;后中断,中断之后的后遗症就是没有vendor文件夹及中间内容,后执行 composer update --ignore-platform-reqs,提示:1.Loading composer repositories with package information 2. Updating dependencies 3.Your requirements could not be resolved to an installable set of packages.
果断修改国内下载网站:composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ (腾讯云 :https://mirrors.cloud.tencent.com/composer),执行 composer update --ignore-platform-reqs成功安装。
5、wampserver服务器启动项目
wampserver服务器更新至php8.5.4之后,新建网站站点php文件出错,最后切换到之前的php7之前的版本新建的站点后,转换到php8.5.4之后解决。
6、apache 的入口文件配置
(1) URL重写:找到项目根目录的pulic中的.htaccess中修改如下:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>
(2)配置httpd.conf:首先加载了mod_rewrite.so模块;二是修改入口文件名:
<IfModule dir_module>
DirectoryIndex index.php index.php3 index.html index.htm
</IfModule>
(3)修改C:/WINDOWS/system32/drivers/etc/hosts
127.0.0.1 tp8.cc
#::1 tp8.cc 将该行注释掉,可保证在本地以tp8.cc域名访问。
7、 thinkphp8中think/facade/view 中的方法出错
执行 composer require topthink/think-view
8、路由开启
注意设置 config/app.php 中 ,否则路由不起作用,
// 是否启用路由 'with_route' => true
更多推荐


所有评论(0)