如何使用 Apache 安装 Prestashop 并在 Debian 11 上加密 SSL
本教程适用于这些操作系统版本
- Debian 11(Bullseye)
- Debian 9(Stretch)
在此页
- 先决条件
- 安装 Apache、MariaDB 和 PHP
- 为 PrestaShop 创建数据库
- 下载 PrestaShop
- 为 PrestaShop 配置 Apache
- 访问 PrestaShop 网络用户界面
- 使用 Lets Encrypt SSL 保护 PrestaShop
- 结论
PrestaShop 是一种免费、开源、高效且创新的电子商务解决方案,可帮助您在线销售产品。它是一个功能强大且适应性强的电子商务 CMS,可提供创建在线商店所需的所有功能。使用 PrestaShop,您可以管理库存、产品目录、运输、发票等。它提供 5000 多个模块、主题,并支持许多不同的支付网关系统,如 PayPal、Google Checkout 等。
在这篇文章中,我们将向您展示如何在 Debian 11 上使用 Apache Web 服务器和 Lets Encrypt SSL 安装 PrestaShop。
先决条件
- 运行 Debian 11 的服务器。
- 一个有效的域名指向您的服务器 IP。
- 在服务器上配置了根密码。
安装 Apache、MariaDB 和 PHP
首先,您需要在服务器上安装 Apache、MariaDB、PHP 和其他 PHP 扩展。您可以使用以下命令安装所有这些:
apt-get install apache2 mariadb-server libapache2-mod-php php php-gd php-mbstring php-mysql php-curl php-xml php-cli php-intl php-zip unzip -y
安装所有软件包后,编辑 php.ini 文件并调整一些设置:
nano /etc/php/7.4/apache2/php.ini
更改以下行:
memory_limit = 256M
post_max_size = 64M
upload_max_filesize = 32M
date.timezone = UTC
保存并关闭文件,然后重新启动 Apache 服务以应用更改:
systemctl restart apache2
为 PrestaShop 创建数据库
首先,您需要保护 MariaDB 安装并设置 MariaDB root 密码。您可以通过运行 mysql_secure_installation 脚本来完成:
mysql_secure_installation
如下图所示回答所有问题:
Enter current password for root (enter for none):
Switch to unix_socket authentication [Y/n] Y
Change the 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 shell:
mysql -u root -p
提供您的 MariaDB root 密码,然后使用以下命令为 PrestaShop 创建用户和数据库:
MariaDB [(none)]> CREATE DATABASE prestadb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON prestadb.* TO 'prestauser'@'localhost' IDENTIFIED BY 'yourpass';
接下来,使用以下命令刷新权限并退出 MariaDB:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
下载 PrestaShop
接下来,转到 PrestaShop 网站并使用以下命令下载最新版本的 PrestaShop:
wget https://download.prestashop.com/download/releases/prestashop_1.7.7.7.zip
下载完成后,使用以下命令解压缩下载的文件:
unzip prestashop_1.7.7.7.zip
接下来,使用以下命令将 PrestaShop 再次解压缩到 Apache Web 根目录中:
unzip prestashop.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
ServerName presta.example.com
DocumentRoot /var/www/html/prestashop
<Directory /var/www/html/prestashop>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/your-domain.com_error.log
CustomLog ${APACHE_LOG_DIR}/your-domain.com_access.log combined
</VirtualHost>
保存并关闭文件,然后启用 Apache 重写模块并使用以下命令激活 Apache 虚拟主机:
a2enmod rewrite
a2ensite prestashop
最后,重新启动 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 Fri 2021-08-27 06:15:23 UTC; 5min ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 17540 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
Main PID: 14330 (apache2)
Tasks: 6 (limit: 2341)
Memory: 16.5M
CPU: 332ms
CGroup: /system.slice/apache2.service
??14330 /usr/sbin/apache2 -k start
??17544 /usr/sbin/apache2 -k start
??17545 /usr/sbin/apache2 -k start
??17546 /usr/sbin/apache2 -k start
??17547 /usr/sbin/apache2 -k start
??17548 /usr/sbin/apache2 -k start
Aug 27 06:15:23 debian11 systemd[1]: Starting The Apache HTTP Server...
访问 PrestaShop 网页用户界面
至此,PrestaShop 已安装并配置完毕。您现在可以使用 URL http://presta.example.com 访问它。您应该会看到以下页面:

选择您的语言,然后单击“下一步”按钮。您应该会看到以下页面:

接受条款和条件,然后单击“下一步”按钮。您应该会看到以下页面:

提供您的商店名称、管理员帐户详细信息,然后单击“下一步”按钮。您应该会看到以下页面:

提供您的数据库设置,然后单击“下一步”按钮开始安装。安装完成后,您应该会看到以下页面:

单击“管理您的商店”按钮。您应该会看到以下页面:

接下来,打开您的终端并删除安装文件夹:
rm -rf /var/www/html/prestashop/install
现在,使用上一屏幕中显示的 URL 访问 PrestaShop 管理界面。您应该会看到 PrestaShop 登录屏幕:

提供您的管理员用户名和密码,然后单击“登录”按钮。您应该会在以下页面上看到 PrestaShop 仪表板:

使用 Lets Encrypt SSL 保护 PrestaShop
首先,您需要安装 Certbot Lets Encrypt 客户端来为您的域下载和安装 SSL 证书。
您可以使用以下命令安装它:
apt-get install python3-certbot-apache -y
安装后,您可以运行以下命令为您的域 prestashop.example.com 安装 Lets Encrypt 证书。
certbot --apache -d presta.example.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):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/prestashop-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/prestashop-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/prestashop-le-ssl.conf
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 键为您的域下载并安装免费的 SSL 证书。安装成功完成后。您应该得到以下输出:
Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/prestashop.conf to ssl vhost in /etc/apache2/sites-available/
prestashop-le-ssl.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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
结论
在上面的指南中,我们解释了如何在 Debian 11 上使用 Apache 和 Lets Encrypt SSL 证书安装 PrestaShop。您现在可以使用 PrestaShop 轻松托管您的在线商店。如果您有任何问题,请随时问我。