magento 网站迁移上线问题

目录

(1) 服务器参数设置

(2)清除缓存文件

(3)多站点多店铺访问设置

(4)报错Class Magento\User\Model\UserFactory does not exist

(5)报错open_basedir restriction in effect.

(6)nginx站点配置

(7)安装php-opcache扩展 

(8)删除测试订单数据

(9)更改后台地址

(10)后台登录之安全性

(11)去除index.php访问


(1) 服务器参数设置

php配置文件php.ini 中内存限制最少改为2G

memory_limit = 4096M (配置文件nginx.conf.sample中是给的4096M,统一)

项目文件夹直接给755权限,否则中途会出现无法预估的错误。

(2)清除缓存文件

 /var/cache

/var/page_cache

/var/session

/var/log

/var/tmp

/var/view

/var/view_preprocessed

...根据实际情况删除

(3)多站点多店铺访问设置

①先说代码中,根目录下index.php。加上下面代码(code指store view的属性值,type指store的属性值)

不用加默认访问的域名,这样就可以多个店铺用默认的 域名/admin 方式访问后台。默认域名与下面后台设置有关

$params = $_SERVER;

switch($_SERVER['HTTP_HOST']) {
    case 'fr.freetoo.cn':
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'fr';
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
    break;

    case 'uk.freetoo.cn':
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'uk';
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
    break;

 
}

②后台配置:

Magento的Base URL是用于访问商店页面的URL,您也可以为单独一个store view设置一个Base Url。
在改这项值之前请确保您的域名已经指向了网站所在服务器的IP,DNS解析完成后,才能通过域名正常访问。

要更改Magento的base url,您需要先进入后台
System > Configuration > Web > Unsecure > Base URL 

System > Configuration > Web > Secure > Base URL

Unsecure里面的Base Link URL、Base Skin URL、Base Media URL、Base JavaScript URL一般网站采用CDN技术的时候会更改,不用的时候呢,一般用系统默认值就可以了。
如果网站域名有SSL技术的,Secure里面的Base Url就要改成https://yourdomain.com

改完之后,各位记得刷新cache。

如果后台无法进入的时候,也可以通过数据库操作进行修改Base URL的:
进入phpmyadmin,找到对应的数据库,点击"core_config_data"表,很容易找到"web/unsecure/base_url"和"web/secure/base_url"两个值。

③还要改店铺的域名配置:

点击"core_config_data"表,

根据店铺多少来,每个店铺改成对应店铺域名:

(4)报错Class Magento\User\Model\UserFactory does not exist

Exception #0 (ReflectionException): Class Magento\User\Model\UserFactory does not exist
Exception #1 (ReflectionException): Class Magento\User\Model\UserFactory does not exist
Exception #2 (RuntimeException): The specified "/website/store/generated/code/Magento/User/Model/UserFactory.php.20764" file could not be written Warning!file_put_contents(/website/store/generated/code/Magento/User/Model/UserFactory.php.20764): failed to open stream: Permission denied
Class Magento\User\Model\UserFactory generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only.

解决办法:根目录下 /generated  文件夹要给777权限。

(5)报错open_basedir restriction in effect.

1 exception(s):
Exception #0 (Exception): Warning: is_readable(): open_basedir restriction in effect. File(/etc/pki/tls/certs/ca-bundle.crt) is not within the allowed path(s): (/website/store/:/tmp/:/proc/) in /website/store/vendor/composer/ca-bundle/src/CaBundle.php on line 85

解决办法:

看到上面报错可以看出:/etc/pki/tls/certs/ca-bundle.crt  这个文件路径不在open_basedir中,

解决办法有多个,这里因为是nginx环境,说两个:

(1)可以 在nignx配置中:nginx/conf/fastcgi.conf   

最下面加入一行:

fastcgi_param PHP_ADMIN_VALUE "open_basedir=/website/store/:/tmp/:/proc/:/etc/pki/tls/certs/ca-bundle.crt";

(2)如果项目根目录下有 .user.ini配置文件,则可以打开

修改为:

open_basedir=/website/store/:/tmp/:/proc/:/etc/pki/tls/certs/ca-bundle.crt

(6)nginx站点配置

在宝塔中,打开网站的站点配置文件。(这个配置文件的实际位置在/www/server/panel/vhost/nginx/www.xxx.com.conf)

