您好,登錄后才能下訂單哦!
1. 配置概要:
a) 172.16.20.10主機運行httpd+php服務(php為模塊工作模式)
b) 配置兩臺虛擬主機:wordpress個人博客系統(tǒng),PHPmyadmin遠程控制mysql
c) 172.16.20.11主機運行mariadb服務(mysql)
2. 配置流程:
a) 首先配置172.16.20.10主機:http服務
i. 安裝程序
1. #yum install httpd php php-mysql php-mbstring
2. Httpd提供web服務
3. Php 安裝后自動編譯為httpd的模塊,用于處理動態(tài)資源php腳本
4. Php-mbstring:此程序包為phpMyAdmin遠程控制mysql所必須的
5. Php-mysql:php驅動mysql的庫文件程序包
b) Rpm包安裝完成之后,進入下一步的配置階段:
i. 添加虛擬主機(基于FQDN)
1. # Vim /etc/httpd/conf.d/vhost.conf文件
添加如下內容,基于FQDN的虛擬主機配置
<VirtualHost172.18.20.10:80> # 固定語法 <VirtualHost ip:port>可忽略大小寫
ServerName # 很重要,基于FQDN的虛擬主機必須要有主機名
DocumentRoot"/www/host/htdoc" # 虛擬主機根目錄,可指定路徑
<Directory"/www/host/htdoc"> # 對虛擬主機根目錄的權限設置
OptionsFollowSymLinks # FollowSymLinks 表示可以訪問符號連接資源
require allGranted # 目錄的權限設置
</Directory>
</VirtualHost>
<VirtualHost172.18.20.10:80>
ServerNamewww.myadmin.com
DocumentRoot"/www/host2/htdoc"
<Directory"/www/host2/htdoc">
OptionsFollowSymLinks
require allGranted
</Directory>
</VirtualHost>
c) 為虛擬主機創(chuàng)建配置文件中定義的資源目錄
i. # mkdir/www/{host,host2}/htdoc
d) 添加測試資源
i. # vim /www/host/htdoc/index.php
<?php
$conn =mysql_connect('172.18.17.8','admin','admin'); # ip填寫mysql主機ip
if($conn) # 用戶為mysql所授權的用戶,密碼空
echo "DATABASEConnet OK";
else
echo"DATABASE Connet Failure";
?>
# 測試php是否正常工作的php代碼
<?php
phpinfo(); #此函數(shù)調用會顯示php的詳細信息
?>
e) 配自豪httpd主配置文件
#vim /etc/httpd/conf/httpd.conf
# 找到DocumentRoot"/var/www/html" #將其注釋掉,一般使用虛擬機都要注釋掉,避免沖突 #DocumentRoot "/var/www/html"
# 添加php主頁索引
DirectoryIndexindex.php index.html # 將index.php添加在前頭,這樣就會默認訪問此類資源索引
# 取消服務器名稱注釋
f) 啟動服務,測試是否正常
# 檢測配置文件語法有沒有錯誤
# httpd -t # 語法無誤啟動服務
# systemctl starthttpd.service 打開網頁查看服務是否正常
http服務測試正常,php模塊也能正常工作,但是,如你所見,mysql的連接是失敗,因為我們還mysql的服務器還沒有配置
g) 獲取wordpress和phpmyadmin
wordpress配置:
# 下載并解壓至/www/host/htdoc
#cd 到wordpress目錄
#復制配置文件wp-config-sample.php為wp-config.php
#cpwp-config-sample.php wp-config.php
#編輯配置文件
#vimwp-config.php
define('DB_NAME','wpdb'); # 此填寫mysql所要授權數(shù)據(jù)庫的名字(后面會配置)
/**MySQL數(shù)據(jù)庫用戶名 */
define('DB_USER','wpuser'); # 填寫數(shù)據(jù)庫的用戶名
/**MySQL數(shù)據(jù)庫密碼 */
define('DB_PASSWORD','wppasswd'); # 填寫數(shù)據(jù)的密碼
/**MySQL主機 */
define('DB_HOST','172.18.17.8'); # 填寫mysql主機的ip
/**創(chuàng)建數(shù)據(jù)表時默認的文字編碼 */
define('DB_CHARSET','utf8');
/**數(shù)據(jù)庫整理類型。如不確定請勿更改 */
define('DB_COLLATE','');
phpmyadmin配置:
# 將包下載并解壓至/www/host2/htdoc
#cd 到 文件目錄
# 創(chuàng)建符號連接
#ln -s phpMyAdmin-4.4.14.1-all-languages myadmin
#ls
index.php phpMyAdmin-4.4.14.1-all-languages
myadmin phpMyAdmin-4.4.14.1-all-languages.zip
#cd至myadmin 目錄里面,修改配置文件
#cp config.sample.inc.php config.inc.php
#編輯配置文件
#vim config.inc.php
$cfg['blowfish_secret']= 'o71mI9rimj6syc00fT3g'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
#單引號填寫隨機密碼,可使用openssl rand -base64 15(密碼長度)生成
/*
*Servers configuration
*/ $i = 0;
/* * First server
*/
$i++;
/*Authentication type */
$cfg['Servers'][$i]['auth_type']= 'cookie';
/*Server parameters */
$cfg['Servers'][$i]['host']= '172.18.17.8'; # 數(shù)據(jù)庫主機ip
$cfg['Servers'][$i]['connect_type']= 'tcp';
$cfg['Servers'][$i]['compress']= false;
$cfg['Servers'][$i]['AllowNoPassword']= false;
h) 172.16.20.11主機配置:mysql服務
# yuminstall mariadb-server 安裝mysql
# systemctlstart mariadb 啟動mysql服務
# ss –tnl 查看監(jiān)聽端口,3306為默認端口
執(zhí)行安全操作
#mysql_secure_installation
強烈建議在mysql安裝完成后執(zhí)行安全操作,這樣使得數(shù)據(jù)庫更安全
創(chuàng)建所需數(shù)據(jù)庫并授權
# mysql -uroot –p
Enterpassword:
Welcome to the MariaDBmonitor. Commands end with ; or \g.
Your MariaDB connectionid is 66
Server version:5.5.44-MariaDB MariaDB Server
Copyright (c) 2000,2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>CREATE DATABASE wpdb; # 創(chuàng)建wordpress的數(shù)據(jù)庫
Query OK, 1 rowaffected (0.02 sec)
# 授權wordpress數(shù)據(jù)庫
MariaDB [(none)]>GRANT ALL ON wpdb.* TO wpuser@172.16.20.10 IDENTIFIED BY 'wppasswd';
Query OK, 0 rowsaffected (0.01 sec)
#授權遠程訪問主機(phpMyadmin)
MariaDB [(none)]> GRANTALL ON *.* TO admin@'172.16.20.10' IDENTIFIED BY 'admin';
Query OK, 0 rowsaffected (0.01 sec)
3. 支持所有配置基本完畢,驗證結果
驗證數(shù)據(jù)庫聯(lián)通
4. 查看wordpress是否正常
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。