步骤1-安装Nginx
参考官方文档:https://devdocs.magento.com/guides/v2.4/install-gde/prereq/nginx.html#install-nginx-1
在此步骤中,我们将从epel存储库安装Nginx。默认情况下,Epel不可用,因此我们需要在安装Nginx之前安装epel存储库。
使用此yum命令安装epel-repository。
yum -y install epel-release
现在,我们可以从epel存储库安装Nginx。
yum -y install nginx
安装完成后,启动Nginx并将其添加以在启动时启动。
systemctl start nginx
systemctl enable nginx
Nginx在端口80上启动,您可以使用下面的netstat命令进行检查。
netstat -plntu
如果您看到结果“找不到命令”,则可以像这样安装net-tools。
yum -y install net-tools
步骤2-安装php7.3
sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum -y install epel-release yum-utils
sudo yum-config-manager --disable remi-php54
sudo yum-config-manager --enable remi-php73
yum -y install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json
yum -y install php php-iconv php-intl php-mbstring php-openssl php-pdo_mysql php-simplexml php-soap php-xsl php-zip php-bcmath php-ctype php-dom php-gd php-hash
yum -y install php-mbstring git unzip
步骤3-安装和配置PHP-FPM
在本教程中,我们将使用PHP-FPM 7进行Magento安装。我将使用Webtatic存储库中的PHP 7软件包。
下载新的Webtatic仓库并将其添加到系统。
yum -y install php70w-fpm
2./etc/php.ini在编辑器中打开文件
3.取消注释该cgi.fix_pathinfo行并将其值更改为0。
4.编辑文件以匹配以下行:
memory_limit = 2G
max_execution_time = 1800
zlib.output_compression = On
5.取消注释会话路径目录并设置路径:
session.save_path = "/var/lib/php/session"
保存退出
6./etc/php-fpm.d/www.conf在编辑器中打开。
7.编辑文件以匹配以下行:
user = nginx
group = nginx
listen = /run/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
8.取消注释环境线:
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
保存并退出
9.为PHP会话路径创建一个新目录,并将所有者更改为apache用户和组:
mkdir -p /var/lib/php/session/
chown -R apache:apache /var/lib/php/
sudo chmod 777 /var/lib/php/session
10.为php-fpm路径创建一个新目录,并将所有者更改为apache用户和组:
mkdir -p /run/php-fpm/
chown -R apache:apache /run/php-fpm/
11.启动php-fpm服务并将其配置为在引导时启动:
systemctl start php-fpm
systemctl enable php-fpm
12.验证php-fpm服务正在运行:
netstat -pl | grep php-fpm.sock
步骤4-安装Elasticsearch
先安装java环境
yum -y install java-1.8.0-openjdk
在安装Magento Commerce或Magento Open Source 2.4.0之前,您必须安装Elasticsearch。有关详细信息,请参见Elasticsearch。
1、https://devdocs.magento.com/guides/v2.4/install-gde/prereq/elasticsearch.html
2、https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html
3、https://www.elastic.co/guide/en/elasticsearch/reference/current/targz.html
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.1-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.1-linux-x86_64.tar.gz.sha512
shasum -a 512 -c elasticsearch-7.9.1-linux-x86_64.tar.gz.sha512
# centos7解决shasum: command not found的问题
yum install -y perl-Digest-SHA
tar -xzf elasticsearch-7.9.1-linux-x86_64.tar.gz
cd elasticsearch-7.9.1/
./bin/elasticsearch
如果安装后启动出错:
[2020-09-24T19:11:05,214][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [localhost.localdomain] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:174) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127) ~[elasticsearch-cli-7.9.1.jar:7.9.1]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.9.1.jar:7.9.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.9.1.jar:7.9.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:111) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:178) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:393) ~[elasticsearch-7.9.1.jar:7.9.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.9.1.jar:7.9.1]
... 6 more
uncaught exception in thread [main]
java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:111)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:178)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:393)
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
For complete error details, refer to the log at /root/elasticsearch-7.9.1/logs/elasticsearch.log
解决:
groupadd elasticsearch
useradd elasticsearch -g elasticsearch -p elasticsearch
cd /opt
chown -R elasticsearch:elasticsearch /root/elasticsearch-7.9.1
chmod o+x /root/ /root/elasticsearch-7.9.1/
chgrp elasticsearch /root/elasticsearch-7.9.1/
su - elasticsearch
cd /root/elasticsearch-7.9.1
./bin/elasticsearch
后台启动:
./bin/elasticsearch -d
检验是否安装成功:
[root@iZj6c5w0d1f4ltvrd3ukfrZ ~]# curl 127.0.0.1:9200
成功返回如下:
{
"name" : "iZj6c5w0d1f4ltvrd3ukfrZ",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "9NRUr8r-QRSOZ_6b2Eli2w",
"version" : {
"number" : "7.9.1",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "083627f112ba94dffc1232e8b42b73492789ef91",
"build_date" : "2020-09-01T21:22:21.964974Z",
"build_snapshot" : false,
"lucene_version" : "8.6.2",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
失败返回如下:
curl: (7) Failed connect to 127.0.0.1:9200; 拒绝连接
启动报错如下:
1.max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144
解决:
sudo sysctl -w vm.max_map_count=262144
2.the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
解决:
进入/elasticsearch-7.10.0/config/elasticsearch.yml
把以下配置注释:
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["127.0.0.1"]
cluster.initial_master_nodes: ["127.0.0.1"]
步骤5-安装数据库mysql并配置magento
安装mysql:
yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
yum install mysql-community-server
启动:
systemctl start mysqld
systemctl enable mysqld
查看默认密码:
grep 'temporary' /var/log/mysqld.log
用随机密码链接登陆后并修改:
mysql -u root -p
TYPE DEFAULT PASSWORD
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
flush privileges;
create database magentodb;
create user magentouser@localhost identified by 'Magento123@';
grant all privileges on magentodb.* to magentouser@localhost identified by 'Magento123@';
flush privileges;
设置数据库编码
CREATE DATABASE magentodb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
步骤6-安装PHP Composer
上次测试安装太高版本安装magento会出错,目前安装较低版本,最好进入到magento目录安装composer!
安装最新版本:
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
安装指定版本:
获取哈希:
https://composer.github.io/pubkeys.html
验证:
HASH=c31c1e292ad7be5f49291169c0ac8f683499edddcfd4e42232982d0fd193004208a58ff6f353fde0012d35fdd72bc394
php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --version=1.10.13
查看版本:
php composer.phar -v
添加软连接:
ln -s /var/www/magento2/composer.phar /usr/bin/composer
步骤7-下载并解压缩Magento
1.下载压缩包
cd /var/www/
wget https://github.com/magento/magento2/archive/2.4.zip
unzip 2.4.zip
mv magento2-2.4 magento2
2.直接用composer下载:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
安装PHP依赖项
cd magento2
composer install -v
等待安装完即可!
错误:
Your lock file does not contain a compatible set of packages. Please run composer update.
错误:
[root@localhost magento2]# php composer.phar -v
Could not open input file: composer.phar
解决:
php -r "readfile('https://getcomposer.org/installer');" | php
步骤8-配置Magento虚拟主机
参考官方文档:
https://devdocs.magento.com/guides/v2.3/install-gde/prereq/nginx.html#configure-nginx-centos
1.事先把基础配置文件中http里面的server配置先删掉,防止访问域名或者ip显示nginx或centos默认页面!:
cd /etc/nginx/
vim nginx.conf
2.创建配置文件:
cd /etc/nginx/
vim conf.d/magento.conf
3.现在测试配置。如果没有错误,请重新启动Nginx服务。
upstream fastcgi_backend {
server unix:/run/php-fpm/php-fpm.sock;
}
server {
listen 80;
server_name test.com;
set $MAGE_ROOT /var/www/magento2;
set $MAGE_MODE developer;
include /var/www/magento2/nginx.conf.sample;
}
4.重启nginx
nginx -t
systemctl restart nginx
设置文件权限:
cd /var/www/html/<magento install directory>
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R :www-data . # Ubuntu
chmod u+x bin/magento
步骤9-安装magento
php bin/magento setup:install --backend-frontname="adminlogin" \
--key="biY8vdWx4w8KV5Q59380Fejy36l6ssUb" \
--db-host="localhost" \
--db-name="magentodb" \
--db-user="magentouser" \
--db-password="Magento123@" \
--language="en_US" \
--currency="USD" \
--timezone="America/New_York" \
--use-rewrites=1 \
--use-secure=0 \
--base-url="http://test.com" \
--base-url-secure="https://magento.hakase-labs.com" \
--admin-user=adminuser \
--admin-password=admin123@ \
--admin-email=admin@newmagento.com \
--admin-firstname=admin \
--admin-lastname=user \
--cleanup-database
更改以下值:
–backend-frontname:Magento管理员登录页面“ adminlogin”
–key:生成自己的密钥
–db-host:数据库主机本地主机
–db-name:数据库名称’magentodb’
–db-user:数据库用户“ magentouser”
–db-password:数据库密码’ Magento123 @ ’
–base-url:Magento URL
–admin-user:您的管理员用户
–admin-password:您的Magento管理员密码
–admin-email:您的电子邮件地址
实例安装
php bin/magento setup:install --base-url="http://www.test.com" \
--db-host="127.0.0.1" \
--db-name="magento" \
--db-user="magento1" \
--db-password="mangento_test" \
--admin-firstname="admin" \
--admin-lastname="user" \
--admin-email="test@163.com" \
--admin-user="admin" \
--admin-password="password" \
--language="en_US" \
--currency="USD" \
--timezone="America/Chicago" \
--use-rewrites="1"
注意:Magento 2.4已安装。运行以下命令以更改etc目录的权限,并将magento2目录的所有者更改为“ nginx”用户,否则打开网站是空白页。
chmod 700 /var/www/magento2/app/etc
chown -R nginx:nginx /var/www/magento2
步骤10-配置SELinux和Firewalld
sestatus
使用下面的yum命令安装SELinux管理工具’policycoreutils-python’。
yum -y install policycoreutils-python
运行以下命令以更改Magento文件和目录的安全上下文。
cd /var/www/
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento2(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento2/app/etc(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento2/var(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento2/pub/media(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento2/pub/static(/.*)?'
restorecon -Rv '/var/www/magento2/'
SELinux配置完成。现在我们需要配置firewalld。
yum -y install firewalld
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
步骤11-测试magento
打开您的Web浏览器,然后浏览Magento URL。我的是:
test.com
如果页面提示以下错误 ,则说明安装有误:
There has been an error processing your request
Exception printing is disabled by default for security reasons.
Error log record number: 59c3e7c48a96ebaf4a8a7cd3b5318cf4a042c03ad88c6859897c170ec587ac54
转到magento/var/report并使用错误日志记录编号名称(即673618173351您的情况)打开文件。在该文件中,您可以找到错误的完整描述。
对于像system.log和的日志文件exception.log,请转至magento/var/log/
以上错误日志为:
SESSION ERROR open(/var/lib/php/session) Permisison Denied (13) [duplicate] 就是
解决:
sudo chmod 777 /var/lib/php/session
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento cache:clean
php bin/magento cache:flush
参考:
https://mirasvit.com/knowledge-base/magento-2-there-has-been-an-error-processing-your-request.html
解决完重新访问首页,您将看到默认的Magento主页。
接下来,通过打开adminlogin URL登录到管理仪表板
访问:
test.com/admin_1qf4s3
登陆到后台:
常见错误
1.登陆后台出错:
Failed to send the message. Please contact the administrator
解决方案:
bin/magento module:disable Magento_TwoFactorAuth
2.出现以下错误:
One or more indexers are invalid. Make sure your Magento cron job is running.
解决方案:
php bin/magento indexer:reindex
3.安装php-fpm出错:
[root@localhost ~]# systemctl restart php-fpm.service
Job for php-fpm.service failed because the control process exited with error code. See "systemctl status php-fpm.service" and "journalctl -xe" for details
9月 25 01:06:01 localhost.localdomain systemd[1]: Starting LSB: starts the nginx web server...
-- Subject: Unit nginx.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has begun starting up.
9月 25 01:06:01 localhost.localdomain nginx[2731]: Starting nginx... done
9月 25 01:06:01 localhost.localdomain polkitd[670]: Unregistered Authentication Agent for unix-process:2721:242390 (system bus name :1.64, object path
9月 25 01:06:01 localhost.localdomain systemd[1]: Started LSB: starts the nginx web server.
-- Subject: Unit nginx.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has finished starting up.
--
-- The start-up result is done.
9月 25 01:06:12 localhost.localdomain polkitd[670]: Registered Authentication Agent for unix-process:2737:243460 (system bus name :1.65 [/usr/bin/pktty
9月 25 01:06:12 localhost.localdomain systemd[1]: Starting The PHP FastCGI Process Manager...
-- Subject: Unit php-fpm.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit php-fpm.service has begun starting up.
9月 25 01:06:12 localhost.localdomain php-fpm[2743]: [25-Sep-2020 01:06:12] ERROR: [pool www] cannot get uid for user 'nginx'
9月 25 01:06:12 localhost.localdomain php-fpm[2743]: [25-Sep-2020 01:06:12] ERROR: FPM initialization failed
9月 25 01:06:12 localhost.localdomain systemd[1]: php-fpm.service: main process exited, code=exited, status=78/n/a
9月 25 01:06:12 localhost.localdomain systemd[1]: Failed to start The PHP FastCGI Process Manager.
-- Subject: Unit php-fpm.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit php-fpm.service has failed.
--
-- The result is failed.
9月 25 01:06:12 localhost.localdomain systemd[1]: Unit php-fpm.service entered failed state.
9月 25 01:06:12 localhost.localdomain systemd[1]: php-fpm.service failed.
9月 25 01:06:12 localhost.localdomain polkitd[670]: Unregistered Authentication Agent for unix-process:2737:243460 (system bus name :1.65, object path
解决方案:
useradd nginx
groupadd nginx
usermod -G nginx nginx
systemctl restart php-fpm.service
4.出现错误:
[root@localhost ~]# composer
Do not run Composer as root/super user! See https://getcomposer.org/root for details
解决方案:
```shell
export COMPOSER_ALLOW_SUPERUSER=1
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
5.出现以下错误:
Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
Authentication required (repo.magento.com):
Username:
解决方案:
composer config http-basic.repo.magento.com <public_key> <private_key>
其中public_key、private_key需要提前注册账号并登陆后台查看:
6.不小心更改了权限导致页面无法打开,如下图:
解决方案:
- a. Cache issue
rm -rf var/cache/ var/generation/ var/page_cache/ var/view_preprocessed/
rm -rf pub/static/frontend/ pub/static/adminhtml/ pub/static/_requirejs/
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
- b. Permission Issue
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find ./var -type d -exec chmod 777 {} \;
find ./pub/media -type d -exec chmod 777 {} \;
find ./pub/static -type d -exec chmod 777 {} \;
chmod 777 ./app/etc
chmod 644 ./app/etc/*.xml
7.报文件不存在
解决方案:
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:Deploy -f
chmod -R 777 var/ generated/
8.有时候忘记自己的管理员url,解决:
php bin/magento info:adminuri
9.出现以下错误
解决方案:
授权先去log里面查看原因
[root@localhost ~]# cd /var/www/magento2/var/log
[root@localhost log]# ls
debug.log exception.log system.log
[root@localhost log]# cat exception.log
[2020-11-02 16:34:31] main.CRITICAL: Class Magento\Framework\App\Http\Interceptor does not exist {"exception":"[object] (ReflectionException(code: -1): Class Magento\\Framework\\App\\Http\\Interceptor does not exist at /var/www/magento2/lib/internal/Magento/Framework/Code/Reader/ClassReader.php:26)"} []
[2020-11-02 16:37:20] main.CRITICAL: The stream or file "/var/www/magento2//var/log/system.log" could not be opened: failed to open stream: Permission denied {"exception":"[object] (UnexpectedValueException(code: 0): The stream or file \"/var/www/magento2//var/log/system.log\" could not be opened: failed to open stream: Permission denied at /var/www/magento2/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:108)"} []
[2020-11-02 16:37:26] main.CRITICAL: The stream or file "/var/www/magento2//var/log/system.log" could not be opened: failed to open stream: Permission denied {"exception":"[object] (UnexpectedValueException(code: 0): The stream or file \"/var/www/magento2//var/log/system.log\" could not be opened: failed to open stream: Permission denied at /var/www/magento2/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:108)"} []
[2020-11-02 17:43:04] main.CRITICAL: Class Magento\User\Model\User\Interceptor does not exist {"report_id":"85e90c9250a1ac92812a17a4c3211572f8a50bdace4dac9392b9fd117747dccb","exception":"[object] (ReflectionException(code: -1): Class Magento\\User\\Model\\User\\Interceptor does not exist at /var/www/magento2/lib/internal/Magento/Framework/Code/Reader/ClassReader.php:26)"} []
可以看到该错误就是问题7,所以解决方案可以参考问题7.
10.如果打开域名或者ip是空白页,也没提示任何错误,一般是权限的问题,解决:
chmod 700 /var/www/magento2/app/etc
chown -R nginx:nginx /var/www/magento2
11.如果magento打开很卡的话,优化如下:
参考解决:https://magento.stackexchange.com/questions/152221/why-magento-2-is-extremely-slow
a.查看是否设置为Developer
[root@localhost magento2]# php -f bin/magento deploy:mode:show
Current application mode: default. (Note: Environment variables may override this value.)
设置开发者模式
php -f bin/magento deploy:mode:set developer
b.检查Magento的缓存已启用
[root@localhost magento2]# php -f bin/magento cache:status
Current status:
config: 0
layout: 0
block_html: 0
collections: 0
reflection: 0
db_ddl: 0
compiled_config: 0
eav: 0
customer_notification: 0
config_integration: 0
config_integration_api: 0
full_page: 0
config_webservice: 0
translate: 0
如果未启用则是0,启用
[root@localhost magento2]# php -f bin/magento cache:enable
Changed cache status:
config: 0 -> 1
layout: 0 -> 1
block_html: 0 -> 1
collections: 0 -> 1
reflection: 0 -> 1
db_ddl: 0 -> 1
compiled_config: 0 -> 1
eav: 0 -> 1
customer_notification: 0 -> 1
config_integration: 0 -> 1
config_integration_api: 0 -> 1
full_page: 0 -> 1
config_webservice: 0 -> 1
translate: 0 -> 1
Cleaned cache types:
config
layout
block_html
collections
reflection
db_ddl
compiled_config
eav
customer_notification
config_integration
config_integration_api
full_page
config_webservice
translate
c.启用JS / CSS捆绑
Stores > Configuration > Advanced > Developer
请注意,以上菜单项仅在开发人员模式下显示
设置如下:
Template Setttings
Minify HTML = Yes
Javascript Settings
Merge JS files = Yes
Enable JS Bundling = Yes
Minify JS files = Yes
CSS Settings
Merge CSS = Yes
Minify CSS = Yes
在每一步刷新缓存后,从此处开始进行缓存刷新,这是您尝试缩短加载时间的基准。
php -f bin/magento cache:flush
d.启用redis
centos安装命令
sudo yum install epel-release
sudo yum update
sudo yum -y install redis
sudo systemctl start redis
了可以使Redis能被远程连接,需要修改配置文件,路径为/etc/redis.conf
vi /etc/redis.conf
注释:
#bind 127.0.0.1
打开/var/www/magento2/app/etc/env.php配置如下:
'cache' => [
'frontend' => [
'default' => [
'id_prefix' => 'a6b_',
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => '127.0.0.1',
'database' => '0',
'port' => '6379',]
],
'page_cache' => [
'id_prefix' => 'a6b_',
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => '127.0.0.1',
'port' => '6379',
'database' => '1',
'compress_data' => '0',
]
]
]
],
以下是ubuntu的安装命令:
sudo apt-get update
sudo apt-get install build-essential tcl8.5
sudo apt-get install make
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
cd utils/
sudo ./install_server.sh
Edit /www/project/app/etc/env.php
Ubunto配置如下:
'cache' =>
array (
'frontend' =>
array (
'default' =>
array (
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' =>
array (
'server' => '127.0.0.1',
'database' => '0',
'port' => '6379',
),
),
'page_cache' =>
array (
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' =>
array (
'server' => '127.0.0.1',
'port' => '6379',
'database' => '1',
'compress_data' => '0',
),
),
),
),
e.启用PHP-FPM
以下是ubuntu的安装命令:
apt-get install php7.1-fpm
a2enmod proxy_fcgi setenvif
a2enconf php7.1-fpm
sudo service php7.1-fpm restart
sudo service apache2 restart
Enable opcache in PHP
Edit /etc/php/7.1/apache2/php.ini find opcache.enable
opcache.enable=1
12.报错如下
Error filtering template: Invalid template file: 'owl_list.phtml' in module: 'Smartwave_Filterproducts' block's name: 'home\featuredlist_0'
解决方案:
出现这种问题多半是由于上传新的主题文件安装后未选定主题导致的问题,进入Content>Design>Configuration 选择主题即可!
13.错误如下图:
解决方案:
cd /var/www/magento2
find ./pub/static -type d -exec chmod 777 {} \;
Or
sudo chmod -R 777 ./pub/static/
14.错误如下图:
解决方案:
由于安装完修改了redis配置导致错误
redis-cli flushall
附加
如果不配置nginx,安装完直接开启项目也行:
cd /var/www/magento2
php -S 0.0.0.0:80 -t ./pub/ ./phpserver/router.php
如果觉得文章对您有帮助,欢迎点赞、收藏、评论讨论!