天天看點

建構LAMP平台利用虛拟主機實作提供discuz論壇、基于SSL安裝phpMyAdmin、安裝wordpress...

建立Web服務,提供LAMP平台,提供至少3個虛拟主機,基于主機名實作: 

下面是3個虛拟主機,及其網頁目錄存放位置:

www.magedu.com  /web/vhosts/www

pma.magedu.com /web/vhosts/pma

wp.magedu.com  /web/vhosts/wp

要求:

    為虛拟主機www.magedu.com提供一個discuz論壇。

    為虛拟主機pma.magedu.com安裝一個PHP開發的網站頁面(即安裝phpMyAdmin軟體),要基于SSL來實作。

    為虛拟主機wp.magedu.com安裝wordpress。

一、準備工作:

1、關閉selinux

由于我們所要做的實驗會改動web服務的網頁目錄,是以隻有關閉selinux才會生效。關閉selinux的方法有以下2種:

(1)直接在指令行中輸入setenforce 0,但這種方式隻會目前shell有效,當系統重新開機時,又會失效。

  1. [[email protected] ~]# getenforce   
  2. Enforcing  
  3. [[email protected] ~]# setenforce 0  
  4. [[email protected] ~]# getenforce   
  5. Permissive 

(2)修改selinux的配置檔案/etc/sysconfig/selinux

建構LAMP平台利用虛拟主機實作提供discuz論壇、基于SSL安裝phpMyAdmin、安裝wordpress...

2、我這裡沒有配置dns,是以就編輯RHEL5.8系統上的/etc/hosts,還有Win7上的hosts檔案來實作域名解析:

  1. 在/etc/hosts檔案中和Win7的hosts檔案中添加如下四行内容,以實作域名解析  
  2. 172.16.26.1     www.magedu.com  
  3. 172.16.26.1     pma.magedu.com  
  4. 172.16.26.1     wp.magedu.com 
  5. 172.16.26.1 linli.linux //linli.linux是我的主機名,如果你的主機名不是
  6. 新設定,這一行是沒有必要的。

3、phpMyAdmin的認證過程是依賴于時間的,是以要保證cookie時間要和本地時間保持一緻:

  1. 使用hwclock可以使用同步時間  
  2. [[email protected] ~]# hwclock -s  
  3. [[email protected] ~]# date  
  4. Tue Jul  3 10:48:06 CST 2012 

二、建構LAMP平台:

1、使用CD光牒配置yum源

 (1)挂載CD光牒(注意:挂載的CD光牒要有php53相關的rpm包):

建構LAMP平台利用虛拟主機實作提供discuz論壇、基于SSL安裝phpMyAdmin、安裝wordpress...

為了可以在每次啟動時/dev/cdrom可以自動挂載,可以編輯/etc/fstab添加如下一行:

  1. /dev/cdrom              /dev/cdrom              iso9660 defaults        0 0 

(2)編輯/etc/yum.repos.d/my_yum.repo檔案,添加内容如下:

  1. [base]  
  2. name=Server 
  3. baseurl=file:///mnt/cdrom/Server  
  4. gpgcheck=0 
  5. enabled=1 
  6. [Cluster]  
  7. name=Cluster 
  8. baseurl=file:///mnt/cdrom/Cluster  
  9. gpgcheck=0 
  10. enabled=1 
  11. [ClusterStorage]  
  12. name=ClusterStorage 
  13. baseurl=file:///mnt/cdrom/ClusterStorage  
  14. gpgcheck=0 
  15. enabled=1 
  16. [VT]  
  17. name=VT 
  18. baseurl=file:///mnt/cdrom/VT  
  19. gpgcheck=0 
  20. enabled=1 

(3)此時可以先使用指令yum clean all 清除一下緩存資料,然後使用yum repolist看看yum源是否配置成功。

2、用rpm包安裝web服務,提供LAMP平台

  1. [[email protected] ~]# yum -y install httpd php53 php53-mbstring php53-mysql mysql myql-server 

注意:要安裝php53,是為了安裝phpMyAdmin;因為phpMyAdmin-3.4的系列和phpMyAdmin-3.5的系列要求安裝的php是5.3以後的版本。

