本次安装基于windos10+phpstudy8.1.1.3+magento2.3.6。
安装步骤很简单,安装phpstudy,下载magento,配置nginx或apache,安装magento,访问站点。
但是安装过程,遇到的坑着实不少。。。
1、安装phpstudy(含composer)。
略。
2、下载magento。
保证网络可用的情况下,需要做的事情就是耐心等待。(我用了几个小时才下载完毕)
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.3.6 . -vvv
3、配置nginx。
修改自动生成的vhost,如下:
upstream fastcgi_backend {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name local.magento.com;
error_log D:/phpstudy_pro/Extensions/Nginx1.15.11/logs/local.magento.com_error.log;
access_log D:/phpstudy_pro/Extensions/Nginx1.15.11/logs/local.magento.com_acess.log;
set $MAGE_ROOT G:/magento;
include G:/magento/nginx.conf.sample;
}
修改nginx.conf.sample,如下:
# PHP entry point for main application
location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {
try_files $uri =404;
fastcgi_pass fastcgi_backend;
# fix: upstream sent too big header
#fastcgi_buffers 1024 4k;
fastcgi_buffers 16 256k;
fastcgi_buffer_size 256k;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=756M \n max_execution_time=18000";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
4、安装magento。
magento2.3仍旧可以使用url安装的方式,magento2.4开始,只能通过命令行安装了。
如果nginx配置成功,可以通过访问local.magento.com,根据提示进行安装。
这里采用命令行安装的方式,也建议大家采用命令行的方式安装。
手动创建数据库后,执行以下命令进行安装即可。
php bin/magento setup:install --base-url=http://local.magento.com --db-host=localhost --db-name=magento --db-user=magento --db-password=magento --admin-firstname=admin --admin-lastname=admin --admin-email=admin@admin.com --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1
安装过程中,如果出现以下错误,修改vendor/magento/framework/Image/Adapter/Gd2.php文件的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) && !file_exists($filename)) {
return false;
}
return true;
}
5、访问站点。
如果出现以下配置,则插入配置dev/template/allow_symlink,设置为1,更新缓存即可。
insert into core_config_data(`path`,`value`) values('dev/template/allow_symlink', 1);
如果使用apache的,需要注意以下几点:
1、.htaccess的内容会被phpstudy清空,重新复制.htaccess.sample中的内容即可。
2、php_value和php_flag相关的error,这是由于phpstudy的php 默认版本缺少php7apache2_4.dll的原因。解决方案:到https://windows.php.net/downloads/releases/archives/下载新的php版本并替换(或多版本兼容)。
并在httpd.conf添加以下配置:
LoadModule php7\_module "D:\\\\phpstudy\_pro\\\\Extensions\\\\php\\\\php7.3.4nts\\\\php7apache2\_4.dll"
3、IfVersion相关的error。解决方案:修改httpd.conf,加载version_module模块。
LoadModule version_module modules/mod_version.so
转自Magento2开发实例
https://www.kancloud.cn/liguojia1987/magento2/2527100