magento安装

(1)安装包下载

在magento的中文社区中:Magento2 | Magento中文

推荐composer安装,下载安装包到服务器解压,再安装也行。

(2)执行安装(先看下面报错,一个个解决再访问安装,否则各种不知名错误)

执行安装我们是配置好了域名进行访问的,首先域名做去index.php处理。

location / { 
	   if (!-e $request_filename) {
		rewrite  ^(.*)$  /index.php?s=/$1  last;
		break;
	  }
    }

①如果是2.2.x版本的magento。访问项目文件根目录(网址),会出现以下提示:

Fatal error: Uncaught Magento\Framework\Exception\FileSystemException: The file "/magento/var/.regenerate" cannot be deleted Warning!unlink(/var/www/magento/var/.regenerate):

意思是:无法删除项目根目录下 /var/.regenerate文件,我们可以手动删除。

②2.2.x接下来可能遇到的报错:

Fatal error: Uncaught Magento\Framework\Exception\FileSystemException: Directory "/magento//var/log" cannot be created Warning!mkdir(): 

这个是文件权限不够,给上777权限即可。

一共需要给权限的有:

You meet 5 out of 5 writable file permission requirements. 

  • "{"path":"/magento/app/etc"}" writable directory permission. (etc先考虑不给777试试 ,安装完了也要改为755或以下权限)
  • "{"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.

③安装的时候会有提示哪些需要给777权限,一般测试的话,直接给整个项目文件夹777权限。

④如果是2.3.x版本把安装包下载到服务器后,访问项目文件根目录。会发现出现以下提示:

Autoload error

Vendor autoload is not found. Please run 'composer install' under application root directory.

首先先确定服务器已经安装了composer。

然后需要进入到项目文件的根目录下,执行命令composer install(shell命令)去安装项目依赖的插件。

⑤安装时期建议提前安装下面扩展,否则报错(我这边实际只出现问题1,建议缺少哪个扩展装哪个扩展,装多了bug多):

Problem 1
    - The requested PHP extension ext-xsl * is missing from your system. Install or enable PHP's xsl extension.

 

Problem 2
- The requested PHP extension ext-intl * is missing from your system. Install or enable PHP's intl extension.

如果服务器是linux服务器,安装了宝塔面板,宝塔自带的PHP是可以直接安装这两个扩展的。

这里我写下手动安装的过程:

进入cd /www/server/php/71/src/ext/xsl   (这里根据自己php安装的目录来实际填写)
执行  phpize && ./configure --with-php-config=/www/server/php/56/bin/php-config && make && make install

在这个configure的过程中如果出现错误,安装相应的lib就行。
yum install libicu-devel -y
yum install libxslt-devel -y


cd /www/server/php/71/src/ext/intl    (这里根据自己php安装的目录来实际填写)
phpize && ./configure --with-php-config=/www/server/php/56/bin/php-config && make && make install


修改php.ini

增加:
extension=/www/server/php/71/lib/php/extensions/no-debug-non-zts-20160303/xsl.so
extension=/www/server/php/71/lib/php/extensions/no-debug-non-zts-20160303/intl.so

⑥最后,继续进入到项目根目录下,执行composer install  命令

最后安装完成。截图如下:

(3)访问生成项目

如果是2.2.x版本,直接访问 http://域名 

如果是2.3.x版本,访问 http://域名/setup/index.php

然后出现图形化安装界面,最后一步需要先在服务器的数据库上新建这个项目的数据库。

执行安装耗能比较大,建议修改下php.ini配置再安装。

max_execution_time = 6000
max_input_time = 6000
memory_limit = 1024M

 

服务器性能越好,内存可以改更大值。

(4)安装中出现错误

Fatal error: Uncaught Exception: Warning: openlog() has been disabled for security reasons in /var/www/magento/vendor/monolog/monolog/src/Monolog/Handler/SyslogHandler.php on line 62

这段话的意思是告诉我们由于安全考虑 openlog() 函数被禁用,如果你有服务器管理权限请修改 php.ini 配置文件参数并重启nginx。

具体实例:在php.ini中存在 disable_functions配置,默认配置中,cli执行函数都是被禁止的,如果需要的话,需要在php.ini中将 disable_functions = phpinfo,exec , popen, system ….,将你需要执行的函数从列表中删掉再重启nginx即可.

这里写一下我实际安装遇到报错需要去除的函数有(请安装前一次性全部去掉):

openlog,syslog,

(5)安装完毕访问,页面无法加载css js等样式文件

首先排除掉权限问题。

然后执行以下代码试试,看静态文件是否生成了:

php bin/magento setup:static-content:deploy -f en_US && php bin/magento cache:clean

如果已经生成了,那么很可能是 rewrite 问题。

按键盘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 这样就不存在转向问题了。但是治标不治本。

因为你已经可能无法进入后台了,所以得直接改数据库记录。

可以先查询是否存在这条数据,当然一般是不存在的,保险还是查询下,查询语句如下:

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

方法二

Apache 下,按照一般情况,在 pub/static/.htacess 中是设置好了的:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Remove signature of the static files that is used to overcome the browser cache
    RewriteRule ^version.+?/(.+)$ $1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule .* ../static.php?resource=$0 [L]
</IfModule>

Nginx 设置,以下仅供参考:

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\d*/)?(.*)$ /static/$2 last;
    }

    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;

        if (!-f $request_filename) {
            rewrite ^/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 ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
        }
    }
    if (!-f $request_filename) {
        rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
    }
    add_header X-Frame-Options "SAMEORIGIN";
}

(6)后台访问去除index.php

STORES->Configuration->Web->Search Engine Optimization ->Use Web Server Rewrites ->设置为Yes

nginx环境不建议用此设置,建议直接修改nginx配置文件来去除index.php。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值