服务器环境配置
php 7.0-7.3(不要用7.4,会报__toString()错误,反正我现在安装的版本会有这个问题)
mysql 5.6以上
php memory_limit 设置为 2000M
查看是否禁用下面的函数,如果有禁用解除
syslog,openlog,exec,system,syformlink,proc_open
查看是否安装下面的php扩展,如果没有安装上
bcmath ctype curl dom gd hash iconv intl mbstring openssl pdo_mysql simplexml soap xsl zip libxml
下载magento 2.x到你的网站目录,如果是网站目录打开了防跨站攻击(open_basedir),安装的时候记得先关闭。 删除原有的.user.ini,index.html,404.html,特别是.user.ini一定要删除,因为magento有个配置文件要覆盖它
解压magento到网站根目录
然后SSH连接你的服务器,进入到网站根目录
切换默认php版本为7.x, 我用的宝塔,设置命令如下:
rm -f /usr/bin/php
ln -sf /www/server/php/73/bin/php /usr/bin/php
切换用户到www 命令:su www
如果切换不了 输入命令 vi /etc/passwd
找到 www开头的这一行
把/sbin/nologin 改成/bin/bash
然后就是安装了
php bin/magento setup:install –base-url=”http://www.xxx.com/” –db-host=”localhost” –db-name=”dbname” –db-user=”dbusername” –db-password=”dbpassword” –admin-firstname=”admin” –admin-lastname=”admin” –admin-email=”depyou@gmail.com” –admin-user=”admin” –admin-password=”admin123″ –language=”en_US” –currency=”USD” –timezone=”America/Chicago” –use-rewrites=”1″ –backend-frontname=”admin”
OK, 完成
如果你用的nginx把下面的伪静态规则加上
location /{
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}location /pub/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 ~ ^/pub/static/version {
rewrite ^/pub/static/(version\d*/)?(.*)$ /pub/static/$2 last;
}
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|html|json)$ {
add_header Cache-Control “public”;
add_header X-Frame-Options “SAMEORIGIN”;
expires +1y;if (!-f $request_filename) {
rewrite ^/pub/static/(version\d*/)?(.*)$ /static.php?resource=$2 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 ^/pub/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
}
if (!-f $request_filename) {
rewrite ^/pub/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
add_header X-Frame-Options “SAMEORIGIN”;
}location /pub/media/ {
try_files $uri $uri/pub/ /pub/get.php$is_args$args;location ~ ^/pub/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/pub/ /pub/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/pub/ /pub/get.php$is_args$args;
}
add_header X-Frame-Options “SAMEORIGIN”;
}
进入前后台如果没有js 和 css文件执行下面的命令
php -f bin/magento setup:upgrade
rm -rf cache/* page_cache/* generation/*
php -f bin/magento setup:di:compile
php -f bin/magento setup:static-content:deploy -f
php -f bin/magento cache:flush