ECStore B2C V5.0.1 是商派于2018年7月份宣布开源时推出的最后一个开源社区版(后面还有个5.0.2 商业版),目前该系列产品都已下架,现阶段正在主推 ECshopX 系列。
注:本文所有操作都在 root 账户下进行,所有操作也同样适应 AnolisOS 8.x。php5.6.40 使用 el8 rpm 安装。
一、初始化 dnf 源
1、下载并配置 epel(RHEL 8),参考:https://developer.aliyun.com/mirror/epel
2、创建并配置 remi.repo
cat > /etc/yum.repos.d/remi.repo <<EOF
> # This repository only provides packages for the PHP stack
>
> [remi]
> name=Remi's RPM repository for Enterprise Linux 8 - $basearch
> baseurl=https://mirrors.aliyun.com/remi/enterprise/8/remi/$basearch/
> enabled=1
> gpgcheck=1
> gpgkey=https://rpms.remirepo.net/RPM-GPG-KEY-remi2018
EOF
二、安装配置 php 环境
1、安装 php5.6.40 及必要扩展,完成后输入 php56 -m 确认所有已安装的扩展
dnf -y install php56-php t1lib php56-php-bcmath php56-php-gd php56-php-mbstring php56-php-mcrypt php56-php-xml php56-php-process php56-php-pdo php56-php-mysqlnd php56-php-pecl-redis4 php56-php-pecl-memcached
2、创建 www 组、www 用户
groupadd www
useradd -c "HTTPD User" -g www www -s /sbin/nologin
3、创建 /srv/httpd 目录,同时将 ECStore-xxx.tar 源码包解压到该目录。然后再将该目录所属用户和组都设置成 www
mkdir /srv/httpd
tar xvf /路径/ECStore-Community-php5.6-5.0.1.tar -C /srv/httpd
chown -R www:www /srv/httpd
4、给以下目录设置必要的写入权限
cd /srv/httpd/ecstore
chmod ug+w config data public public/images public/files themes
5、安装 Swoole Loader扩展(必要扩展)
(1) 查看当前所装 php 的默认扩展目录
php56 -i | grep extension_dir
结果:extension_dir => /opt/remi/php56/root/usr/lib64/php/modules
(2) 将 ECStrore 源码包中的 swoole_loader56.so 扩展文件复制到 php 的默认扩展目录
cp /srv/httpd/ecstore/deploy/swoole_loader56.so /opt/remi/php56/root/usr/lib64/php/modules
(3) 在 /etc/opt/remi/php56/php.d 下新建文件 60-swoole_loader.ini,使用 cat 创建如下:
cat > 60-swoole_loader.ini <<EOF
> ; 注意这里的 .so 如果不是在 php 的默认扩展目录中,需要使用全局文件路径。
> extension = swoole_loader56.so
EOF
6、打开 /etc/opt/remi/php56/php.ini
(1) 定位到 cgi.fix_pathinfo,确认其已被注释(默认值是1)或者去掉注释后将其值设为1
(2) 定位到 date.timezone,去掉注释并设置 date.timezone = "Asia/Shanghai"。保存并退出
7、打开 /etc/opt/remi/php56/php-fpm.d/www.conf
(1) 确保 php-fpm 模块使用 www 用户和 www 用户组的身份运行
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = www
; RPM: Keep a group allowed to write in log dir.
group = www
(2) 紧接上面用户设置的下面一段,确认接收 FastCGI 请求的监听方式,本例为 Unix Socket。后面在配置 Nginx fastcgi_pass 时,也要设成 Unix Socket。保存并退出。
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all IPv4 addresses on a
; specific port;
; '[::]:port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/opt/remi/php56/run/php-fpm/www.sock
重要:必须将 www.sock 的所有者和所属组都分配给 www
chown www:www /var/opt/remi/php56/run/php-fpm/www.sock
8、禁用 httpd.service、httpd.socket 开机自启动(防止 httpd 占用 80 端口导致 Nginx 不能启动)
systemctl disable httpd.service
systemctl disable httpd.socket
systemctl stop httpd.service
systemctl stop httpd.socket
9、重启 php56-php-fpm.service
systemctl restart php56-php-fpm.service
10、配置定时任务,输入 crontab -uwww -e 回车,输入以下内容后保存并退出
* * * * * /srv/httpd/ecstore/script/queue/queue.sh /usr/bin/php56 >/dev/null
* * * * * /usr/bin/php56 /srv/httpd/ecstore/script/crontab/crontab.php >/dev/null
三、安装配置 Nginx 环境
1、安装Nginx
dnf -y nginx
2、打开 /etc/nginx/fastcgi_params 注释掉 SCRIPT_NAME 所在行
# fastcgi_param SCRIPT_NAME $fastcgi_script_name;
3、打开 /etc/nginx/nginx.conf 配置 Unix Socket 及 PATH_INFO,配置中的 user 必须要添加一个 www
user nginx www;
...... 省略 ......
http {
...... 省略 ......
server {
listen 80;
listen [::]:80;
server_name boge.com;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /srv/httpd/ecstore;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
index index.php index.html index.htm;
}
location ~ ^/shopadmin {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
location ~ \.php {
root /srv/httpd/ecstore;
fastcgi_pass unix:/var/opt/remi/php56/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi_params;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "(.+?.php)(/.+)") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
}
}
4、重启 Nginx
nginx -s stop
nginx
后面 MySQL、Redis、Memcached 的安装配置就不再赘述了。