3、配置3個虛拟主機

 (1)建立web伺服器提供網頁的目錄

建構LAMP平台利用虛拟主機實作提供discuz論壇、基于SSL安裝phpMyAdmin、安裝wordpress...

 (2)修改httpd配置檔案,添加3個基于主機名的虛拟主機

  1. [[email protected] ~]# vim /etc/httpd/conf/httpd.conf   
  2. #注釋DocumentRoot  
  3. #DocumentRoot "/var/www/html"  
  4. #将NameVirtualHost的注釋去掉  
  5. NameVirtualHost *:80  
  6. #讓httpd支援php網頁
  7. DirectoryIndex index.php index.html index.html.var
  8. #設定虛拟主機  
  9. <VirtualHost 172.16.26.1:80> 
  10.   ServerName www.magedu.com  
  11.   DocumentRoot /web/vhosts/www  
  12. </VirtualHost> 
  13. <VirtualHost 172.16.26.1:80> 
  14.   ServerName pma.magedu.com  
  15.   DocumentRoot /web/vhosts/pma  
  16. </VirtualHost> 
  17. <VirtualHost 172.16.26.1:80> 
  18.   ServerName wp.magedu.com  
  19.   DocumentRoot /web/vhosts/wp  
  20. </VirtualHost> 

 (3)使用指令httpd -t 測試httpd的配置檔案是否有文法,然後啟動服務就OK了

建構LAMP平台利用虛拟主機實作提供discuz論壇、基于SSL安裝phpMyAdmin、安裝wordpress...

 4、為3個虛拟主機提供網頁,并測試:

  1. [[email protected] ~]# echo "<h1>www.magedu.com</h1>" > /web/vhosts/www/index.html  
  2. [[email protected] ~]# echo "<h1>pma.magedu.com</h1>" > /web/vhosts/pma/index.html  
  3. [[email protected] ~]# echo "<h1>wp.magedu.com</h1>" > /web/vhosts/wp/index.html 
建構LAMP平台利用虛拟主機實作提供discuz論壇、基于SSL安裝phpMyAdmin、安裝wordpress...
建構LAMP平台利用虛拟主機實作提供discuz論壇、基于SSL安裝phpMyAdmin、安裝wordpress...
建構LAMP平台利用虛拟主機實作提供discuz論壇、基于SSL安裝phpMyAdmin、安裝wordpress...

5、啟動mysqld, 首次啟動會做mysql初始化:

  1. [[email protected] ~]# service mysqld start 

6、設定服務開機自動啟動

  1. [[email protected] ~]# chkconfig httpd on  
  2. [[email protected] ~]# chkconfig mysqld on  

注意:

        php在這種模型下預設是以apache的子產品存在的,是以apache服務啟動來,php就不用啟動了。

7、測試php能否連上mysql

  1. [[email protected] ~]# vim /web/vhosts/www/index.html <h1>www.magedu.com</h1> 
  2. <?php 
  3.   $link=mysql_connect('localhost','root','redhat');  
  4.   if ($link)  
  5.     echo "Success!!!";  
  6.   else   
  7.     echo "Faulure...";  
  8. mysql_close();  
  9. ?> 
建構LAMP平台利用虛拟主機實作提供discuz論壇、基于SSL安裝phpMyAdmin、安裝wordpress...

三、為www.magedu.com安裝discuz論壇:

