因前一篇安装文章有顺序不对的情况,故写一篇简明直接的文章来叙述安装过程。
下面操作都是安装必须操作的步骤
(1)服务器环境性能配置
针对nginx、php、mysql的各项上传文件限制,执行超时时间、内存限制 等等都做相应调整,往大了设置。
(2)下载源码到服务器文件夹后,配置好域名访问。
(3)设置文件夹权限
一共需要给777权限的文件夹有:
You meet 5 out of 5 writable file permission requirements.
"{"path":"/magento/app/etc"}" writable directory permission. (这个是后台修改一些秘钥等配置时候会用到777权限)
"{"path":"/magento/var"}" writable directory permission.
"{"path":"/magento/pub/media"}" writable directory permission.
"{"path":"/magento/pub/static"}" writable directory permission.
"{"path":"/magento/generated"}" writable directory permission.
(4)删除php禁用函数
一般需要禁用的有openlog,syslog 两个函数,根据实际情况再进行其他禁用。
(5)配置PHP扩展
lib-libxml,ext-ctype,ext-gd,ext-spl,ext-dom,ext-simplexml,ext-mcrypt,ext-bcmath,ext-hash,ext-curl,ext-iconv,ext-intl,ext-xsl,ext-mbstring,ext-openssl,ext-zip,ext-pdo_mysql,ext-soap
实际经验来说,把ext-intl,ext-xsl 两个扩展安装一下即可,其他的基本自带安装有的。
这边还建议安装一个PHP缓存器扩展opcache,这个也是官方建议安装的。
(6)建好magento数据库
建好一个magento的数据库,utf8格式就行。
(7)安装检查报错open_basedir
Cannot determine required PHP extensions: Warning: is_readable(): open_basedir restriction in effect. File(/etc/pki/tls/certs/ca-bundle.crt) is not within the allowed path(s): (/var/www/magento/:/tmp/:/proc/) in /var/www/magento/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 (红色代码是需要加在后面的部分)
(8)安装完毕后访问基本会页面错乱,页面无法加载css js等样式文件
首先排除掉权限问题。
然后执行以下代码试试,看静态文件是否生成了:
php bin/magento setup:static-content:deploy -f en_US && php bin/magento cache:clean
按键盘F12,看到一些报错,出现404,类似:
http://www.example.com/static/version1511952472/frontend/Magento/luma/en_US/mage/loader.js
但是 访问下面链接,可以正常访问:
http://www.example.com/static/frontend/Magento/luma/en_US/mage/loader.js
可以看出,下面的路径比上面的少了 version1511952472 ,该文件夹实际上是不存在的,是通过 rewrite 来实现转向的。
首先后台是可以控制是否使用 static files versioning 的
设置 Sign Static Files
为 No 这样就不存在转向问题了。但是治标不治本。
因为你已经可能无法进入网站后台了,所以得直接改数据库记录。
可以先在mysql中查询是否存在这条数据,当然一般是不存在的,保险还是查询下,查询语句如下:
select * from core_config_data where path = 'dev/static/sign';
查不到那就执行插入语句:
insert into core_config_data(path, value) VALUES ('dev/static/sign', 0);
然后执行命令(shell命令):
php bin/magento cache:clean
(9)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 ,里面有个
②在引入项目根目录这行代码中,将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;
}
(10)上传图片权限设置
上传图片报错:file validation failed
解决办法:
/pub/media/wysiwyg 这个文件夹给777权限
fileinfo 安装php的fileinfo扩展