CentOS 7, 基于rpm包方式安装部署apm(php module) + xcache; a) 一个虚拟主机提供phpMyAdmin,另一个虚拟主机提供wordpress; b) 为phpMyAdmim提供https服务;

一、环境配置 关闭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.conf > <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."; > ?> 测试结果: 二、安装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应用程序在服务器端不需要修改配置文件,直接在本地登录测试即可,如下:

至此,搭建wordpress论坛和配置phpMyAdmin应用程序成功。

三、为第二个虚拟主机站点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服务是否建立成功:

至此,https服务提供成功。

四、压力测试并比对测试使用加速器结果: [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次每秒,结果比较于安装加速器之前提升很多: