magento换域名和服务器要怎么操作
今天客户让ytkah帮忙把magento迁移到新服务器并换新域名,很多朋友可能在迁移过程中遇到了很多问题,下面就整理一下亲测可用的步骤吧。本文以magento 1.9.2.4为例,环境是lnmp,centos7.8,php版本为5.6,mysql为8.0.20,NGINX为1.17.10
1、打包压缩原网站的文件和数据库
2、在新服务器上创建站点,并添加NGINX规则
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | location / { index index.html index.php; ## Allow a static html file to be shown first try_files $uri $uri / @handler; ## If missing pass the URI to Magento's front handler allow all; } ## These locations would be hidden by .htaccess normally location ^~ /app/ { deny all; } location ^~ /includes/ { deny all; } location ^~ /lib/ { deny all; } location ^~ /media/downloadable/ { deny all; } location ^~ /pkginfo/ { deny all; } location ^~ /tmp/ { deny all; } location ^~ /report/config.xml { deny all; } location ^~ / var / { deny all; } location ^~ / var /rw_google_base/ { allow all; } location ^~ /media/catalog/product/ { allow 116.6.89.107;} location ^~ /media/catalog/product/cache/ {allow all;} location / var /export/ { ## Allow admins only to view export folder auth_basic "Restricted" ; ## Message shown in login window auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword autoindex on; } location /. { ## Disable .htaccess and other hidden files return 404; } location @handler { ## Magento uses a common front handler rewrite / /index.php; } location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler rewrite ^(.*.php)/ $1 last; } rewrite ^/minify/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f= $2 &d= $1 last; rewrite ^/skin/m/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f= $2 &d= $1 last; location /lib/minify/ { allow all; } location ~ .php$ { ## Execute PHP scripts if (!-e $request_filename ) { rewrite / /index.php last; } ## Catch 404s that try_files miss expires off; ## Do not cache dynamic content fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_param SCRIPT_FILENAME $document_root $fastcgi_script_name ; fastcgi_param MAGE_RUN_CODE default ; ## Store code is defined in administration > Configuration > Manage Stores fastcgi_param MAGE_RUN_TYPE store; include fastcgi_params; ## See /etc/nginx/fastcgi_params } |
3、上传网站文件到新服务器,并解压,将/var/session/,/var/cache/,/var/tmp/三个文件夹里面的文件都清除,并赋予他们可写权限,否则magento迁移服务器时提示Mage registry key "_resource_helper/core" already exists
4、修改magento的配置文件,位置在app/etc/local.xml,注意修改CDATA里面的内容 主要是数据库连接数据库用户名 密码 数据库名称
1 2 3 4 5 6 | <host><![CDATA[localhost]]></host> <username><![CDATA[ytkah]]></username> <password><![CDATA[ytkah-pwd]]></password> <dbname><![CDATA[ytkah-db]]></dbname> <initStatements><![CDATA[SET NAMES utf8]]></initStatements> <model><![CDATA[mysql4]]></model> |
5、导入数据库,建议用命令导入( phpmyadmin导入经常提示错误或者无法导入,因为magento的数据库使用了外键约束,通过phpmyadmin导入的时候会报错,在导出的sql文件上加一行
5.1进入数据库,
1 | mysql -u ytkah -p |
输入密码
5.2显示所有数据库
1 | show databases; |
5.3选择数据库
1 | use ytkah数据库名; |
显示数据表
1 | show tables; |
5.4导入数据库
1 | source /home/ytkah.sql; |
6、修改域名
1 | update core_config_data set value= 'https://www.cnblogs.com/ytkah/' where path like '%secure/base_url' ; |
修改magento数据库,core_config_data表中的path为web/unsecure/base_url和web/secure/base_url的内容,为你网站的新域名,注意域名后面的“/”。更换网站完整域名+/ http://www.abc.com/
7、记得退出数据库
1 | exit (回车) |
访问站点试试,再访问后台清理一下缓存,最后测试相关功能是不是正常
到此,magento迁移服务器算正式完成了

加微信交流
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2019-09-02 wordpress不同分类调用不同的模板
2019-09-02 wordpress调用指定tag的文章