在centos7上實作,搭建httpd+php+mariadb三個服務:
實體主機使用win7系統;
本次實驗使用2台虛拟機,web伺服器安裝httpd和php程式包,web伺服器使用192.168.255.2,mysql資料庫伺服器安裝mariadb程式包,mysql資料庫伺服器使用192.168.255.3。
要求:
(1)httpd與php的結合方式:php以子產品形式結合httpd,三個服務部署在2台伺服器上。
(2)一個虛拟主機用于提供phpMyAdmin;另一個虛拟主機用于提供wordpress。
(3)為phpMyAdmin提供https虛拟主機。
(4)使用xcache實作php加速。
在web伺服器上操作:
]# yum -y install httpd
]# yum -y install php
]# vim /etc/httpd/conf/httpd.conf
注釋httpd主配置檔案中的首頁(即注釋掉DocumentRoot條目)
<a href="http://s4.51cto.com/wyfs02/M02/7F/5D/wKioL1ccK0TC8cAhAABGcTtQo4o819.png" target="_blank"></a>
建立虛拟主機配置檔案及網頁檔案
]# mkdir -pv /web/vhost/{www1,www2}
]# vim /web/vhost/www1/index.php
<a href="http://s3.51cto.com/wyfs02/M01/7F/60/wKiom1ccK0_xoH2BAAAVmOdeeR8750.png" target="_blank"></a>
]# vim /web/vhost/www2/index.php
<a href="http://s2.51cto.com/wyfs02/M01/7F/5D/wKioL1ccLEfTQLtUAAAcLO68oJ0277.png" target="_blank"></a>
]# vim /etc/httpd/conf.d/vhost.conf
虛機1網址:www1.stu11.com
虛機2網址:www2.stu11.com
<a href="http://s2.51cto.com/wyfs02/M02/7F/60/wKiom1ccLRaQR3NOAABaQEKywvk202.png" target="_blank"></a>
在實體主機中測試httpd是否能正常加載php子產品
首先更改實體主機的hosts檔案,添加解析條目
C:\Windows\System32\drivers\etc
<a href="http://s5.51cto.com/wyfs02/M00/7F/5E/wKioL1ccL4bDBG-EAABXsZGE_U8473.png" target="_blank"></a>
在實體機打開浏覽器測試2個虛拟主機名稱是否能正常工作
<a href="http://s3.51cto.com/wyfs02/M01/7F/5E/wKioL1ccMBTDkRwCAAC0-IvpYc8915.png" target="_blank"></a>
<a href="http://s3.51cto.com/wyfs02/M02/7F/60/wKiom1ccL06iw2VJAADHiYNGxpY517.png" target="_blank"></a>
在mysql資料庫主機操作:
]# yum -y install mariadb-server
加強資料庫安全設定
]# mysql_secure_installation
設定連接配接資料庫的root使用者密碼為root,其它設定可根據提示自行設定。
]# mysql -uroot -proot
> CREATE USER 'testuser'@'192.168.%.%' IDENTIFIED BY 'testpass';
> CREATE USER 'pmauser'@'192.168.%.%' IDENTIFIED BY 'pmapass';
> CREATE DATABASE pmadb;
> CREATE DATABASE wpdb;
> GRANT ALL ON wpdb.* TO 'wpuser'@'192.168.%.%';
> GRANT ALL ON phpdb.* TO 'pmauser'@'192.168.%.%';
在web主機操作:
測試php正常連接配接mysql伺服器
測試需要使用php連接配接資料庫的函數,安裝php-mysql
]# yum -y install php-mysql
編輯兩個虛拟主機中的網頁測試代碼
<a href="http://s5.51cto.com/wyfs02/M00/7F/61/wKiom1ccTUvg8CmUAAA1aGDvwpc520.png" target="_blank"></a>
<a href="http://s1.51cto.com/wyfs02/M00/7F/5E/wKioL1ccThHjSEfSAAAw3XhxEwM450.png" target="_blank"></a>
打開浏覽器測試
<a href="http://s3.51cto.com/wyfs02/M01/7F/5E/wKioL1ccTqTxelFbAABYVTgLiIc736.png" target="_blank"></a>
<a href="http://s2.51cto.com/wyfs02/M01/7F/5E/wKioL1ccTqTC1I29AABF3qASrXY159.png" target="_blank"></a>
php連接配接mysql資料庫ok,成功連接配接。
分别在虛機1上部署phpMyAdmin,在虛機2上部署wordpress:
下載下傳phpMyAdmin-4.4.14.1-all-languages.zip,并解壓在/web/vhost/www1目錄下
]# unzip phpMyAdmin-4.4.14.1-all-languages.zip
解壓後把檔案名改為pma即檔案名改短了使用起來友善
]# mv phpMyAdmin-4.4.14.1-all-languages pma
生成的随機數複制在下面的config.inc.php配置檔案中
]# openssl rand -base64 -15
添加phpMyAdmin的配置檔案:
]# cd pma
複制樣例配置檔案并修改
]# cp config.sample.inc.php config.inc.php
]# vim config.inc.php
添加随機數、指定mysql資料庫IP位址
<a href="http://s5.51cto.com/wyfs02/M02/7F/61/wKiom1ccT02BP3_GAABcCEC0LE0472.png" target="_blank"></a>
在浏覽器測試
<a href="http://s3.51cto.com/wyfs02/M02/7F/5E/wKioL1ccUfHyHzqDAABvYwlsdTc711.png" target="_blank"></a>
安裝中文字元集,php-mbsting包
]# yum -y install php-mbstring
]# systemctl restart httpd.service
浏覽器測試,輸入在mysql資料庫的使用者名密碼即可登入
<a href="http://s3.51cto.com/wyfs02/M00/7F/61/wKiom1ccUd-QkBMRAAC4xRuav6g006.png" target="_blank"></a>
登入後的phpMyAdmin頁面
<a href="http://s1.51cto.com/wyfs02/M01/7F/5E/wKioL1ccUySxQ_gcAAG_paxKk_M656.png" target="_blank"></a>
下載下傳wordpress-4.3.1-zh_CN.zip,解壓在/web/vhost/www2目錄下
]# unzip wordpress-4.3.1-zh_CN.zip
]# cd wordpress/
]# cp wp-config-sample.php wp-config.php
輸入mysql中的庫名、使用者、密碼及mysql主機的IP位址
<a href="http://s2.51cto.com/wyfs02/M00/7F/61/wKiom1ccVLTALyHQAABrB3_UkYs650.png" target="_blank"></a>
<a href="http://s3.51cto.com/wyfs02/M00/7F/5E/wKioL1ccVizSaDWhAACz9QlY_T4749.png" target="_blank"></a>
輸入自定義資訊,點選安裝wordpress;
<a href="http://s3.51cto.com/wyfs02/M00/7F/5E/wKioL1ccVvrDy4eoAADidXSknhU880.png" target="_blank"></a>
<a href="http://s2.51cto.com/wyfs02/M01/7F/61/wKiom1ccVu2z_8ORAACeJMhirDc664.png" target="_blank"></a>
輸入剛才設定wordpress的使用者名和密碼,登入即可:
<a href="http://s2.51cto.com/wyfs02/M01/7F/5E/wKioL1ccV7OwM8xBAAB84oQisDY206.png" target="_blank"></a>
<a href="http://s2.51cto.com/wyfs02/M01/7F/5F/wKioL1ccV7TCvHUPAAD_quMZjso249.png" target="_blank"></a>
為phpMyAdmin提供https虛拟主機:
把mysql資料庫所在主機當做CA主機,建立私有CA:
建立CA的私鑰:
]# cd /etc/pki/CA/
]# (umask 077;openssl genrsa -out private/cakey.pem 2048)
建立CA自簽證書:
<a href="http://s5.51cto.com/wyfs02/M02/7F/5F/wKioL1ccWdiiTLuRAACSoq9afDc022.png" target="_blank"></a>
]# touch serial index.txt
]# echo 01 > seria
注意:CA目錄下要有固定目錄及檔案:目錄有certs、crl、newcerts,檔案index.txt、serial。
把CA憑證發送到web伺服器主機上:
<a href="http://s5.51cto.com/wyfs02/M01/7F/5F/wKioL1ccWpaQZ9abAAA80kYZz4Q091.png" target="_blank"></a>
在web伺服器主機操作:
建立伺服器私鑰:
<a href="http://s4.51cto.com/wyfs02/M02/7F/61/wKiom1ccW1zhgEMcAAAj1niQM2I579.png" target="_blank"></a>
建立伺服器請求認證的檔案:
]# openssl req -new -key httpd.key -out httpd.csr
輸入伺服器證書内容:
<a href="http://s1.51cto.com/wyfs02/M02/7F/61/wKiom1ccXBWyDDPlAABFggN3P0I030.png" target="_blank"></a>
在CA主機上操作:
把web伺服器請求檔案發送給CA:
]# scp [email protected]:/etc/httpd/ssl/httpd.csr /tmp
給web伺服器簽證:
]# openssl ca -in /tmp/httpd.csr -out certs/httpd.crt
輸入兩次y,确認簽署即可;
CA傳回web伺服器證書檔案:
]# scp certs/httpd.crt [email protected]:/etc/httpd/ssl
安裝支援httpd的ssl的子產品
]# yum -y install mod_ssl
]# vim /etc/httpd/conf.d/ssl.conf
<a href="http://s4.51cto.com/wyfs02/M02/7F/5F/wKioL1ccbQWAwteiAAA7ZnnsMq8134.png" target="_blank"></a>
<a href="http://s3.51cto.com/wyfs02/M01/7F/5F/wKioL1ccbTejIqq3AAAvBJBTnFY726.png" target="_blank"></a>
把CA憑證導入浏覽器(步驟略)
在浏覽器上測試:
<a href="http://s3.51cto.com/wyfs02/M00/7F/61/wKiom1ccbObSxDGlAABQRep128Q924.png" target="_blank"></a>
<a href="http://s3.51cto.com/wyfs02/M02/7F/61/wKiom1ccbOfB-jGuAAGB4yYBaBI400.png" target="_blank"></a>
安裝想xcahe測試
本文轉自 crystaleone 51CTO部落格,原文連結:http://blog.51cto.com/linsj/1767224,如需轉載請自行聯系原作者