如何使用nginx在ubuntu 18.04 lts上安装prestashop
在本教程中,将介绍如何使用nginx作为Web服务器在Ubuntu 18.04 LT上安装Prestashop。
PrestAshop是一个完全可扩展的开源电子商务解决方案,可通过为商家和客户提供最佳的购物车体验,在线销售产品。
prestashop是用PHP编写的,以高度可定制,并支持所有主要的付款服务。
它配备了很多模板,我们可以轻松选择适合我们品牌的正确店面。
以下是使用nginx在Ubuntu 18.04 LTS上安装Prestashop的标准步骤。
第1步:安装nginx和php
prestashop需要PHP和Web服务器。
我们的Web服务器选择是nginx,但也可以使用Apache。
sudo apt update sudo apt -y install nginx php-cli php-intl php-fpm php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
nginx和php-fpm服务都应该运行:
$systemctl status nginx php7.2-fpm.service
* nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2016-11-04 12:13:11 PST; 21s ago
Docs: man:nginx(8)
Process: 23848 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 23837 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 23852 (nginx)
Tasks: 3 (limit: 1111)
CGroup: /system.slice/nginx.service
|-23852 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
|-23853 nginx: worker process
`-23854 nginx: worker process
Nov 04 12:13:11 ubuntu-01 systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 04 12:13:11 ubuntu-01 systemd[1]: Started A high performance web server and a reverse proxy server.
* php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2016-11-04 05:57:11 PST; 6h ago
Docs: man:php-fpm7.2(8)
Main PID: 17354 (php-fpm7.2)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
Tasks: 3 (limit: 1111)
CGroup: /system.slice/php7.2-fpm.service
|-17354 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
|-17369 php-fpm: pool www
`-17370 php-fpm: pool www
Nov 04 05:57:11 ubuntu-01 systemd[1]: Starting The PHP 7.2 FastCGI Process Manager...
Nov 04 05:57:11 ubuntu-01 systemd[1]: Started The PHP 7.2 FastCGI Process Manage
第2步:安装和配置MariaDB数据库服务器
prestashop需要一个数据库服务器来存储其数据。
MariaDB是一个强大的开源关系数据库系统。
我们可以在下面的教程下遵循Ubuntu 18.04服务器在Ubuntu 18.04服务器上安装MariaDB:
在Ubuntu 18.04和Centos 7上安装MariaDB 10.x
如果我们想使用MySQL,请检查:
如何在Ubuntu 18.04/16.04上安装MySQL 8.0
登录MariaDB shell:
$mysql -u root -p
为prestashop创建一个数据库和用户:
CREATE USER 'prestashop'@'localhost' IDENTIFIED BY 'StrongPassword'; CREATE DATABASE prestashop; GRANT ALL PRIVILEGES ON prestashop.* TO 'prestashop'@'localhost'; FLUSH PRIVILEGES; QUIT
检查我们是否可以登录数据库shell prestashop用户:
$mysql -u prestashop -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 42 Server version: 10.3.34-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04 Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | prestashop | +--------------------+ 2 rows in set (0.00 sec)
第3步:下载最新的prestashop
在下载之前,请检查最新发布的Prestashop。
获取版本后,将其导出为变量。
export VER="1.7.4.3"
下载最新版本:
wget https://download.prestashop.com/download/releases/prestashop_${VER}.zip
解压缩存档文件。
mkdir prestashop
unzip prestashop_${VER}.zip -d prestashop
将prestashop移动到 /srv/prestashop
sudo mv prestashop /srv
设置适当的权限 /srv/prestashop
sudo chown -R www-data:www-data /srv/prestashop/ sudo chmod -R 755 /srv/prestashop/
第4步:配置nginx
如果我们在第一步中未安装Nginx,请确保它已安装和运行
sudo apt install nginx
然后为prestashop创建一个虚拟主机文件
sudo vim /etc/nginx/conf.d/prestashop.conf
将以下数据填充到文件
server {
listen 80;
server_name example.com;
root /srv/prestashop;
index index.php index.html;
location/{
rewrite ^/api/?(.*)$/webservice/dispatcher.php?url= last;
rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$/img/p//.jpg last;
rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$/img/p///.jpg last;
rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$/img/p////.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$/img/p/////.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$/img/p//////.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$/img/p///////.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$/img/p////////.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$/img/p/////////.jpg last;
rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$/img/c/.jpg last;
rewrite ^/c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg$/img/c/.jpg last;
rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$/img/c/.jpg last;
try_files $uri $uri//index.php?$args;
}
location ~ \.php${
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
gzip on;
gzip_comp_level 1;
gzip_buffers 16 8k;
gzip_types application/json text/css application/javascript;
}
在重新启动nginx之前,应确认文件语法可以正常。
# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
重新启动nginx服务,以获取要加载的新文件
sudo systemctl restart nginx
启动prestashop设置向导完成安装 http://example.com1.选择安装语言,然后单击"下一步"
2.同意软件条款和条件,然后单击"下一步"
3.确认prestashop兼容性验证是成功的单击下一步 4.选择商店名称,主要活动并创建帐户 5.使用前面创建的凭据配置数据库连接,然后单击"立即测试数据库连接!"。
等待安装完成与用户创建的用户登录 4.出于安全目的,我们必须删除"安装"文件夹。
sudo rm -rf /srv/prestashop/install/

