LAMP早期即爲Linux+Apache+MySQL+PHP,以基於Linux平臺的三個軟件搭建出動態網頁站點,而如今的LAMP不只僅表明以上幾個軟件,由於如今的開源軟件種類較多,網站的構建人員的選擇也較多,因此如今的M能夠爲MySQL,也能夠爲maria DB或者是其餘的數據庫管理系統。而P則也不只可表明PHP,在實際應用中還多是Python、Perl、JSP等語言。php
本文將基於rpm包安裝的形式實現Linux+Apache+MySQL+PHP的LAMP平臺,而且實現如下功能:html
1.建立兩個虛擬主機,分別用於wordpress和phpmyadmin,要求能使用wordpress建立本身的博客,能使用phpmyadmin管理本機上的數據庫。mysql
2.使用HTTPD+SSL配置worpress的那臺虛擬主機成HTTPS服務器,實現加密通訊。linux
準備實驗環境介紹:sql
物理機是基於Windows 7的系統,在物理機上安裝Vmware 9,而後再在虛擬機上安裝CentOS 6.6系統,並配置好YUM源等。準備好後檢查YUM倉庫是否可用,以下圖所示:數據庫
實驗過程:vim
一.安裝配置虛擬主機windows
1.安裝httpd,安全
在肯定未安裝httpd的狀況下使用以下命令安裝便可:服務器
[root@LAMP /]# yum install httpd -y
2.配置虛擬主機
切換目錄在/etc/httpd/conf.d/新建虛擬主機配置文件virtualhost.conf,以下所示
註釋掉/etc/httpd/conf/httpd.conf配置文件中的Section 2 部份內的DocumentRoot項
1.爲虛擬主機新建目錄並提供測試頁面
新建虛擬主機目錄
[root@LAMP conf.d]# mkdir -pv /data/{wordpress,Myadmin}
mkdir: created directory `/data'
mkdir: created directory `/data/wordpress'
mkdir: created directory `/data/Myadmin'
[root@LAMP conf.d]#
提供臨時測試頁面index.html
[root@LAMPconf.d]#echo"HIwordpress">/data/wordpress/index.html
[root@LAMP conf.d]# echo "HI Myadmin">/data/Myadmin/index.html
[root@LAMP conf.d]#
2.重啓測試
重啓服務並關閉iptables和SElinux
[root@LAMP conf.d]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: apr_sockaddr_info_get() failed for LAMP
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
[root@LAMP conf.d]# service iptables stop
[root@LAMP conf.d]# setenforce 0
[root@LAMP conf.d]#
2、安裝php,ph-mysql,mysql-server,配置phpMyadmin和wordpress
1.直接使用yum安裝好以上軟件,
[root@LAMP wordpress]# yum install php php-mysql mysql-server -y
2.下載phpMyadmin和wordpress並解壓到/data/Myadmin和/data/wordpress目錄下,刪除之前存在的Myadmin和wordpress目錄並直接將phpMyadmin和wordpress解壓後改名爲Myadmin和wordpress
[root@LAMP data]# ls
Myadmin wordpress
3.重啓服務,並測試
能看到以下信息,則表示配置沒問題
[root@LAMP data]# elinks -dump www.myadmin.com
ELinks: Host not found
[root@LAMP data]# vim /etc/hosts
[root@LAMP data]# elinks -dump www.myadmin.com
[1]phpMyAdmin
Welcome to phpMyAdmin
Language [[2]________________________________] [3][ Go ]
Log in[4]phpMyAdmin documentation
Username: [5]_________________________
Password: [6]_________________________
[7][ Go ]
Cannot load [8]mcrypt extension. Please check your PHP configuration.
Cookies must be enabled past this point.
References
Visible links
1. http://www.phpmyadmin.net/
4. http://www.myadmin.com/Documentation.html?phpMyAdmin=vvpak8172gftl0hi3fqkkpiu036he9vh
8. http://php.net/mcrypt
[root@LAMP data]# elinks -dump www.wordpress.com
看起來彷佛沒有 wp-config.php 文件。開始以前,咱們須要這個文件。須要幫助?
您可查看[1]這篇幫助文檔。您能夠經過本網頁界面來編輯 wp-config.php 文件,但
並不是全部主機都支持這種方法。最安全的作法還是手動建立。
[2]試試建立一個配置文件
References
Visible links
1. http://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php
2. http://www.wordpress.com/wp-admin/setup-config.php
4.啓動並配置mysql,建立wordpress數據庫,爲用戶wuxiaotao受權。
建立wordpress數據庫
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| wordpress |
+--------------------+
4 rows in set (0.00 sec)
mysql>
爲用戶wuxiaotao受權
mysql> GRANT ALL ON wordpress.* TO 'wuxiaotao'@'127.0.0.1' IDENTIFIED BY 'hello mage';#由於mysql和http是安裝在同一主機上,配置其可在本地登陸便可
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL ON wordpress.* TO 'wuxiaotao'@'localhost' IDENTIFIED BY 'hello mage';#配置其反解
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;#通知mysql重讀受權信息
Query OK, 0 rows affected (0.00 sec)
5.配置wordpress,測試
切換目錄至/data/wordpress目錄,並複製wp-config-sample.php 爲wp-config.php
[root@LAMP data]# cd wordpress/
[root@LAMP wordpress]# ls
index.php wp-admin wp-comments-post.php wp-cron.php wp-load.php wp-rdf.php wp-settings.php
license.txt wp-app.php wp-commentsrss2.php wp-feed.php wp-login.php wp-register.php wp-signup.php
readme.html wp-atom.php wp-config-sample.php wp-includes wp-mail.php wp-rss2.php wp-trackback.php
wp-activate.php wp-blog-header.php wp-content wp-links-opml.php wp-pass.php wp-rss.php xmlrpc.php
[root@LAMP wordpress]# cp wp-config-sample.php wp-config.php
修改wp-config.php文件,更改內容以下
重啓服務並測試
登陸mysql
www.mywordpress.com
如上顯示,成功!
3、配置wordpress稱爲HTTPS
1.另起一臺虛擬機,設置其IP爲172.16.35.3,改主機用做CA
生成CA私鑰
[root@CA CA]# (umask 077;openssl genrsa -out private/pam.key 1024)
Generating RSA private key, 1024 bit long modulus
..........++++++
............++++++
e is 65537 (0x10001)
生成簽證書
[root@CA CA]# openssl req -new -x509 -key private/pam.key -out server.pem -days 36000
根據提示鍵入相關信息
修改openssl配置文件(/etc/pki/tls/openssl.cf),併爲CA提供配置文件
[root@CA CA]# echo "01">serial
2.客戶端生成證書
客戶端生成私鑰
[root@LAMP ssl]# (umask 077;openssl genrsa -out httpd.key 1024)
Generating RSA private key, 1024 bit long modulus
.........++++++
...++++++
e is 65537 (0x10001)
客戶端生成證書
[root@LAMP ssl]# openssl req -new -key httpd.key -out httpd.csr
根據提示鍵入相關信息
3.複製客戶端證書到CA服務器端,並簽署
複製客戶端證書到CA服務器
[root@LAMP ssl]# scp /etc/httpd/ssl/httpd.csr root@172.16.35.3:/etc/pki/CA/
根據提示輸入密碼等驗證信息
CA服務器端簽署請求
[root@CA CA]# openssl ca -in httpd.csr -out httpd.crt -days 3650
把簽署號的證書發回http服務器
[root@CA CA]#scp/etc/pki/CA/root@172.16.35.3:/etc/httpd/ssl/httpd.csr
4.在主機LAMP上安裝mod_ssl模塊並配置。
安裝mod_ssl
[root@LAMP ssl]# yum install mod_ssl
配置/etc/httpd/conf.d/ssl.conf
把以前在virtualhost.conf文件中的關於wordpress的虛擬主機刪除。
2.爲網卡子接口配置第地址,並測試:
配置網卡子接口
[root@LAMP ~]# ifconfig eth0:1 172.16.35.4/16
在windows主機中修改C:\Windows\System32\drivers\etc\hosts文件爲其添加以下條目
重啓服務並測試
[root@LAMP ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: apr_sockaddr_info_get() failed for LAMP
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[Thu Apr 30 23:55:41 2015] [warn] NameVirtualHost *:80 has no VirtualHosts
[ OK ]
測試www.mywordpress.com