欢迎光临
让更多人用上统信UOS系统

如何在 Ubuntu 22.04 LTS 上安装 Magento

Magento 是一个非常流行的开源电子商务平台,用 PHP 编写并由 Adob​​e Inc. 管理。该平台非常灵活,并且具有构建在线商店的多种功能。Magento 提供社区和其平台的商业版本,社区版本是免费的,主要为个人和/或小型企业设计。另一方面,企业版主要针对大中型企业,更多的是企业环境。magento-logo

在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 Magento

apt步骤 1. 首先,通过在终端中运行以下命令,确保所有系统包都是最新的。

sudo apt update
sudo apt upgrade

步骤 2. 在 Ubuntu 22.04 上安装 LAMP 堆栈。

在开始本教程之前,必须在您的服务器上安装 LAMP 服务器。如果您没有安装 LAMP Stack,您可以在此处按照我们的指南进行操作。

步骤 3. 在 Ubuntu 22.04 上安装 Elasticsearch。

默认情况下,Elasticsearch 在 Ubuntu 22.04 基础存储库中不可用。现在运行以下命令将 Elasticsearch 存储库添加到您的 Ubuntu 系统:

echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

接下来,导入 GPG 密钥:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

启用存储库后,现在使用以下命令安装最新版本的 Elasticsearch :

sudo apt update
sudo apt install elasticsearch

Elasticsearch 服务在安装后不会自动启动,要启动该服务并在系统启动时启用它,请键入以下systemctl命令:

sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch
sudo systemctl status elasticsearch

要验证 Elasticsearch 是否正确运行,您将使用以下curl命令:

curl -X GET "localhost:9200/"

输出:

{
  "name" : "1krDCO-",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "mzgLCfLJeliZUbpC_6R0wQ",
  "version" : {
    "number" : "6.8.24",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "4f66956",
    "build_date" : "2022-06-06T21:23:50.08771JZ",
    "build_snapshot" : false,
    "lucene_version" : "7.7.4",
    "minimum_wire_compatibility_version" : "5.6.1",
    "minimum_index_compatibility_version" : "5.0.1"
  },
  "tagline" : "You Know, for Search"
}

步骤 4. 在 Ubuntu 22.04 上安装 Composer。

默认情况下,Composer 在 Ubuntu 22.04 基础存储库中不可用。现在运行以下命令以使用wget命令下载 Composer 安装程序:

wget -O composer-setup.php https://getcomposer.org/installer

下载 Composer 后,在命令行执行以下命令,在 Linux Ubuntu 系统上安装和设置 Composer:

php composer-setup.php --install-dir=/usr/local/bin --filename=composer

确认安装并检查 Composer 的已安装构建版本:

composer -V

步骤 5. 在 Ubuntu 22.04 上安装 Magento。

在本教程中,我们将使用 Composer 安装 Magento 2.4.4。要继续此操作,您需要创建访问密钥。您可以在 magento.com 网站上创建一个帐户并导航至创建访问密钥。https://marketplace.magento.com/customer/accessKeys/

创建访问密钥后,您可以在 SSH 会话中运行此命令:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.4 /var/www/magento2

系统将要求您输入用户名和密码。这是您需要填写的信息:

Username: YOUR_PUBLIC_KEY
Password: YOUR_PRIVATE_KEY

接下来,导航到 Magento 目录:

cd /var/www/magento2

我们将需要更改一些文件夹权限:

find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
sudo chown -R www-data:www-data /var/www/magento2
sudo chmod -R 755 /var/www/magento2

之后,使用下面的 composer 命令安装 Magento:

sudo bin/magento setup:install \
--base-url=http://your-domain.com \
--db-host=localhost \
--db-name=magento_db \
--db-user=magento_user \
--db-password=Password \
--admin-firstname=Admin \
--admin-lastname=User \
--admin-email=admin@your-domain.com \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1

您应该看到以下输出:

