一: 下载 magento2 安装包,可以去 magento官方的github 下载指定你所需的版本;
二: 解压到指定目录,配置环境,使用phpstudy点击安装composer 然后添加系统环境变量;
执行 composer install -vvv 下载magento运行所需的包;
三:根据配置的域名来到magento2安装面板,环境检测一步步走下去就好;
四: 安装时候需要修改的文件;修改GD2文件
lib\internal\Magento\Framework\Image\Adapter\Gd2.php
找到函数 function validateURLScheme,进行如下修改
private function validateURLScheme(string $filename) : bool
{
$allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
$url = parse_url($filename);
//if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes)) {
if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename)) {
return false;
}
return true;
}
继续执行安装,安装完成;
访问站点会发现没有样式问题:
还需要修改 lib\internal\magento\framework\View\Element\Template\File\Validator.php 的函数isPathInDirectories
protected function isPathInDirectories($path, $directories)
{
if (!is_array($directories)) {
$directories = (array)$directories;
}
$realPath = $this->fileDriver->getRealPath($path);
$realPath = str_replace('\\', '/', $realPath);
foreach ($directories as $directory) {
if (0 === strpos($realPath, $directory)) {
return true;
}
}
return false;
}
CSS JS 文件 404 执行
php magento setup:static-content:deploy -f
如果admin和店铺端没有样式还是没有样式
可能在服务器上启用了版本控制,因此请通过运行以下查询进入数据库然后进行检查来禁用它。
insert into core_config_data (config_id, scope, scope_id, path, value) values (null, 'default', 0, 'dev/static/sign', 0);
再重复执行安装静态文件 清理缓存
php bin/magento setup:static-content:deploy -f
php bin/magento cache:clean
php bin/magento cache:flush