①在顶部加入:

upstream fastcgi_backend {
#    # use tcp connection
#    # server  127.0.0.1:9000;
#    # or socket
    server   unix:/tmp/php-cgi-71.sock;
}

#这个sock路径来源在 php中的配置文件php-fpm.conf  ,里面有个listen

②在引入项目根目录这行代码中,将root修改下:

root /website/store;

修改为:

 set $MAGE_ROOT /website/store;

③引入nginx.conf.sample配置文件 

include /website/store/nginx.conf.sample;

nginx.conf.sample文件放在项目根目录下,内容如下(注意:memory_limit 设置大小)

## Example configuration:
# upstream fastcgi_backend {
#    # use tcp connection
#    # server  127.0.0.1:9000;
#    # or socket
#    server   unix:/var/run/php/php7.0-fpm.sock;
# }
# server {
#    listen 80;
#    server_name mage.dev;
#    set $MAGE_ROOT /var/www/magento2;
#    include /vagrant/magento2/nginx.conf.sample;
# }
#
## Optional override of deployment mode. We recommend you use the
## command 'bin/magento deploy:mode:set' to switch modes instead.
##
## set $MAGE_MODE default; # or production or developer
##
## If you set MAGE_MODE in server config, you must pass the variable into the
## PHP entry point blocks, which are indicated below. You can pass
## it in using:
##
## fastcgi_param  MAGE_MODE $MAGE_MODE;
##
## In production mode, you should uncomment the 'expires' directive in the /static/ location block

root $MAGE_ROOT/pub;

index index.php;
autoindex off;
charset UTF-8;
error_page 404 403 = /errors/404.php;
#add_header "X-UA-Compatible" "IE=Edge";

# PHP entry point for setup application
location ~* ^/setup($|/) {
    root $MAGE_ROOT;
    location ~ ^/setup/index.php {
        fastcgi_pass   fastcgi_backend;

        fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
        fastcgi_param  PHP_VALUE "memory_limit=4096M \n max_execution_time=600";
        fastcgi_read_timeout 600s;
        fastcgi_connect_timeout 600s;

        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ ^/setup/(?!pub/). {
        deny all;
    }

    location ~ ^/setup/pub/ {
        add_header X-Frame-Options "SAMEORIGIN";
    }
}

# PHP entry point for update application
location ~* ^/update($|/) {
    root $MAGE_ROOT;

    location ~ ^/update/index.php {
        fastcgi_split_path_info ^(/update/index.php)(/.+)$;
        fastcgi_pass   fastcgi_backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        include        fastcgi_params;
    }

    # Deny everything but index.php
    location ~ ^/update/(?!pub/). {
        deny all;
    }

    location ~ ^/update/pub/ {
        add_header X-Frame-Options "SAMEORIGIN";
    }
}

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

location /pub/ {
    location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
        deny all;
    }
    alias $MAGE_ROOT/pub/;
    add_header X-Frame-Options "SAMEORIGIN";
}

location /static/ {
    # Uncomment the following line in production mode
    # expires max;

    # Remove signature of the static files that is used to overcome the browser cache
    location ~ ^/static/version {
        rewrite ^/static/(version[^/]+/)?(.*)$ /static/$2 last;
    }

    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|json)$ {
        add_header Cache-Control "public";
        add_header X-Frame-Options "SAMEORIGIN";
        expires +1y;

        if (!-f $request_filename) {
            rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
        }
    }
    location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
        add_header Cache-Control "no-store";
        add_header X-Frame-Options "SAMEORIGIN";
        expires    off;

        if (!-f $request_filename) {
           rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
        }
    }
    if (!-f $request_filename) {
        rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
    }
    add_header X-Frame-Options "SAMEORIGIN";
}

location /media/ {
    try_files $uri $uri/ /get.php$is_args$args;

    location ~ ^/media/theme_customization/.*\.xml {
        deny all;
    }

    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
        add_header Cache-Control "public";
        add_header X-Frame-Options "SAMEORIGIN";
        expires +1y;
        try_files $uri $uri/ /get.php$is_args$args;
    }
    location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
        add_header Cache-Control "no-store";
        add_header X-Frame-Options "SAMEORIGIN";
        expires    off;
        try_files $uri $uri/ /get.php$is_args$args;
    }
    add_header X-Frame-Options "SAMEORIGIN";
}

