CentOS 7, 基於rpm包方式安裝部署apm(php module) + xcache;
a) 一個虛擬主機提供phpMyAdmin,另外一個虛擬主機提供wordpress;
b) 爲phpMyAdmim提供https服務;php
1、環境配置
關閉SELinux和防火牆:
安裝必要的程序包--基於rpm包方式:
httpd程序用來提供靜態頁面內容的瀏覽和訪問;php程序實現動態web頁面;php-mysql用來實現php和數據庫的鏈接;mod_ssl用來實現提供https服務;mariadb-server用阿里提供數據庫服務;
啓動配置好的服務:
查看服務狀態:
查看這次配置服務使用的模塊:
[root@chenliang ~]# vim /etc/httpd/conf.modules.d/10-php.conf
配置兩個虛擬主機站點:
[root@chenliang ~]# cd /etc/httpd/conf.d
[root@chenliang conf.d]# ls
autoindex.conf php.conf README ssl.conf userdir.conf welcome.conf www1.conf www2.conf
[root@chenliang conf.d]# vim vhost1.confhtml
<VirtualHost 172.16.72.1:80>
ServerName www.clvhost1.com
DocumentRoot /var/www/html/vhost1
</VirtualHost>
[root@chenliang conf.d]# vim vhost2.conf
<VirtualHost 172.16.72.1:80>
ServerName www.clvhost2.com
DocumentRoot /var/www/html/vhost2
</VirtualHost>
[root@chenliang conf.d]# mkdir -pv /var/www/html/vhost{1,2}
mkdir: 已建立目錄 "/var/www/html/vhost1"
mkdir: 已建立目錄 "/var/www/html/vhost2"
[root@chenliang conf.d]# echo "Vhost1's homepage." >> /var/www/html/vhost1/index.html
[root@chenliang conf.d]# echo "Vhost2's homepage." >> /var/www/html/vhost2/index.html
語法檢查配置有沒有問題,沒有問題從新啓動服務:
[root@chenliang conf.d]# httpd -t
AH00557: httpd: apr_sockaddr_info_get() failed for chenliang
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK
[root@chenliang conf.d]# systemctl restart httpd.service
在本地主機添加解析條目:
通常是C盤下\Windows\System32\drivers\etc\hosts文件添加:172.16.72.1 www.clvhost1.com www.clvhost2.com
測試結果:
創建PHP測試頁面:
[root@chenliang conf.d]# cd /var/www/html/vhost1
[root@chenliang vhost1]# ls
index.html
[root@chenliang vhost1]# mv index.html index.php
[root@chenliang vhost1]# vim index.php
Vhost1's homepage.
<?php
phpinfo();
?>
[root@chenliang vhost1]# cd /var/www/html/vhost2
[root@chenliang vhost2]# ls
index.html
[root@chenliang vhost2]# mv index.html index.php
[root@chenliang vhost2]# vim index.php
Vhost2's homepage.
<?php
phpinfo();
?>
PHP頁面鏈接測試結果:
PHP和服務器端數據庫鏈接測試:
在確認mariadb-server開啓的狀況下,建立wordpress數據庫並受權用戶:
測試數據庫鏈接是否成功:
虛擬機vhost1用來安裝配置wordpress論壇:
[root@chenliang vhost2]# cd /var/www/html/vhost1
[root@chenliang vhost1]# ls
index.php
[root@chenliang vhost1]# vim index.php
Vhost2's homepage. </br>
<?php
$conn = mysql_connect('172.16.72.1','wpuser','123456');
if($conn)
echo "Connect successful.";
else
echo "Connect failed.";
?>
測試結果:
虛擬機vhost2用來安裝配置phpMyAdmin應用程序:
[root@chenliang vhost1]# cd /var/www/html/vhost2
[root@chenliang vhost2]# ls
index.php
[root@chenliang vhost2]# vim index.php
Vhost1's homepage. </br>
<?php
$conn = mysql_connect('172.16.72.1','wpuser','123456');
if($conn)
echo "Connect successful.";
else
echo "Connect failed.";
?>
測試結果:
2、安裝wordpress論壇和phpMyAdmin應用程序:
將wordpress論壇壓縮包防放置到/var/www/html/vhost1目錄下,將phpMyAdmin應用程序壓縮包防放置到/var/www/html/vhost2目錄下:
搭建wordpress論壇:
解壓並改名(改名是爲了更好的鍵入地址):
進入wp目錄,更改配置文件和文件名:
[root@chenliang wp]# mv wp-config-sample.php wp-config.php
搭建成功:
配置phpMyAdmin應用程序:
phpMyAdmin應用程序在服務器端不須要修改配置文件,直接在本地登陸測試便可,以下:mysql
至此,搭建wordpress論壇和配置phpMyAdmin應用程序成功。web
3、爲第二個虛擬主機站點phpMyAdmim應用程序提供https服務(本次配置https在同一主機完成):
建立私有CA:
生成自簽證書:
建立文本文件和目錄文件:
爲httpd服務器生成密鑰並生成證書請求:
將證書請求發送到CA:
在CA上爲這次請求籤發證書:
在CA上將CA簽發的證書傳送到httpd服務器:
[root@chenliang ssl]# cp /etc/pki/CA/certs/httpd.crt /etc/httpd/ssl/
在httpd服務器上,刪除證書請求文件:
[root@chenliang ssl]# ls
httpd.crt httpd.csr httpd.key
[root@chenliang ssl]# rm -f httpd.csr
在vhost2虛擬主機站點服務器上配置ssl支持:
配置https的虛擬主機(保證mod_ssl模塊被正確裝載;若是沒有,則須要單獨安裝):
[root@chenliang ~]# cd /etc/httpd/conf.d
[root@chenliang conf.d]# ls
autoindex.conf php.conf README ssl.conf userdir.conf vhost1.conf vhost2.conf welcome.conf
[root@chenliang conf.d]# vim ssl.conf //在ssl.conf中僅需修改如下內容
<VirtualHost 172.16.72.1:443>
DocumentRoot "/var/www/html/vhost2/pma"
ServerName www.clvhost2.com:443
SSLCertificateFile /etc/httpd/ssl/httpd.crt
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key
<Directory "/var/www/html/vhost2/pma">
SSLOptions +StdEnvVars
</Directory>
查看端口是否有監聽到https端口443:
測試https服務是否創建成功:sql
至此,https服務提供成功。
4、壓力測試並比對測試使用加速器結果:
[root@chenliang ~]# ab -c 100 -n 1000 http://www.clvhost1.com/wp/index.php
測試顯示14.43次每秒
安裝加速器xcache後:
[root@chenliang ~]# yum -y install php-xcache //php-xcache安裝包不存在於本地光盤鏡像中,通常是發行商提供。也能夠自行編譯
再一次測試併發:
[root@chenliang ~]# ab -c 100 -n 1000 http://www.clvhost1.com/wp/index.php
結果是39.39次每秒,結果比較於安裝加速器以前提高不少:數據庫