在Apache 20.04上使用Apache2和Let’s Encrypt安装Magento电子商务平台

在Apache 20.04上使用Apache2和Let’s Encrypt安装Magento电子商务平台

Magento是一个免费的开放源代码电子商务Web应用程序,可让您在几分钟内创建功能齐全的电子商务商店。它用PHP编写,结合了强大的功能,灵活性和友好的用户界面。由于其简单和强大的管理面板,它是自托管在线商店最受欢迎的解决方案之一。它具有丰富的功能集,包括站点管理,SEO,目录管理,产品和目录浏览,订单管理,结帐,促销和转换工具等等。

在本教程中,我们将向您展示如何在Ubuntu 20.04上使用Apache和Let’s Encrypt SSL来安装Magento电子商务平台。

先决条件

  • 运行带有4 GB RAM的Ubuntu 20.04的服务器。
  • 服务器指向的有效域名。
  • 在您的服务器上配置了root密码。

安装LAMP服务器

Magento在用PHP编写的Web服务器上运行,并将MariaDB用作数据库。因此,您将需要在服务器中安装LAMP堆栈。

首先,使用以下命令安装Apache Web服务器和MariaDB服务器:

apt-get install apache2 mariadb-server mariadb-client -y

Magento的最新版本仅与PHP 7.1.3+和7.2.x兼容。因此,您将需要在服务器中安装具有所需扩展名的受支持的PHP版本。

默认情况下,Ubuntu 20.04附带PHP版本7.4。因此,您需要在系统中添加Ondrej PPA才能安装其他PHP版本。

您可以使用以下命令添加Ondrej PHP PPA:

apt-get install software-properties-common -y
add-apt-repository ppa:ondrej/php

接下来,使用以下命令更新存储库并使用其他必需的扩展名安装PHP:

apt-get install php7.2 libapache2-mod-php7.2 php7.2-bcmath php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-intl php7.2-mysql php7.2-cli php7.2-ldap php7.2-zip php7.2-curl wget curl unzip -y

完成后,您可以继续下一步。

配置MariaDB数据库

默认情况下,MariaDB不安全。因此,保护​​并设置MariaDB根密码是一个好主意。您可以使用以下命令进行操作:

mysql_secure_installation

回答所有问题,如下所示:

Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
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安全,请登录MariaDB shell:

mysql -u root -p

提供您的MariaDB root密码,然后为Magento创建数据库和用户:

MariaDB [(none)]> CREATE DATABASE magentodb;
MariaDB [(none)]> CREATE USER 'magento'@'localhost' IDENTIFIED BY 'password';

接下来,使用以下命令将所有特权授予Magento数据库:

MariaDB [(none)]> GRANT ALL ON magentodb.* TO 'magento'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

接下来,使用以下命令刷新特权并退出MariaDB shell:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

完成后,您可以继续下一步。

下载Magento

在撰写本教程时,Magento的最新版本是2.3.5。您可以从Magento官方下载页面下载它。

下载完成后,使用以下命令将下载的文件解压缩到Apache Web根目录:

mkdir /var/www/html/magento
tar -xvjf magento-ce* -C /var/www/html/magento/

接下来,对magento目录赋予适当的所有权和权限:

chown -R www-data:www-data /var/www/html/magento/
chmod -R 755 /var/www/html/magento/

完成后,您可以继续下一步。Advertisements.banner-1{text-align:center; padding-top:10pximportant; padding-bottom:10pximportant; padding-left:0pximportant; padding-right:0pximportant; width:100%important; box-sizing:border-boximportant; background -color:#eeeeeeimportant; border:1px实心#dfdfdf}

为Magento配置Apache

接下来,创建一个新的Apache虚拟主机配置文件以服务Magento网站。

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

添加以下行:


     ServerAdmin [email protected]
     DocumentRoot /var/www/html/magento/
     ServerName magento.linuxbuz.com
     
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

保存并关闭文件,然后使用以下命令启用Magento虚拟主机和Apache重写模块:

a2ensite magento.conf
a2enmod rewrite

最后,重新启动Apache服务以实现更改:

systemctl restart apache2

此时,Apache Web服务器已配置为提供Magento.Advertisements.large-leaderboard-2 {text-align:center; padding-top:10pximportant; padding-bottom:10pximportant; padding-left:0pximportant; padding-right:0pximportant; width:100%important; box-sizing:border-boximportant; background -color:#eeeeeeimportant; border:1px实心#dfdfdf}

让我们加密货币SSL保护Magento

使用“让我们加密货币免费的SSL”保护您的网站始终是一个好主意。首先,在服务器中安装Certbot客户端,以下载和配置网站的“让我们加密货币SSL”。

apt-get install certbot python3-certbot-apache -y

一旦安装了Certbot,请运行以下命令为您的网站下载并安装“让我们加密货币SSL”:

certbot --apache -d magento.linuxbuz.com

系统将要求您提供有效的电子邮件并接受服务条款,如下所示:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing 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: Y

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for magento.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/magento-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/magento-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/magento-le-ssl.conf

接下来,将要求您选择是否将HTTP流量重定向到HTTPS:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

键入2,然后按Enter键以完成安装。

Redirecting vhost in /etc/apache2/sites-enabled/magento.conf to ssl vhost in /etc/apache2/sites-available/magento-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://magento.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=magento.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/magento.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/magento.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-08-11. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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

访问Magento网站

此时,您的Magento网站已使用“让我们加密货币SSL”保护。

现在,打开Web浏览器,然后输入URL https://magento.linuxbuz.com。您将被重定向到基于Web的Magento安装向导:

Magento设置

单击同意并设置Magento按钮。您应该会看到Magento准备屏幕:

准备检查Advertisements.leader-1 {text-align:center; padding-top:10pximportant; padding-bottom:10pximportant; padding-left:0pximportant; padding-right:0pximportant; width:100%important; box-sizing:border-boximportant; background -color:#eeeeeeimportant; border:1px实心#dfdfdf}

单击开始准备检查按钮。准备就绪检查完成后,您将看到以下屏幕:

满足所有先决条件

单击下一步按钮。您应该看到数据库设置屏幕:

配置数据库

提供您的Magento数据库名称,数据库用户名,密码,然后单击下一步按钮。您应该看到Magento Web配置向导:

网络配置

提供您的Magento商店和管理员地址,启用HTTPS,然后单击下一步按钮。您应该看到商店自定义屏幕:

自定义商店设置

设置您的首选时区,货币,语言,然后单击下一步按钮。您应该看到管理员用户创建屏幕:

创建一个管理员用户

提供您的管理员用户名,电子邮件,密码,然后单击下一步按钮。您应该看到以下屏幕:

现在安装

单击立即安装按钮以开始安装。成功完成安装后,您将看到以下屏幕:

安装成功

单击Magento管理员地址。您应该会看到Magento管理页面:

Magento登录

提供您的Magento管理员用户名,密码,然后单击“登录”按钮。您应该在以下屏幕中看到Magento仪表板:

Magento资讯主页

您也可以使用URL https://magento.linuxbuz.com访问Magento商店。您应该看到以下屏幕:

Magento起始页

结论

恭喜你您已在Ubuntu 20.04上使用“让我们加密货币SSL”成功安装了Magento。您现在可以轻松地部署自己的在线商店。如有任何问题,随时问我。

资讯来源:由0x资讯编译自HOWTOFORGE,版权归作者所有,未经许可,不得转载
你可能还喜欢