本页内容
- 先决条件
- 安装 LAMP 服务器
- 为 PrestaShop 创建数据库
- 安装 PrestaShop
- 为 PrestaShop 配置 Apache
- 配置防火墙
- 访问 PrestaShop
- 使用 Let's Encrypt SSL 保护 PrestaShop
- 结论
PrestaShop 是一款用 PHP 编写的开源购物车,用于创建和管理您的在线业务。它提供了一个简单易用的界面,帮助您在最短时间内上线您的在线商店。它提供了许多功能,包括用户友好的界面、多种支付网关(PayPal、Google Checkout)、响应式移动设计、免费支持、多语言、分析、报表等。
在本文中,我们将向您展示如何在 CentOS 8 上使用 Apache 和免费的 Let's Encrypt SSL 证书安装 PrestaShop。
先决条件
- 一台运行 CentOS 8 的服务器。
- 一个指向您服务器 IP 的有效域名。
- 您的服务器上已配置 root 密码。
安装 LAMP 服务器
在开始之前,必须在您的服务器上安装 LAMP 服务器。如果尚未安装,您可以使用以下命令连同其他 PHP 扩展一起安装:
dnf install httpd mariadb-server php php-cli php-bcmath php-mysqli php-gd php-pdo php-xmlrpc php-intl php-posix php-json php-curl php-zip unzip -y
安装完所有必需的软件包后,编辑 php.ini 文件并更改一些默认设置:
nano /etc/php.ini
更改以下行:
max_input_vars = 3000 post_max_size = 64M upload_max_filesize = 64M max_execution_time = 600 memory_limit = 256M date.timezone = Asia/Kolkata
保存并关闭文件,然后启动 Apache 和 MariaDB 服务,并设置它们在系统重启时自动启动:
systemctl start httpd
systemctl start mariadb
systemctl enable httpd
systemctl enable mariadb
此时,LAMP 服务器已安装在您的服务器上。
为 PrestaShop 创建数据库
PrestaShop 使用 MySQL/MariaDB 数据库来存储其数据。因此您需要为 PrestaShop 创建一个数据库和用户。
首先,使用以下命令登录 MariaDB:
mysql
登录后,使用以下命令创建数据库和用户:
MariaDB [(none)]> CREATE DATABASE prestashopdb;
MariaDB [(none)]> CREATE USER 'prestashopuser'@'localhost' IDENTIFIED BY 'securepassword';
接下来,使用以下命令授予 prestashopdb 所有权限:
MariaDB [(none)]> GRANT ALL PRIVILEGES ON prestashopdb. * TO 'prestashopuser'@'localhost';
接下来,使用以下命令刷新权限并退出 MariaDB:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
完成后,您可以继续下一步。
安装 PrestaShop
接下来,您需要从其官方下载页面下载最新版本的 PrestaShop。您可以使用以下命令下载:
wget https://download.prestashop.com/download/releases/prestashop_1.7.7.3.zip
下载完成后,使用以下命令将下载的文件解压到 Apache Web 根目录:
unzip prestashop_1.7.7.3.zip -d /var/www/html/prestashop
接下来,使用以下命令为 prestashop 目录设置适当的所有权:
chown -R apache:apache /var/www/html/prestashop
完成后,您可以继续下一步。
为 PrestaShop 配置 Apache
接下来,您需要为 PrestaShop 创建一个 Apache 虚拟主机配置文件。您可以使用以下命令创建它:
nano /etc/httpd/conf.d/prestashop.conf
添加以下行:
<VirtualHost *:80>
ServerAdmin
[email protected]
ServerName prestashop.example.com
DocumentRoot /var/www/html/prestashop
<Directory /var/www/html/prestashop>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/prestashop-error_log
CustomLog /var/log/httpd/prestashop-access_log common
</VirtualHost>
完成后保存并关闭文件。接下来,重启 Apache 服务以应用更改:
systemctl restart httpd
接下来,使用以下命令验证 Apache 服务的状态:
systemctl status httpd
您应该看到以下输出:
? httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/httpd.service.d
??php-fpm.conf
Active: active (running) since Wed 2021-04-07 01:04:19 EDT; 2h 2min ago
Docs: man:httpd.service(8)
Main PID: 47841 (httpd)
Status: "Total requests: 313; Idle/Busy workers 100/0;Requests/sec: 0.0425; Bytes served/sec: 1.2KB/sec"
Tasks: 278 (limit: 12524)
Memory: 35.9M
CGroup: /system.slice/httpd.service
??47841 /usr/sbin/httpd -DFOREGROUND
??47843 /usr/sbin/httpd -DFOREGROUND
??47844 /usr/sbin/httpd -DFOREGROUND
??47845 /usr/sbin/httpd -DFOREGROUND
??47846 /usr/sbin/httpd -DFOREGROUND
??48061 /usr/sbin/httpd -DFOREGROUND
Apr 07 01:04:19 centos8 systemd[1]: Stopped The Apache HTTP Server.
Apr 07 01:04:19 centos8 systemd[1]: Starting The Apache HTTP Server...
完成后,您可以继续下一步。
配置防火墙
接下来,您需要通过防火墙允许 80 和 443 端口。您可以使用以下命令允许它们:
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
接下来,重新加载防火墙以应用更改:
firewall-cmd --reload
完成后,您可以继续下一步。
访问 PrestaShop
现在,打开 Web 浏览器并使用 URL http://prestashop.example.com 访问 PrestaShop 的 Web 界面。您将被重定向到以下页面:


选择您的语言并点击 Next 按钮。您应该看到以下页面:

同意许可协议并点击 Next 按钮。您应该看到以下页面:


提供您的商店名称、国家信息和账户信息,然后点击 Next 按钮。您应该看到以下页面:

提供您的数据库名称、数据库用户名、密码,然后点击 Next 按钮。安装完成后,您应该看到以下页面:

点击 Manage your store 按钮。您应该看到以下页面:

现在,使用以下命令删除安装文件夹:
rm -rf /var/www/html/prestashop/install
接下来,点击 PrestaShop 管理后台 URL。您应该看到以下页面:

提供您的管理员用户名、密码并点击 LOG IN 按钮。您将在以下页面看到 PrestaShop 仪表盘:

使用 Let's Encrypt SSL 保护 PrestaShop
接下来,您需要安装 Certbot 客户端,以便为 PrestaShop 安装 Let's Encrypt SSL。您可以使用以下命令安装:
dnf install letsencrypt python3-certbot-apache
接下来,使用以下命令为您的域名获取并安装 SSL 证书:
certbot --apache -d prestashop.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): [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. 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: Y Account registered. Requesting a certificate for prestashop.example.com Performing the following challenges: http-01 challenge for prestashop.example.com Waiting for verification. Cleaning up challenges Deploying Certificate to VirtualHost /etc/httpd/conf.d/prestashop.conf Redirecting all traffic on port 80 to ssl in /etc/httpd/conf.d/prestashop.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://prestashop.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Subscribe to the EFF mailing list (email: [email protected] ). 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 certificate will expire on 2021-06-09. 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" - 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
现在您可以使用 URL https://prestashop.example.com 安全地访问您的网站。如果您想按设备进行重定向,请查看此处。
结论
恭喜!您已在 CentOS 8 上成功使用 Apache 和 Let's Encrypt SSL 安装了 PrestaShop。现在您可以将产品添加到 PrestaShop 并开始在线销售。如有任何问题,欢迎随时提问。