基於RPM包的LAMP搭建

  1. 1.     配置概要:

  2. a)      172.16.20.10主機運行httpd+php服務(php爲模塊工作模式)

  3. b)      配置兩臺虛擬主機:wordpress個人博客系統,PHPmyadmin遠程控制mysql

  4. c)      172.16.20.11主機運行mariadb服務(mysql)

  5. 2.     配置流程:

  6. a)      首先配置172.16.20.10主機:http服務

                i.         安裝程序

  1. 1.      #yum install httpd php php-mysql php-mbstring

  2. 2.      Httpd提供web服務

  3. 3.      Php 安裝後自動編譯爲httpd的模塊,用於處理動態資源php腳本

  4. 4.      Php-mbstring:此程序包爲phpMyAdmin遠程控制mysql所必須的

  5. 5.      Php-mysql:php驅動mysql的庫文件程序包

  6. b)      Rpm包安裝完成之後,進入下一步的配置階段:

                i.         添加虛擬主機(基於FQDN)

  1. 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>

  1. c)      爲虛擬主機創建配置文件中定義的資源目錄

                i.         # mkdir/www/{host,host2}/htdoc

  1. 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();                      #此函數調用會顯示php的詳細信息 

?>

  1. e)      配自豪httpd主配置文件

#vim /etc/httpd/conf/httpd.conf 

# 找到DocumentRoot"/var/www/html"                     #將其註釋掉,一般使用虛擬機都要註釋掉,避免衝突  #DocumentRoot "/var/www/html"

# 添加php主頁索引 

DirectoryIndexindex.php index.html # 將index.php添加在前頭,這樣就會默認訪問此類資源索引    

# 取消服務器名稱註釋

  1. f)      啓動服務,測試是否正常

# 檢測配置文件語法有沒有錯誤 

# httpd -t  # 語法無誤啓動服務 

# systemctl starthttpd.service  打開網頁查看服務是否正常

spacer.gif

http服務測試正常,php模塊也能正常工作,但是,如你所見,mysql的連接是失敗,因爲我們還mysql的服務器還沒有配置

  1. 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所要授權數據庫的名字(後面會配置)    

/**MySQL數據庫用戶名 */    

define('DB_USER','wpuser'); # 填寫數據庫的用戶名    

/**MySQL數據庫密碼 */ 

define('DB_PASSWORD','wppasswd'); # 填寫數據的密碼    

/**MySQL主機 */ 

define('DB_HOST','172.18.17.8'); # 填寫mysql主機的ip   

/**創建數據表時默認的文字編碼 */ 

define('DB_CHARSET','utf8');    

/**數據庫整理類型。如不確定請勿更改 */ 

define('DB_COLLATE','');

phpmyadmin配置:

# 將包下載並解壓至/www/host2/htdoc

#cd 到 文件目錄 

# 創建符號連接 

#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';  # 數據庫主機ip  

$cfg['Servers'][$i]['connect_type']= 'tcp'; 

$cfg['Servers'][$i]['compress']= false; 

$cfg['Servers'][$i]['AllowNoPassword']= false;

  1. h)      172.16.20.11主機配置:mysql服務

# yuminstall mariadb-server                  安裝mysql

# systemctlstart mariadb                                 啓動mysql服務

# ss –tnl                                                         查看監聽端口,3306爲默認端口

執行安全操作

#mysql_secure_installation

強烈建議在mysql安裝完成後執行安全操作,這樣使得數據庫更安全

 

創建所需數據庫並授權

                            # 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; # 創建wordpress的數據庫 

Query OK, 1 rowaffected (0.02 sec)

 

# 授權wordpress數據庫 

MariaDB [(none)]>GRANT ALL ON wpdb.* TO [email protected] 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)

  1. 3.     支持所有配置基本完畢,驗證結果

驗證數據庫聯通

spacer.gif

  1. 4.     查看wordpress是否正常

spacer.gif


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章