這里使用網上開源的PHPSHE商城系統(該系統采用PHP+MYSQL設計的)
下載地址:
LAMP架構了解
LAMP分別表示Linux,Apche、MySQL、PHP/Perl/Python。
- Apache(httpd):提供web服務。接受用戶的連接請求(只支持靜態頁面解析,當客戶端請求的是靜態資源時,web服務(httpd程序)會直接將靜態資源返回給客戶端)
- PHP:負責PHP腳本程序解析及實現與MySQL數據庫的交互。當客戶端請求的是動態資源時,Apache(httpd程序)會調用libphpN.so模塊進行解析。如果解析處理需用到后台數據庫,此時php會連接數據庫,最終php程序將解析后的結果返回給Apache。Apache返回給客戶端。
- MySQL:是一個關系型數據庫管理系統,由瑞典MySQL AB公司開發,目前屬於oracle旗下產品。主要用於永久的存儲數據。
一鍵部署LAMP環境
1、環境准備
- 關閉防火牆和selinux
# 關閉防火牆 [root@rhel8 ~]# systemctl stop firewalld [root@rhel8 ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1) # 設置selinux為disabled或permissive [root@rhel8 ~]# vi /etc/selinux/config SELINUX=disabled [root@rhel8 ~]# getenforce Disabled
配置本地軟件倉庫
[root@rhel8 ~]# mount -o ro /dev/sr0 /media/
[root@rhel8 ~]# df -h /media/
文件系統 容量 已用 可用 已用% 掛載點 /dev/sr0 7.4G 7.4G 0 100% /media [root@rhel8 ~]# vi /etc/yum.repos.d/local.repo
[BaseOS] name=BaseOS enabled=1 baseurl=file:///media/BaseOS/ gpgcheck=0 [AppStream] name=AppStream enable=1 baseurl=file:///media/AppStream/ gpgcheck=0
# 寫入開機自啟動配置文件中
[root@rhel8 ~]# echo "mount -o ro /dev/sr0 /mnt" >> /etc/rc.local
[root@rhel8 ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 8月 30 2019 /etc/rc.local -> rc.d/rc.local [root@rhel8 ~]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 500 6月 6 04:24 /etc/rc.d/rc.local [root@rhel8 ~]# chmod +x /etc/rc.d/rc.local
# 清空緩存
yum clean all yum makecache yum repolist
2、部署LAMP環境
- 安裝Apache(httpd)軟件(RedHat8默認自帶2.4版本)
[root@rhel8 ~]# yum -y install httpd
- 安裝PHP相關軟件(自帶2.7版本)
# 先查詢php相關軟件包
[root@rhel8 ~]# yum list | grep "php-"
# 安裝相關php軟件
[root@rhel8 ~]# yum -y install php-xml.x86_64 \
> php-json.x86_64 \ > php-mysqlnd.x86_64 \ > php-common.x86_64 \ > php-fpm.x86_64 \ > php-bcmath.x86_64 \ > php-cli.x86_64 \ > php.x86_64 \ > php-gd.x86_64 \ > php-pdo.x86_64 \ > php-devel.x86_64
- 安裝MySQL數據庫軟件(RedHat7后默認自帶Mariadb數據庫)
[root@rhel8 ~]# yum -y install mariadb-server mariadb
3、啟動相應服務
- 啟動數據庫服務
# 啟動服務,設置開機自啟
[root@rhel8 ~]# systemctl start mariadb.service
[root@rhel8 ~]# systemctl enable mariadb.service
# 查看端口
[root@rhel8 ~]# netstat -nltp | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 6914/mysqld # 設置數據庫密碼
[root@rhel8 ~]# mysqladmin -u root password '密碼'
# 進入數據庫(回車輸入密碼即可)
[root@rhel8 ~]# mysql -u root -p
# 文件數據目錄
[root@rhel8 ~]# ll /var/lib/mysql/
# 重啟下數據庫
[root@rhel8 ~]# systemctl restart mariadb
- 啟動httpd服務
# 啟動httpd服務,設置開機自啟
[root@rhel8 ~]# systemctl start httpd.service
[root@rhel8 ~]# systemctl enable httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. # 查看端口情況
[root@rhel8 ~]# netstat -nltp | grep 80
tcp6 0 0 :::80 :::* LISTEN 7232/httpd # 配置文件目錄
[root@rhel8 ~]# cd /etc/httpd/conf
[root@rhel8 conf]# ll
總用量 28
-rw-r--r-- 1 root root 11899 9月 2 2019 httpd.conf -rw-r--r-- 1 root root 13064 9月 2 2019 magic # 該文件中定義了訪問的路徑(122行)
[root@rhel8 conf]# vi httpd.conf
122 DocumentRoot "/var/www/html"
4、測試是否能解析php頁面
# 編輯一個php文件
[root@rhel8 ~]# vim /var/www/html/index.php
<?php phpinfo(); ?>
通過瀏覽器訪問IP地址能訪問到phpinfo信息界面就表示搭建成功
二、PHPSHE商城網站部署
1、上傳源碼至web服務器
# 新建目錄存放源碼,將源碼上傳至lamp目錄
[root@rhel8 ~]# mkdir /lamp
[root@rhel8 ~]# ll /lamp/
總用量 4368
-rw-r--r-- 1 root root 4469363 6月 6 06:31 phpshe1.7.rar
2、解壓並拷貝指定位置
# 由於下載的時候默認是rar壓縮,但服務器上並沒有rar解壓命令,需要安裝下rar軟件(https://www.rarlab.com/download.htm)
[root@rhel8 ~]# wget https://www.rarlab.com/rar/rarlinux-x64-5.9.1b1.tar.gz
# 解壓文件(這里建議將下載的軟件放入/usr/local/下)
[root@rhel8 ~]# mkdir /usr/local/soft
[root@rhel8 ~]# mv *.gz /usr/local/soft/
[root@rhel8 ~]# ll /usr/local/soft/
總用量 584
-rw-r--r-- 1 root root 595665 6月 4 18:31 rarlinux-x64-5.9.1b1.tar.gz [root@rhel8 ~]# cd /usr/local/soft/
[root@rhel8 soft]# tar -zxvf rarlinux-x64-5.9.1b1.tar.gz
# 進入rar目錄編譯
[root@rhel8 rar]# make
# 解壓商城源碼(unrar沒有指定目錄會在當前目錄解壓)
[root@rhel8 lamp]# unrar x phpshe1.7.rar
[root@rhel8 lamp]# pwd
/lamp # 將解壓的文件拷貝到/var/www/html中(為了方便,上面解壓時是沒有目錄,所以這里新建一個目錄存放剛剛解壓的文件,然后再將這些文件拷貝過去)
[root@rhel8 lamp]# mv *.php *.ico *.txt .ini data hook install include module template phpshe1.7
[root@rhel8 lamp]# cd phpshe1.7/
[root@rhel8 phpshe1.7]# ls
admin.php config.php hook index.php module template api.php data httpd.ini install PHPSHE安裝升級說明.txt user.php common.php favicon.ico include license.php robots.txt [root@rhel8 phpshe1.7]# mv ./* /var/www/html/
# 為源碼文件設置所有者權限(httpd默認屬主和屬組為apache),配置文件中有寫
[root@rhel8 html]# vi /etc/httpd/conf/httpd.conf
69 User apache 70 Group apache [root@rhel8 html]# chown -R apache.apache ./*
4、安裝商城系統
通過瀏覽器進行安裝:http://IP地址/install。點擊下一步進入數據庫配置頁面
配置好點擊【開始安裝】
點擊【管理后台】輸入剛剛的管理員密碼進入后台 管理系統
可以點擊首頁進入商城首頁,測試注冊