[TOC]
需要注意的事项
composer self-update --1
curl
fileinfo
gd2
intl
mbstring
exif
openssl
pdo_mysql
soap
sockets
sodium
tidy
xsl
post_max_size = 128M
memory_limit = 2048M
upload_max_filesize = 64M
short_open_tag = On
max_execution_time = 900
max_input_time = 300
max_input_vars = 500
PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS
大概就是在环境变量里设置
set PHP_FCGI_MAX_REQUESTS=1000
set PHP_FCGI_CHILDREN=32
nginx -s quit
nginx -s reload
nginx -T
查看被占用端口对应的 PID
netstat -aon|findstr "8081"
查看指定 PID 的进程
tasklist|findstr "9088"
查看 IMAGENAME 为 nginx.exe 的进程
tasklist /V /FI "IMAGENAME eq nginx.exe"
结束进程 强制(/F参数)杀死 pid 为 9088 的所有进程包括子进程(/T参数)
taskkill /T /F /PID 9088
结束进程 强制(/F参数)杀死 IMAGENAME 为 nginx.exe 的所有进程包括子进程(/T参数)
taskkill /T /F /FI "IMAGENAME eq nginx.exe"
.
,命令最后的参数是安装目录, .
是安装到当前目录
composer create-project --repository=https://repo.magento.com/ magento/project-community-edition=2.3.7 .
vendor\magento\framework\Image\Adapter\Gd2.php
大概在 90 行左右的位置
private function validateURLScheme(string $filename) : bool
{
if(!file_exists($filename)) { // if file not exist
$allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
$url = parse_url($filename);
if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes)) {
return false;
}
}
return true;
}
vendor\magento\framework\View\Element\Template\File\Validator.php
大概在 140 行左右的位置
protected function isPathInDirectories($path, $directories)
{
if (!is_array($directories)) {
$directories = (array)$directories;
}
//$realPath = $this->fileDriver->getRealPath($path);
$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
foreach ($directories as $directory) {
if (0 === strpos($realPath, $directory)) {
return true;
}
}
return false;
}
php bin/magento setup:install `
--base-url=http://localhost-magento/ `
--db-host=localhost `
--db-name=magento2ce `
--db-user=root `
--db-password=1234 `
--admin-firstname=admin `
--admin-lastname=admin `
--admin-email=admin@admin.com `
--admin-user=admin `
--admin-password=admin123 `
--language=en_US `
--currency=USD `
--timezone=America/Chicago `
--use-rewrites=1
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento indexer:reindex
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
upstream fastcgi_backend {
server 127.0.0.1:9001;
}
server {
listen 80;
access_log logs/localhost-magento.access.log;
error_log logs/localhost-magento.error.log;
server_name localhost-magento;
set $MAGE_ROOT C:/code/magento-community; # 这里是 magento 的根目录
set $MAGE_DEBUG_SHOW_ARGS 1;
include C:/code/magento-community/nginx.conf.sample; # 这里是 magento 的根目录里的 nginx.conf.sample
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
php bin/magento deploy:mode:set developer
php bin/magento sampledata:deploy
php bin/magento setup:upgrade
需要注意的事项
var/log
,安装过程中遇到什么问题可以在这里找日志看app/etc/env.php
里查看 admin 的 url ,运行完安装命令后也会输出 admin 的 url
'backend' => [
'frontName' => 'admin_1a3uev'
],
admin >> STORE >> Configuration >> SALES >> Payment Methods
php -S 127.0.0.1:8082 -t ./pub/ ./phpserver/router.php
php bin/magento cache:clean
php bin/magento indexer:reindex
php bin/magento cache:flush
rm -rf var/di/* var/generation/* var/cache/* var/page_cache/* var/view_preprocessed/* var/composer_home/cache/*
rm -rf generated/code/* generated/metadata/*
rm -rf pub/static/*
'session' => [
'save' => 'redis',
'redis' => [
'host' => '127.0.0.1',
'port' => '6379',
'password' => '',
'timeout' => '2.5',
'persistent_identifier' => '',
'database' => '2',
'compression_threshold' => '2048',
'compression_library' => 'gzip',
'log_level' => '4',
'max_concurrency' => '6',
'break_after_frontend' => '5',
'break_after_adminhtml' => '30',
'first_lifetime' => '600',
'bot_first_lifetime' => '60',
'bot_lifetime' => '7200',
'disable_locking' => '0',
'min_lifetime' => '60',
'max_lifetime' => '2592000'
]
],
'cache' => [
'frontend' => [
'default' => [
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => '127.0.0.1',
'database' => '0',
'port' => '6379'
],
],
'page_cache' => [
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => '127.0.0.1',
'port' => '6379',
'database' => '1',
'compress_data' => '0'
]
]
]
],
opcache.enable_cli=1
composer dumpautoload -o
后速度也有提升
php bin/magento setup:di:compile
后面php bin/magento setup:static-content:deploy -f
前面除了可以通过 compoer 安装外,还可以通过 github 的仓库安装。
clone 整个仓库后再切换分支
git clone https://github.com/magento/magento2.git .
git pull
git switch 2.4.2-p1
只 clone 一个分支
git clone -b 2.4.2-p1 https://github.com/magento/magento2.git .
vendor/magento/framework
。lib/internal/Magento/Framework
。笔者发现 magento2 的每个小版本的系统依赖都有一点不一样 https://devdocs.magento.com/guides/v2.4/install-gde/system-requirements.html
2.3 和 2.4 的主要区别是
因为 Elasticsearch 的存在使得门槛高了不少。笔者感觉奥多比正在抛弃中小用户。
安装流程和注意事项和 2.3 的基本一致。
2.4.0 依赖的 elasticsearch 版本为 7.6 。
直接从官网下载就可以了,下载后解压,然后运行 bin/elasticsearch.bat 。压缩包里原本就带着 jdk 。
magento2 的官网推荐使用 nginx 做 es 的反向代理,这样就可以给 es 加上 http 认证。
composer create-project --repository=https://repo.magento.com/ magento/project-community-edition=2.4.0 .
vendor\magento\framework\App\StaticResource.php
大概在 278 行左右的位置
private function isThemeAllowed(string $theme): bool
{
$theme = str_replace('\\', '/', $theme); //fix windows path
return in_array($theme, array_keys($this->themePackageList->getThemes()));
}
php bin/magento setup:install `
--base-url=http://localhost-magento/ `
--db-host=localhost `
--db-name=magento2ce2 `
--db-user=root `
--db-password=1234 `
--admin-firstname=admin `
--admin-lastname=admin `
--admin-email=admin@admin.com `
--admin-user=admin `
--admin-password=admin123 `
--language=en_US `
--currency=USD `
--timezone=America/Chicago `
--use-rewrites=1 `
--search-engine=elasticsearch7 `
--elasticsearch-host=localhost `
--elasticsearch-port=9200 `
--elasticsearch-index-prefix=magento2
php bin/magento module:disable Magento_TwoFactorAuth
php bin/magento cache:flush
用户指南 https://docs.magento.com/user-guide/
开发文档 https://devdocs.magento.com/
github https://github.com/magento/magento2
magento 相关的博客