[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_1m31xl
Nothing to import.

步骤 6. 为 WordPress 配置 MariaDB。

默认情况下,MariaDB 未加固。mysql_secure_installation您可以使用脚本保护 MariaDB 。您应该仔细阅读下面的每个步骤,这些步骤将设置 root 密码、删除匿名用户、禁止远程 root 登录、删除测试数据库和访问安全 MariaDB:

mysql_secure_installation

像这样配置它:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

接下来,我们需要登录 MariaDB 控制台并为 Magento 创建一个数据库。运行以下命令:

mysql -u root -p

这将提示您输入密码,因此请输入您的 MariaDB 根密码并按 Enter。登录到数据库服务器后,您需要为 Magento 安装创建一个数据库:

MariaDB [(none)]> CREATE DATABASE magento_db;
MariaDB [(none)]> CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'your-strong-password';
MariaDB [(none)]> GRANT ALL ON magento_db.* TO 'magento_user'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

步骤 7. 配置 Apache 虚拟主机。

现在为 Magento 创建虚拟主机配置文件:

sudo nano /etc/apache2/sites-available/magento.conf

添加以下文件:

<VirtualHost *:80>

   ServerName domain.com
   ServerAlias www.domain.com
   ServerAdmin admin@domain.com
   DocumentRoot /var/www/magento2/pub

   ErrorLog ${APACHE_LOG_DIR}/www.domain.com_error.log
   CustomLog ${APACHE_LOG_DIR}/www.domain.com_access.log combined

   <Directory /var/www/magento2/>
      Options FollowSymlinks
      AllowOverride All
      Require all granted
   </Directory>

</VirtualHost>

保存并关闭文件,然后重新启动 Apache 网络服务器以进行更改:

sudo a2ensite magento.conf
sudo a2enmod ssl rewrite
sudo systemctl restart apache2

第 8 步:使用 Let’s Encrypt 保护 Magento。

首先,您需要安装 Certbot 以使用 Let’s Encrypt 获取 SSL 证书:

sudo apt install certbot python3-certbot-apache

接下来,按照以下步骤使用 Let’s Encrypt 获取您的 SSL 证书:

sudo certbot --apache

您将需要按照交互式提示安装证书。由于我有两个域,我将为这两个域安装 SSL 证书:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): admin@domain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Account registered.

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: domain.com
2: www.domain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1,2
Requesting a certificate for domain.com and www.domain.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/domain.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/domain.com/privkey.pem
This certificate expires on 2022-12-10.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for domain.com to /etc/apache2/sites-available/www.domain.com-le-ssl.conf
Successfully deployed certificate for www.domain.com to /etc/apache2/sites-available/www.domain.com-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://domain.com and https://www.domain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

步骤 9. 设置自动续订 SSL。

Let’s Encrypt 证书的有效期为 90 天,强烈建议在证书到期前更新证书。您可以通过运行以下命令来测试证书的自动续订:

sudo certbot renew --dry-run

输出:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/domain.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Account registered.
Simulating renewal of an existing certificate for domain.com and www.domain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded: 
  /etc/letsencrypt/live/domain.com/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

步骤 10. 配置防火墙。

现在,我们使用 Apache 设置了一个简单防火墙 (UFW),以允许对 HTTP 和 HTTPS 的默认 Web 端口进行公共访问:

sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'
sudo ufw enable

步骤 11. 访问 Magento Web 界面。

成功安装后,打开 Web 浏览器并使用 URL 访问 Magento Web 界面。您将被重定向到以下页面:https://domain.com

magento-web-UI-site

感谢您使用本教程在 Ubuntu 22.04 LTS Jammy Jellyfish 系统上安装带有 LAMP 的 Magento。如需更多帮助或有用信息,我们建议您查看Magento 网站

赞(0) 打赏
未经允许不得转载:统信UOS之家 » 如何在 Ubuntu 22.04 LTS 上安装 Magento

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