Lamp
实验要求:
在同一台linux主机上部署Lamp,实现两个虚拟主机web1,web2,分别跑phpMyadmin,wordpress应用,且提供https服务。
Linux主机:centos7.2 一块网卡 eno16777728 桥接模式 ip 172.16.254.79/16
首先关闭selinux setenforce 0,避免影响实验。
安装所需软件包:
Yum -y install httpd php php-mysql php-mbstring mariadb-server
创建虚拟主机web1 web2站点的根目录:
Mkidr /data/web1/
Mkdir /data/web2/
在httpd.2-4上配置虚拟主机web1,web2的配置文件
[root@localhost CA]# cat /etc/httpd/conf.d/web1.conf
<VirtualHost 172.16.254.79>
ServerName www1.wudang.com
DocumentRoot /data/web1
DirectoryIndex index.php
ErrorLog logs/www1_error_log
CustomLog logs/www1_access_log combined
<Directory /data/web1/mpa>
Options Indexes FollowSymLinks
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
[root@localhost CA]# cat /etc/httpd/conf.d/web2.conf
<VirtualHost 172.16.254.79>
ServerName www2.shaolin.com
DocumentRoot /data/web2
DirectoryIndex index.php
ErrorLog logs/www2_error_log
CustomLog logs/www2_access_log combined
<Directory /data/web2/>
Options Indexes FollowSymLinks
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
下载 phpMyAdmin-4.4.14.1-all-languages.zip wordpress-4.3.1-zh_CN.zip
解压两个应用程序包到站点根目录:
Unzip phpMyAdmin-4.4.14.1-all-languages.zip
Unzip wordpress-4.3.1-zh_CN.zip
创建两个应用程序根目录的软连接文件:
Ln -svf /data/web1/ phpMyAdmin-4.4.14.1-all-languages /data/web1/mpa
Ln -svf /data/web2/wordpress /data/web2/wordpress
配置两个应用程序与数据库mariadb的连接:
cp /data/web1/mpa/config.sample.inc.php /data/web1/mpa/config.inc.php
Vim /data/web1/mpa/config.inc.php
$cfg[‘blowfish_secret‘] = ‘1rnbfOvowLY6GA‘; ----生成密钥的随机数
$cfg[‘Servers‘][$i][‘host‘] = ‘localhost‘;-------------mariadb主机地址
Cp /data/web2/wordpress/wp-config-sample.php /data/web2/wordpress/wp-config.php
Vim /data/web2/wordpress/wp-config.php
define(‘DB_NAME‘, ‘wordpress‘);-------事先创建好的数据库
/** MySQL数据库用户名 */
define(‘DB_USER‘, ‘jack‘);-------- 管理数据库的用户名
/** MySQL数据库密码 */-----Jack用户连接数据库的密码
define(‘DB_PASSWORD‘, ‘123456‘);
/** MySQL主机 */
define(‘DB_HOST‘, ‘172.16.254.79‘);-------mariadb数据库的地址
启动mariadb
Systemctl strart mariadb.service
连接数据库
Mysql
创建一个数据库用户:
Grant all on *.* to ‘jack’@’%’ identified by ‘123456’ ;
Flush privileges;
启动httpd
Systemctl start httpd
http服务测试:测试机win7 hosts文件添加一条记录
172.16.254.79 www1.wudang.com www2.shaolin.com
http://www2.shaolin.com/wordpress
两个站点phpMyadmi,wordpress 提供https服务
httpd.2-4安装mod_ssl 模块
Yum -y install mod_ssl
创建CA证书:
(umask 066; openssl genrsa -out private/cakey.pem 1024)
openssl req -new -x509 -key private/cakey.pem -days 3650 -out cacert.pem
创建站点phpMyadmin私钥和证书:
(umask 066;openssl genrsa -out /etc/httpd/web1/php.key 1024) openssl req -new -key /etc/httpd/web1/php.key -days 365 -out /etc/httpd/web1/php.csr
openssl ca -in /etc/httpd/web1/php.csr -out certs/php.crt
创建站点wordpress私钥和证书:
mkdir /etc/httpd/web2
(umask 066; openssl genrsa -out /etc/httpd/web2/wordpress.key 1024)
openssl req -new -key /etc/httpd/web2/wordpress.key -days 365 -out /etc/httpd/web2/wordpress.csr
openssl ca -in /etc/httpd/web2/wordpress.csr -days 365 -out certs/wordpress.crt
cp certs/wordpress.crt /etc/httpd/web2/
配置ssl模块配置文件即httpd的配置文件:
Listen 443 httpsi
<VirtualHost 172.16.254.79:443>
DocumentRoot "/data/web2/"
ServerName www2.shaolin.com:443
SSLProtocol All -SSLv2
DirectoryIndex index.php
SSLEngine on
ErrorLog logs/www2_ssl_error_log
LogLevel warn
SSLCertificateFIle /etc/httpd/web2/wordpress.crt
SSLCertificateKeyFile /etc/httpd/web2/wordpress.key
<Directory /data/web2/>
Options Indexes
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
Listen 443 httpsi
<VirtualHost 172.16.254.79:443>
DocumentRoot "/data/web1/"
ServerName www1.wudang.com:443
SSLProtocol All -SSLv2
DirectoryIndex index.php
SSLEngine on
ErrorLog logs/www1_ssl_error_log
LogLevel warn
SSLCertificateFIle /etc/httpd/web1/php.crt
SSLCertificateKeyFile /etc/httpd/web1/php.key
<Directory /data/web1/>
Options Indexes FollowSymLinks
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
把CA的证书导入到浏览器中的受信任的根证书机构。
https测试:
https://www2.shaolin.com/wordpress
原文:http://11185786.blog.51cto.com/11175786/1834509