location /media/customer/ {
    deny all;
}

location /media/downloadable/ {
    deny all;
}

location /media/import/ {
    deny all;
}

# PHP entry point for main application
location ~ (index|get|static|report|404|503|health_check)\.php$ {
    try_files $uri =404;
    fastcgi_pass   fastcgi_backend;
    fastcgi_buffers 1024 4k;

    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;
}

gzip on;
gzip_disable "msie6";

gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/xml+rss
    image/svg+xml;
gzip_vary on;

# Banned locations (only reached if the earlier PHP entry point regexes don't match)
location ~* (\.php$|\.htaccess$|\.git) {
    deny all;
}

(7)安装php-opcache扩展 

安装opcache扩展,加速php

(8)删除测试订单数据

相关文章链接:Magento中删除测试订单数据 | Alan Hou的个人博客

以下表中数据建议全部删掉,用delete语句,不要用truncate语句

--------《订单表》----------
sales_order                           
sales_order_address            
sales_order_grid                   
sales_order_item                  
sales_order_status_history   
sales_order_payment           

--------《发货表》----------
sales_shipment                   
sales_shipment_grid           
sales_shipment_item           

--------《发票表》----------

sales_invoice                  
sales_invoice_grid           
sales_invoice_item          

--------《报价表》----------
quote                                    
quote_address                
quote_address_item       
quote_item                      
quote_item_option          
quote_payment             

--------《客户其他表》----------
customer_log
customer_visitor

--------《其他表》----------

sendfriend_log                                       
report_event     

           

*************************************************************************************************************

下面这些表不用去数据库删,建议在系统后台删除customer所有客户,会自动连带删除所有数据。

--------《顾客地址表》----------

customer_address_entity  #会自动连带删除
customer_address_entity_datetime        
customer_address_entity_decima
customer_address_entity_int
customer_address_entity_text
customer_address_entity_varchar

--------《客户实体表》----------

customer_entity   #前台用户表
customer_entity_datetime
customer_entity_decimal
customer_entity_int
customer_entity_text
customer_entity_varchar

-----------《购物清单》----------

wishlist   #会自动连带删除

****************************************************************************************************************

(9)更改后台地址

更改命令:php bin/magento setup:config:set --backend-frontname="newadminpath"

清除缓存:php bin/magento cache:clean

如果页面还有问题就重新生成静态文件。

(10)后台登录之安全性

在后台设置: "Stores > Configuration > Advance > Admin > Security" 

1. Admin Account Sharing                          是否能够同时登录的设置

2.Password Reset Protection Type            在此可选择密码重置的保护类型

3.Recovery Link Expiration Period (hours)   密码重置连结需要有时间限定,在此单位为hours,当客户收到密码重置连结后,如下图所示设定,管理者需要在2小时内做变更,过后则此连结无效

4.Max Number of Password Reset Requests   限制每小时可以申请忘记密码的次数,您也可以设定为0,不得要求做密码重置设定。

5.Min Time Between Password Reset Requests  重置密码要求的最短时间,用来延迟密码重置请求发出后的间隔时间(分钟)

6.Add Secret Key to URLs     设定是否新增一些密号编码在URLs中

7.Login is Case Sensitive     设定密码需不需要辨识大小写(一般设置NO)

8.Admin Session Lifetime (seconds)  设定管理者帐号的Session停留时间(单位:秒),若管理者在登入后台后,超过该时间没有做任何动作的话,将会被踢出去,至要求输入帐号密码的地方。

9.Maximum Login Failures to Lockout Account   设定帐号的最高失败次数,预设为6次,当超过6次后,Magento将会锁住该帐号一段时间(看设定多久),让您无法使用该帐号进行登入,以策帐号的安全性

10.Lockout Time (minutes)  当登入失败超过指定次数后,帐号被锁住的时间,预设为30分钟

11.Password Lifetime (days)   设定密码Lifetime,预设为90天,也就是90天后,系统就会自动强迫您该换密码啰!

12.Password Change    当超过密码Lifetime天数后,预设是会强迫您更换新密码,当然您也是可以选择Recommended,但建议还是采用预设的Forced确保安全

(11)去除index.php访问

如果网站需要单独配置,去除index.php访问请用这个。

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值