(1)解壓縮Discuz軟體包,并将upload目錄下的所有檔案複制到/web/vhosts/www/目錄中:

  1. unzip Discuz_7.2_FULL_SC_GBK.zip   
  2. mv upload/* /web/vhosts/www/  

(2)在浏覽器中輸入www.magedu.com/install 開始安裝Discuz:

  此時會出現一些小問題隻需要按提示做就OK了。

将小問題彙總如下:

  1. //在一打開網頁你就會看到是亂碼,這時你隻需要修改一下httpd的配置檔案注釋UTF-8這一行,并重新開機httpd服務即可:  
  2. [[email protected] ~]# vim /etc/httpd/conf/httpd.conf   
  3. #AddDefaultCharset UTF-8  
  4. [[email protected] ~]# service httpd restart  
  5. Stopping httpd:                                            [  OK  ]  
  6. Starting httpd:                                            [  OK  ]  
  7. //上面配置好之後,重新整理一下頁面,當你點選下一步時,會讓你編輯/etc/php.ini檔案将short_open_tag設定為on,然後重新開機服務即可:  
  8. [[email protected] ~]# vim /etc/php.ini  
  9. short_open_tag = on 
  10. [[email protected] ~]# service httpd restart  
  11. Stopping httpd:                                            [  OK  ]  
  12. Starting httpd:     
  13. //重新整理頁面之後,到開始安裝界面,你會看到目錄、檔案權限有問題,按照提示一步一步的将檔案權限設定對就OK了  
  14. [[email protected] ~]# cd /web/vhosts/www/  
  15. [[email protected] www]# setfacl -m u:apache:rw config.inc.php   
  16. [[email protected] www]# setfacl -m u:apache:rwx p_w_uploads/ forumdata/ forumdata/cache/ forumdata/templates forumdata/threadcaches/ forumdata/logs/ uc_client/data/cache/    
  17. //在安裝資料庫界面下,需要填寫資料庫使用者名和密碼,此時使用root是不安全的,是以建立一個discuz使用者添加密碼,并授權:   
  18. mysql> Create USER discuz@'localhost' IDENTIFIED BY 'redhat';  
  19. Query OK, 0 rows affected (0.01 sec)  
  20. mysql> GRANT all ON discuz.* TO discuz@'localhost';   
  21. Query OK, 0 rows affected (0.00 sec) 

四、為pma.magedu.com安裝phpMyAdmin:

    phpMyAdmin是一個非常好的基于web頁面實作MySQL管理的GUI,用戶端隻需要有一個浏覽器即可。

 1、安裝phpMyAmin:

 phpMyAmin-3.5.1-all-languages.tar.bz2是web伺服器的網頁頁面,将解壓之後的内容移動到可執行目錄中或網頁目錄中即可:

  1. [[email protected] ~]# tar xf phpMyAdmin-3.5.1-all-languages.tar.bz2   
  2. [[email protected] ~]# cd phpMyAdmin-3.5.1-all-languages  
  3. [ro[email protected] phpMyAdmin-3.5.1-all-languages]# mv * /web/vhosts/pma  
  4. [[email protected] phpMyAdmin-3.5.1-all-languages]# cd /web/vhosts/pma/ 

2、pma運作起來需要一個配置檔案,在目前目錄下有一個config.sample.inc.php檔案,這是一個pma的樣例配置檔案,隻需要把它重命名一下,改為config.inc.php:

  1. [[email protected] pma]# cp config.sample.inc.php config.inc.php 

3、修改pma的配置檔案

    由于pma是通過浏覽器來浏覽、管理我們的MySQL伺服器,但在管理時需要一個賬号密碼才可以進行管理,而這個賬号密碼是通過網際網路發送。http又是明文傳輸的,是以要修改一下配置檔案的下面這一行内容:

  1. [[email protected] pma]# vim config.inc.php   
  2. cfg['blowfish_secret'] = 'skjfaoiursnfvksjfhdskdh' 

    注意:

        (1)blowfish_secret:是為了加密使用者在用戶端浏覽器中産生的cookie資訊,是一種安全防護機制。如果不加密,别人就可以通過cookie直接連上我們的MySQL伺服器。

 (2)'skjfaoiursnfvksjfhdskdh':是随便輸入的一段字元串。

4、blowfish_secret隻是為了保證cookie是加密的;但http在傳輸中還是明文的,為了保證http在傳輸中也是密文的就需要安裝SSL。

(1)配置CA伺服器

  1. //修改儲存目錄  
  2. [[email protected] ~]# vim /etc/pki/tls/openssl.cnf  
  3. dir             = /etc/pki/CA   
  4. //建立CA所需要的目錄及檔案   
  5. [[email protected] ~]# cd /etc/pki/CA  
  6. [[email protected] CA]# mkdir certs newcerts crl  
  7. [[email protected] CA]# touch index.txt  
  8. [[email protected] CA]# echo 01 > serial 

(2)自簽證書

  1. [[email protected] CA]# (umask 077;openssl genrsa 2048 > private/cakey.pem)  
  2. Generating RSA private key, 2048 bit long modulus  
  3. .......................+++  
  4. .................................................................................+++  
  5. e is 65537 (0x10001)  
  6. [[email protected] CA]# openssl req -x509 -new -key private/cakey.pem -out cacert.pem -days 3650  
  7. You are about to be asked to enter information that will be incorporated  
  8. into your certificate request.  
  9. What you are about to enter is what is called a Distinguished Name or a DN.  
  10. There are quite a few fields but you can leave some blank  
  11. For some fields there will be a default value,  
  12. If you enter '.', the field will be left blank.  
  13. -----  
  14. Country Name (2 letter code) [GB]:ZG  
  15. State or Province Name (full name) [Berkshire]:HenNan  
  16. Locality Name (eg, city) [Newbury]:ZZ  
  17. Organization Name (eg, company) [My Company Ltd]:magedu.ca  
  18. Organizational Unit Name (eg, section) []:Tech  
  19. Common Name (eg, your name or your server's hostname) []:ca  
  20. Email Address []: 

(3)httpd伺服器申請CA為自己簽署證書

  1. [[email protected] pma]# mkdir ssl  
  2. [[email protected] pma]# cd ssl  
  3. [[email protected] ssl]# (umask 077;openssl genrsa 1024 > httpd.key)  
  4. Generating RSA private key, 1024 bit long modulus  
  5. .....++++++  
  6. ..........++++++  
  7. e is 65537 (0x10001)  
  8. [r[email protected] ssl]# openssl req -new -key httpd.key -out httpd.csr  
  9. You are about to be asked to enter information that will be incorporated  
  10. into your certificate request.  
  11. What you are about to enter is what is called a Distinguished Name or a DN.  
  12. There are quite a few fields but you can leave some blank  
  13. For some fields there will be a default value,  
  14. If you enter '.', the field will be left blank.  
  15. -----  
  16. Country Name (2 letter code) [GB]:ZG  
  17. State or Province Name (full name) [Berkshire]:HenNan  
  18. Locality Name (eg, city) [Newbury]:ZZ  
  19. Organization Name (eg, company) [My Company Ltd]:pma.magedu.com  
  20. Organizational Unit Name (eg, section) []:Tech  
  21. Common Name (eg, your name or your server's hostname) []:linli.linux                      
  22. Email Address []:  
  23. Please enter the following 'extra' attributes  
  24. to be sent with your certificate request  
  25. A challenge password []:  
  26. An optional company name []:
  27. //CA簽署證書 
  28. [[email protected] ssl]# openssl ca -in httpd.csr -out httpd.crt -days 3650  
  29. Using configuration from /etc/pki/tls/openssl.cnf  
  30. Check that the request matches the signature  
  31. Signature ok  
  32. The organizationName field needed to be the same in the  
  33. CA certificate (magedu.ca) and the request (pma.magedu.com) 

5、使用浏覽器測試通路pma.magedu.com:

建構LAMP平台利用虛拟主機實作提供discuz論壇、基于SSL安裝phpMyAdmin、安裝wordpress...

 注意:

 (1)預設是不支援root空密碼通路的,是以需要設定mysql資料庫中的user表中的root使用者所對應的密碼

(2)安裝PHP擴充時,隻需使用rpm指令安裝libmcrypt和php53-mcrypt包即可。

五、為wp.magedu.com安裝wordpress:

 wordpress在全球是最流行的站點快速建構工具之一,是一個個人部落格系統。子產品化設計,支援子產品、CMS等各種接口。

1、安裝wordpress軟體包:

  1. # unzip wordpress-3.3.1-zh_CN.zip  
  2. # mv wordpress/* /web/vhosts/wp/ 

2、使用浏覽器輸入wp.magedu.com,然後按提示一步一步安裝即可,最後成功的界面如下:

建構LAMP平台利用虛拟主機實作提供discuz論壇、基于SSL安裝phpMyAdmin、安裝wordpress...

注意:

(1)添加過資料庫、使用者,并給使用者授予權限之後,需要重新開機mysqld。

轉載于:https://blog.51cto.com/smile2013/916756