如何在 Ubuntu 22.04 上安装带有 Let’s Encrypt SSL 的 PrestaShop如何在 Ubuntu 22.04 上安装带有 Let’s Encrypt SSL 的 PrestaShop如何在 Ubuntu 22.04 上安装带有 Let’s Encrypt SSL 的 PrestaShop如何在 Ubuntu 22.04 上安装带有 Let’s Encrypt SSL 的 PrestaShop
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Ubuntu 22.04 上安装带有 Let’s Encrypt SSL 的 PrestaShop

PrestaShop 是一个开源电子商务平台,可让您在互联网上运营自己的在线商店或商店。它非常知名,在全球拥有超过 300000 家在线商店。它是用 PHP 编写的,并使用 MySQL/MariaDB 作为其数据库后端。通过 Prestashop,您可以提供您的想法和产品,并在互联网上销售它们。它提供了大量的主题、模块和扩展,您可以使用它们来扩展商店的功能。

在本文中,我们将向您展示如何在 Ubuntu 22.04 上安装 PrestaShop。

要求

  • 运行 Ubuntu 22.04 的服务器。
  • 服务器上设置了 root 密码。

安装 Apache、MariaDB 和 PHP

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

apt install apache2 mariadb-server -y

默认情况下,Ubuntu 22.04 附带 PHP 8.1 版本,但 PrestaShop 不支持 PHP 8.1 版本。因此,您需要在服务器上安装带有其他扩展的 PHP 7.4 版本。

首先,使用以下命令安装所有必需的依赖项:

apt install software-properties-common ca-certificates lsb-release apt-transport-https

接下来,使用以下命令添加 PHP 存储库:

add-apt-repository ppa:ondrej/php

添加 PHP 存储库后,运行以下命令来安装 PHP 7.4 以及所有必需的扩展:

apt install php7.4 libapache2-mod-php7.4 php7.4-zip php7.4-xml php7.4-gd php7.4-curl php7.4-intl php7.4-xmlrpc php7.4-mbstring php7.4-imagick php7.4-mysql unzip -y

安装 PHP 和其他必需的依赖项后,编辑 PHP 默认配置文件:

nano /etc/php/7.4/apache2/php.ini

更改以下行:

memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
date.timezone = UTC

保存并关闭文件并重新启动 Apache 服务以应用更改:

systemctl restart apache2

为 PrestaShop 创建数据库

接下来,您需要为 PrestaShop 创建数据库和用户。首先,使用以下命令登录 MariaDB shell:

mysql

登录后,使用以下命令创建数据库和用户:

MariaDB [(none)]> CREATE DATABASE prestashop;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON prestashop.* TO 'prestashop'@'localhost' IDENTIFIED BY 'password';

接下来,使用以下命令清除权限并退出 MariaDB shell:

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

安装 PrestaShop

首先,转到 PrestaShop Git Hub 页面并使用以下命令下载最新版本的 PrestaShop:

wget https://github.com/PrestaShop/PrestaShop/releases/download/1.7.8.7/prestashop_1.7.8.7.zip

下载完成后,将下载的文件解压到PrestaShop目录:

unzip prestashop_1.7.8.7.zip -d /var/www/html/prestashop

接下来,更改 PrestaShop 目录的所有权和权限:

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

为 PrestaShop 创建 Apache 虚拟主机。

接下来,您需要为 PrestaShop 创建 Apache 虚拟主机的配置文件。您可以使用以下命令创建它:

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

添加以下配置:

<VirtualHost *:80>
   ServerAdmin [email 
   DocumentRoot /var/www/html/prestashop
   ServerName prestashop.example.com

   <Directory /var/www/html/prestashop>
        Options FollowSymlinks
        AllowOverride All
        Require all granted 
   </Directory>
ErrorLog ${APACHE_LOG_DIR}/prestashop_error.log
CustomLog ${APACHE_LOG_DIR}/prestashop_access.log combined
</VirtualHost>

完成后保存并关闭文件。然后使用以下命令激活 PrestaShop 并启用 Apache 标头模块:

a2ensite prestashop
a2enmod rewrite headers

然后重新启动 Apache 服务以应用更改:

systemctl restart apache2

接下来,使用以下命令检查 Apache 服务的状态:

systemctl status apache2

您将得到以下输出:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-08-15 04:14:12 UTC; 5s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 35363 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 35367 (apache2)
      Tasks: 6 (limit: 2242)
     Memory: 21.5M
        CPU: 108ms
     CGroup: /system.slice/apache2.service
             ??35367 /usr/sbin/apache2 -k start
             ??35368 /usr/sbin/apache2 -k start
             ??35369 /usr/sbin/apache2 -k start
             ??35370 /usr/sbin/apache2 -k start
             ??35371 /usr/sbin/apache2 -k start
             ??35372 /usr/sbin/apache2 -k start

Aug 15 04:14:12 ubuntu2204 systemd[1]: Starting The Apache HTTP Server...

执行 PrestaShop Web 安装

现在 PrestaShop 已安装并使用 Apache 配置。现在打开您的网络浏览器并使用 URL http://prestashop.example.com 访问 PrestaShop 网络安装。 您应该看到语言选择屏幕:

选择您的语言,然后单击下一步按钮。您应该看到许可协议屏幕:

接受许可协议并单击“下一步”按钮。您应该看到站点信息屏幕:

输入您的站点信息、用户名和密码,然后单击下一步按钮。您应该看到数据库配置屏幕:

输入您的数据库信息,然后单击下一步按钮。安装完成后,您应该看到以下屏幕:

现在使用以下命令删除安装文件夹:

rm -rf /var/www/html/prestashop/install/

接下来,点击管理您的商店按钮。您应该看到 PrestaShop 后端的登录屏幕:

输入您的电子邮件地址和密码,然后单击登录按钮。您应该看到 PrestaShop 仪表板:

使用 Let's Encrypt 保护 PrestaShop。

接下来,您需要安装 Certbot 客户端包来安装和管理 Let's Encrypt SSL。

首先,使用以下命令安装 Certbot:

apt-get install certbot python3-certbot-nginx -y

安装完成后,运行以下命令在您的网站上安装 Let's Encrypt SSL:

certbot --nginx -d prestashop.example.com

系统将提示您提供有效的电子邮件地址并接受服务条款(见下文):

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 prestashop.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/prestashop.conf

接下来,选择是否将 HTTP 流量重定向到 HTTPS(见下文):

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 all traffic on port 80 to ssl in /etc/nginx/conf.d/prestashop.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://prestashop.example.com

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/prestashop.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/prestashop.example.com/privkey.pem
   Your cert will expire on 2022-11-16. 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

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

结论

恭喜!您已成功安装带有 Apache 和 Let's Encrypt SSL 的 PrestaShop。现在您可以在互联网上托管您自己的在线商店并开始销售您的产品。如果您有任何疑问,请随时与我联系。

©2015-2025 艾丽卡 support@alaica.com