项目实战:ecshop
准备 LNMP 环境
准备 Nginx
bash
# 安装
[root@server ~ 22:17:36]# systemctl enable nginx.service --now
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@server ~ 22:18:44]# echo "nginx test page" > /usr/share/nginx/html/index.html
[root@server ~ 22:19:27]# vim /etc/hosts
#添加 www.server.cloud
#测试
[root@server ~ 22:19:58]# curl http://www.server.cloud/
nginx test page
准备 Mariadb
bash
[root@server ~ 22:22:26]# yum install -y mariadb-server
[root@server ~ 22:22:26]# systemctl enable mariadb.service --now
# 安全初始化
# 设置root密码为123
# 删除匿名用户
# 删除测试数据库
[root@server ~ 22:23:02]# mysql_secure_installation
准备 PHP
bash
[root@server ~ 22:25:29]# yum install -y php php-fpm
[root@server ~ 22:25:29]# systemctl enable php-fpm.service --now
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
# 配置虚拟主机
[root@server ~ 22:25:58]# vim /etc/nginx/conf.d/www.server.cloud.conf
server {
listen 80;
listen [::]:80;
server_name www.server.cloud;
root /usr/share/nginx/html;
index index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@server ~ 22:27:10]# systemctl restart nginx.service
# 准备测试页面
[root@server ~ 22:27:29]# echo "<?php echo 'PHP Test Page'.\"\n\"; ?>" > /usr/share/nginx/html/test.php
# 客户端测试
[root@client ~ 22:31:21]# curl http://www.server.cloud/test.php
PHP Test Page
准备数据库
bash
[root@server ~ 22:34:10]# mysql -u root -p
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> create database ecshop;
MariaDB [(none)]> create user ecshop@localhost identified by '123';
MariaDB [(none)]> grant all privileges on ecshop.* to ecshop@localhost;
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;
准备 ecshop 站点
准备 ecshop 站点数据文件,这里使用 ECShop_V4.1.20 版本。
bash
# 上传ECShop_V4.1.20_UTF8.zip
[root@server ~ 22:39:35]# rz
[root@server ~ 22:39:35]# ls
anaconda-ks.cfg ECShop_V4.1.20_UTF8.zip
#解压
[root@server ~ 22:40:22]# unzip ECShop_V4.1.20_UTF8.zip
[root@server ~ 22:40:22]# ls
anaconda-ks.cfg
ECShop_V4.1.20_UTF8_release20250416
ECShop_V4.1.20_UTF8.zip
#备份html然后复制
[root@server ~ 22:41:18]# mv /usr/share/nginx/html{,.ori}
[root@server ~ 22:41:44]# cp -a ECShop_V4.1.20_UTF8_release20250416/source/ecshop /usr/share/nginx/html
#修改用户用户组
[root@server ~ 22:42:40]# chown nginx:nginx -R /usr/share/nginx/html
# 安装站点需要的各种扩展包
[root@server ~ 22:42:45]#yum install -y php-gd php-common php-pear php-mbstring php-mcrypt php-mysqlnd
# 修改 php-fpm运行用户身份
[root@server ~ 22:42:58]# vim /etc/php-fpm.d/www.conf
# 更改以下两条记录
# user = apache
user = nginx
# group = apache
group = nginx
[root@server ~ 22:46:46]# chown nginx:nginx -R /var/lib/php/
[root@server ~ 22:47:14]# systemctl restart nginx.service php-fpm.service
配置过程