大家好,欢迎来到IT知识分享网。
前言
去年开始magento开发,发现国内magento相关的分享文章太少了。还好我大学的时候英文还可以,平时都是Google搜英文文档边开发边学习,过程及其痛苦难受/(ㄒoㄒ)/~~
最近公司网站升级到了magento2.4.6, 所以我需要本地Windows搭建2.4.6环境来开发工作。
以下内容是我融合了多篇英文文档,自己亲测有效的搭建流程,现分享出来供大家参考~
一、下载XAMPP8
开始之前,最好是把电脑的杀毒软件退出!
下载XAMPP
1.1、点击exe文件安装软件
勾选需要安装的模块,确定安装目录(最好放在一个目录第一层里,我的安装在:D:\xampp8_2_12)后,然后一路next
1.2、开启所需PHP扩展
安装完成后运行xampp,修改php.ini文件,开启magento所需的PHP扩展:intl, xsl, soap, gd, sodium, zip, sockets,openssl
去掉这些扩展前面的分号;
去掉分号后,重启apache(点击stop -> start 按钮)。
1.3、修改PHP配置, php.ini文件
max_execution_time=18000
max_input_time=1800
memory_limit=2G
1.4、修改apache的网址路径, httpd.conf
文件路径:D:\xampp8_2_12\apache\conf\httpd.conf
为了方便后续管理多个项目代码, 我把根目录设在 D:/www目录下
1.5、添加新安装的php8为环境变量
二、下载magento完整代码
2.1、下载代码
官方github的下载链接:Releases · magento/magento2 · GitHub (这里下载的代码没包含vendor目录,后续要自己执行composer命令安装)
我从这里下载的完整代码: Download Magento 2.4.6 | Version Archive – Magefan (后续无需composer命令安装)
下载zip文件,解压到D盘的www目录下,为了方便管理多个项目,我的代码存放目录:D:\www\m246
2.2、创建项目虚拟主机
— 在配置文件新增虚拟机配置: D:\xampp8_2_12\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80> DocumentRoot "D:/www/m246/pub" ServerName m246.com </VirtualHost> <VirtualHost *:80> DocumentRoot "D:/www" ServerName localhost </VirtualHost>
— 修改hosts C:\Windows\System32\drivers\etc\hosts
新增: 127.0.0.1 m246.com
— 重启apache
三、修正magento代码
3.1、Gd2.php
文件路径:D:\www\m246\vendor\magento\framework\Image\Adapter\Gd2.php
if ($url && isset($url['scheme']) && strlen($url['scheme']) > 1 && !in_array($url['scheme'], $allowed_schemes)) {
3.2、Validator.php
文件路径: D:\www\m246\vendor\magento\framework\View\Element\Template\File\Validator.php
3.3、di.xml
文件路径:D:\www\m246\app\etc\di.xml
我的不用修改,如果跟截图不一样,最好改成一样
四、安装elasticsearch
4.1、下载最新版本
官网下载最新版本: https://www.elastic.co/cn/downloads/elasticsearch
2024年7月最新版本是 8.14.3
4.2、在网址根目录解压zip
在apache的网址根目录下,我的是 D:/www目录下解压 zip文件,为了自己方便管理, 可以重命名文件夹名,我的解压后是这样的:
4.3、解决ES乱码
在D:\www\elasticsearch8_14_3\config\jvm.options 文件最后加上一行:
-Dfile.encoding=GBK
4.4、运行ES
直接双击 D:\www\elasticsearch8_14_3\bin\elasticsearch.bat 文件
等个几秒后,如果页面出现这个,就说明运行成功。可以从页面获取你的账号,密码
4.5、自定义配置
在 D:\www\elasticsearch8_14_3\config\elasticsearch.yml 增加如下自定义配置,修改后重启ES服务
#以下是自定义配置 # 换个集群的名字,免得跟别人的集群混在一起 cluster.name: el_lily # 换个节点名字 node.name: el_lily_m1 # 修改一下ES的监听地址,这样别的机器也可以访问 network.host: 0.0.0.0 #设置对外服务的http端口,默认为9200 http.port: 9200 #设置索引数据的存储路径 path.data: D:\www\elasticsearch8_14_3\data #设置日志文件的存储路径 path.logs: D:\www\elasticsearch8_14_3\logs # 关闭http访问限制 xpack.security.enabled: false # 增加新的参数,head插件可以访问es http.cors.enabled: true http.cors.allow-origin: "*" #----------------------- BEGIN SECURITY AUTO CONFIGURATION ----------------------- # # The following settings, TLS certificates, and keys have been automatically # generated to configure Elasticsearch security features on 19-07-2024 01:53:00 # # -------------------------------------------------------------------------------- # Enable security features #xpack.security.enabled: true #这里记得注释掉 xpack.security.enrollment.enabled: true # Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents xpack.security.http.ssl: enabled: true keystore.path: certs/http.p12 # Enable encryption and mutual authentication between cluster nodes xpack.security.transport.ssl: enabled: true verification_mode: certificate keystore.path: certs/transport.p12 truststore.path: certs/transport.p12 # Create a new cluster with the current node only # Additional nodes can still join the cluster later cluster.initial_master_nodes: ["el_lily_m1"] #这个要跟自定义的cluster.name保持一致 # Allow HTTP API connections from anywhere # Connections are encrypted and require user authentication http.host: 0.0.0.0 # Allow other nodes to join the cluster from anywhere # Connections are encrypted and mutually authenticated #transport.host: 0.0.0.0 #----------------------- END SECURITY AUTO CONFIGURATION -------------------------
4.6、在浏览器访问 http://localhost:9200
第一次访问需要输入在步骤4.4那里记录的账号、密码
访问成功:
4.7、ES可视化软件安装(可选)
这块下次有时间再更新, todo…..
五、创建数据库
5.1、设置mysql账号密码
— 在MySQL的 shell修改密码
mysqladmin.exe -u root password root
— 修改phpadmin的密码配置
5.2、新建数据库
按下图步骤创建:
六、命令安装magento
!!安装之前,切记要确保 elasticsearch、apache、MySQL服务都是开启的!!
6.1、安装命令
以下是我执行命令:
以下是我执行命令: php bin/magento setup:install --base-url="http://m246.com/" --db-host="localhost" --db-name="xampp_8_2_12" --db-user="root" --db-password="root" --admin-firstname="admin" --admin-lastname="admin" --admin-email="" --admin-user="admin" --admin-password="admin123" --language="en_US" --currency="USD" --timezone="America/Chicago" --use-rewrites="1" --backend-frontname="admin" --search-engine=elasticsearch8 --elasticsearch-host="localhost" --elasticsearch-port=9200 你们根据你们自己情况,修改以下配置项内容: –base-url: 在步骤2.2创建的域名 –db-name: 在步骤5.2创建的数据库名 –db-password: 在步骤5.1修改的密码
6.2、生成命令
依次执行下面命令,创建必须的magento文件
php bin/magento indexer:reindex php bin/magento setup:upgrade php bin/magento setup:static-content:deploy -f php bin/magento cache:flush
在浏览器访问项目
— 前台: http://m246.com
magento新版本默认没有 sample data,没有样板产品、分类数据、用户等数据,就一个光溜溜的店铺
— 后台:http://m246.com/admin
输入步骤6.1创建命令的账号密码 登录,如果出现下面报错,则执行命令:
php bin/magento module:disable Magento_TwoFactorAuth Magento_AdminAdobeImsTwoFactorAuth
登录成功页面:
七、添加sample data
7.1、邮箱注册一个adobe账号
Adobe Commerce Extensions & Themes for Your Online Store | Marketplace
7.2、创建公钥
创建access
这里public key就是下面要用到的 username
private key就是password
7.3、执行添加命令
在你magento项目根目录下执行: php bin/magento sampledata:deploy && php bin/magento indexer:reindex && php bin/magento se:up && php bin/magento se:s:d -f && php bin/magento c:f 第一次会让你输入username, password, 就是步骤7.2创建的公钥
执行成功界面:
7.4、如果有图片不显示
执行下面命令,重新生成图片
php bin/magento catalog:image:resize
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/139608.html