不断学习 · 持续进步 Skip to main content

ubuntu22部署magento2

配置apt更新源/etc/apt/source.list

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
apt update

安装apache2.4

apt install apache2 -y

配置apache2.4/etc/apache2/apache2.conf

<Directory /var/www/html>
        AllowOverride All
</Directory>
LoadModule rewrite_module modules/mod_rewrite.so

启用apache2 rewrite模块

a2enmod rewrite

启动apache2服务和开机自启

systemctl enable --now apache2

安装mariadb-server

apt install mariadb-server -y

启动mariadb-server服务和开机自启

systemctl enable mysql --now

安全配置

mysql_secure_installation

创建数据库

mysql -u root -p

mysql> create database magento2;
mysql> create user 'mgtuser_09_gpm'@'localhost' identified by 'Admin123456';
mysql> grant all privileges on magento2.* to 'mgtuser_09_gpm'@'localhost';
mysql> flush privileges;

安装php

apt install php8.1 php8.1-fpm php8.1-bcmath php8.1-common php8.1-gmp php8.1-mbstring php8.1-xmlrpc php8.1-soap php8.1-gd php8.1-xml php8.1-intl php8.1-mysql php8.1-cli php8.1-ldap php8.1-zip php8.1-curl php-imagick libapache2-mod-php8.1 -y

切换php版本

add-apt-repository ppa:ondrej/php
apt install php7.3 php7.3-fpm php7.3-bcmath php7.3-common php7.3-gmp php7.3-mbstring php7.3-xmlrpc php7.3-soap php7.3-gd php7.3-xml php7.3-intl php7.3-mysql php7.3-cli php7.3-ldap php7.3-zip php7.3-curl php-imagick libapache2-mod-php7.3 -y

a2disconf php8.1-fpm
a2enconf php7.3-fpm
update-alternatives --set php /usr/bin/php7.3

配置php/etc/php/8.1/apache2/php.ini

memory_limit = 1G

启动php

systemctl enable --now php8.1-fpm.service

启用php8.1-fpm配置

a2enconf php8.1-fpm
systemctl restart apache2

部署magento2网站

https://experienceleague.adobe.com/zh-hans/docs/commerce-operations/installation-guide/advanced

wget https://github.com/magento/magento2/archive/refs/tags/2.4.7-p3.tar.gz
tar xf 2.4.7-p3.tar.gz -C /var/www/html/
shopt -s dotglob nullglob && mv /var/www/html/magento2.4.7-p3/* /var/www/html/
cd /var/www/html/
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:www-data /var/www/
sudo -u www-data composer config repo.packagist composer https://mirrors.aliyun.com/composer/
sudo -u www-data composer install

安装elasticsearch7

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
apt update
apt install elasticsearch jq -y

配置elasticsearch7/etc/elasticsearch/jvm.options.d/memory.options

-Xms2g
-Xmx2g

启动elasticsearch服务和开机自启

systemctl enable --now elasticsearch

测试elasticsearch

curl http://localhost:9200/ | jq .

安装magento2

cd /var/www/html

bin/magento setup:install \
--base-url=http://139.9.105.57/ \
--db-host=localhost \
--db-name=magento2 \
--db-user=mgtuser_09_gpm \
--db-password=Admin123456 \
--admin-firstname=admin \
--admin-lastname=admin \
[email protected] \
--admin-user=admin \
--admin-password=Admin123456 \
--language=zh_Hans_CN \
--currency=CNY \
--timezone=Asia/Shanghai \
--use-rewrites=1 \
--search-engine elasticsearch7