方案:
LNMP 網(wǎng)站運行環(huán)境 Linux / nginx / mysql / php
安裝LNMP平臺相關(guān)軟件
mariadb(數(shù)據(jù)庫客戶端軟件)、mariadb-server(數(shù)據(jù)庫服務(wù)器軟件)、mariadb-devel(其他客戶端軟件的依賴包)、php(解釋器)、php-fpm(進程管理器服務(wù))、php-mysql(PHP的數(shù)據(jù)庫擴展包)
1. 安裝軟件包
[root@centos7 ~]# yum -y install gcc openssl-devel pcre-devel #安裝依賴包
[root@centos7 ~]# tar -xf nginx-1.12.2.tar.gz
[root@centos7 ~]# cd nginx-1.12.2
[root@centos7 nginx-1.12.2]# ./configure \
--with-http_ssl_module \
--with-http_stub_status_module
[root@centos7 nginx-1.12.2]# make && make install
[root@centos7 ~]# yum -y install mariadb mariadb-server mariadb-devel
[root@centos7 ~]# yum -y install php php-mysql php-fpm
2. 啟動服務(wù)(nginx、mariadb、php-fpm)
[root@centos7 ~]# /usr/local/nginx/sbin/nginx #啟動Nginx服務(wù)
[root@centos7 ~]# echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local # 保證有運行權(quán)限 下次開機自啟
[root@centos7 ~]# chmod +x /etc/rc.local
[root@centos7 ~]# ss -utnlp | grep :80 #查看端口信息
[root@centos7 ~]# systemctl start mariadb #啟動mariadb服務(wù)器
[root@centos7 ~]# systemctl enable mariadb #設(shè)置開機自啟
[root@centos7 ~]# systemctl start php-fpm #啟動php-fpm服務(wù)
[root@centos7 ~]# systemctl enable php-fpm #設(shè)置開機自啟
啟動服務(wù)出錯 檢查配置文件
/usr/local/nginx/sbin/nginx -t
3. 修改Nginx配置文件,實現(xiàn)動靜分離
修改配置文件,通過兩個location實現(xiàn)動靜分離,一個location匹配動態(tài)頁面,一個location匹配其他所有頁面
注意修改默認首頁為index.php
vim +65 /usr/local/nginx/conf/nginx.conf # 可以直接定位到65行
# 重新加載配置
/usr/local/nginx/sbin/nginx -s reload
4. 配置數(shù)據(jù)庫
為網(wǎng)站提前創(chuàng)建一個數(shù)據(jù)庫、添加賬戶并設(shè)置該賬戶有數(shù)據(jù)庫訪問權(quán)限
[root@centos7 ~]# mysql
#創(chuàng)建數(shù)據(jù)庫,數(shù)據(jù)庫名稱為wordpress,該數(shù)據(jù)庫支持中文(character set utf8mb4)
MariaDB [(none)]> create database wordpress character set utf8mb4;
MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by 'wordpress';
#語法格式:grant 權(quán)限 on 數(shù)據(jù)庫名.表名 to 用戶名@客戶端主機 identified by 密碼
#創(chuàng)建用戶并授權(quán),用戶名為wordpress,該用戶對wordpress數(shù)據(jù)庫下的所有表有所有權(quán)限
#wordpress用戶的密碼是wordpress,授權(quán)該用戶可以從localhost主機登錄數(shù)據(jù)庫服務(wù)器
#all代表所有權(quán)限(wordpress用戶可以對wordpress數(shù)據(jù)庫中所有表有所有權(quán)限)
#wordpress.*代表wordpress數(shù)據(jù)庫中的所有表
MariaDB [(none)]> grant all on wordpress.* to wordpress@'192.168.2.11' identified by 'wordpress';
MariaDB [(none)]> flush privileges;
#刷新權(quán)限
MariaDB [(none)]> exit
#退出數(shù)據(jù)庫
驗證是否成功
看看是否可以使用新創(chuàng)建的賬戶登錄數(shù)據(jù)庫服務(wù)器:
mysql -uwordpress -pwordpress -h 192.168.2.11 wordpress
#-u指定數(shù)據(jù)庫賬戶名稱,-p指定數(shù)據(jù)庫賬戶的密碼,-h指定需要遠程數(shù)據(jù)庫的IP地址
#最后的wordpress為數(shù)據(jù)庫的名稱
上線wordpress代碼 (測試搭建的LNMP環(huán)境是否可以使用)
軟件使用php語言編寫,創(chuàng)建的網(wǎng)站信息是存儲在數(shù)據(jù)庫里面的。
wordpress的工作頁面是通過網(wǎng)站服務(wù)顯示的。
1. 上線php動態(tài)網(wǎng)站代碼
[root@centos7 ~]# yum install -y unzip
[root@centos7~]# unzip wordpress.zip
[root@centos7~]# cd wordpress
[root@centos7 wordpress]# tar -xf wordpress-5.0.3-zh_CN.tar.gz
[root@centos7 wordpress]# cp -r wordpress/* /usr/local/nginx/html/
[root@centos7 wordpress]# chown -R apache.apache /usr/local/nginx/html/ # -R 遞歸修改
動態(tài)網(wǎng)站運行過程中,php腳本需要對網(wǎng)站目錄有讀寫權(quán)限,而php-fpm默認啟動用戶為apache
2. 初始化網(wǎng)站配置(使用客戶端訪問web服務(wù)器IP)
firefox http://192.168.2.11/
修改配置文件 加首頁名
服務(wù)器會自動進入config配置頁面 效果如下:
開發(fā)人員在寫代碼的時候并不知道未來數(shù)據(jù)庫服務(wù)器的IP、端口、數(shù)據(jù)庫名稱、賬戶等信息,該配置頁面主要的作用就是動態(tài)配置數(shù)據(jù)庫信息,根據(jù)前面步驟配置的數(shù)據(jù)庫信息填空即可:
點擊提交即可完成數(shù)據(jù)庫的初始化工作,php動態(tài)腳本會自動在wordpress數(shù)據(jù)庫中創(chuàng)建若干數(shù)據(jù)表,后期網(wǎng)站的數(shù)據(jù)都會寫入對并的數(shù)據(jù)表中。
第一次使用Wordpress需要給你的網(wǎng)站設(shè)置基本信息,如網(wǎng)站標題、網(wǎng)站管理員賬戶與密碼等信息,配置完成后點擊安裝wordpress即可:
網(wǎng)站后臺管理
1. 訪問數(shù)據(jù)庫
> mysql
> show database;
> use wordpress;
# 看已有的表
show tables;
文章來源:http://www.zghlxwxcb.cn/news/detail-836932.html
2. 查看配置信息
文章來源地址http://www.zghlxwxcb.cn/news/detail-836932.html
到了這里,關(guān)于云計算項目一:部署LNMP動態(tài)網(wǎng)站的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!