您好,登錄后才能下訂單哦!
LAMP的搭建:
使用兩臺虛擬機,一臺虛擬機安裝httpd及php,把php作為模塊編譯進httpd中,另一臺安裝mysql,讓php能調用mysql來讀取數據。
虛擬機1:172.18.250.76 Centos6.7 安裝httpd、php
虛擬機2:172.18.250.10 Centos6.7 安裝mysql
利用httpd創建兩基于域名的虛擬主機,分別運行wordpress博客和phpmyadmin數據庫。
一:yum安裝httpd
[root@localhost ~]# yum -y install httpd
1、編輯配置文件,注釋DocumentRoot
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf #DocumentRoot "/var/www/html"
2、創建虛擬主機文件,編輯文件
[root@localhost php]# vim /etc/httpd/conf.d/vhost.conf NameVirtualHost 172.18.250.76:80 <VirtualHost 172.18.250.76:80> ServerName www.a.com DocumentRoot "/www/blog" <Directory " "> Options None Allowoverride None Order allow,deny allow from all </Directory> </virtualHost> <VirtualHost 172.18.250.76:80> ServerName www.b.net DocumentRoot "/www/php" <Directory " "> Options None Allowoverride None Order allow,deny allow from all </Directory> </virtualHost>
3、啟動httpd服務,查看監聽端口
[root@localhost php]# netstat -ntlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 :::80 :::* LISTEN 2201/httpd
4、創建虛擬主機路徑,并驗證能否正常訪問
[root@localhost conf.d]# mkdir -p /www/blog [root@localhost conf.d]# mkdir -p /www/php [root@localhost conf.d]# cd /www/php [root@localhost php]# echo " [root@localhost conf.d]# cd /www/blog [root@localhost blog]# echo "www.a.com">index.html
重啟httpd服務,驗證:
二、yum安裝php
[root@localhost php]# yum -y install php [root@localhost php]# httpd -M //查看httpd所加載的模塊 php5_module (shared) //php已經編輯進httpd
驗證php能否正常加載:
[root@localhost php.d]# vim /www/blog/index.php <?php phpinfo(); ?>
三、安裝mysql
[root@lsj ~]# yum -y install mysql-server [root@lsj ~]# service mysqld start
授權一個遠程賬號,讓PHP能訪問mysql
mysql> grant all on *.* to admin@'172.18.250.76' identified by "admin";
安裝mysql驅動,支持php遠程
[root@localhost modules]# yum -y install php-mysql [root@localhost modules]# vim /www/blog/index.php <?php $conn = mysql_connect ('172.18.250.10','admin','admin'); if ($conn) echo "success"; else echo "false" ?>
四、安裝wordpress和phpmyadmin軟件
[root@localhost wordpress]# unzip wordpress-4.3.1-zh_CN.zip [root@localhost blog]# cd wordpress [root@localhost wordpress]# cp wp-config-sample.php wp-config.php [root@localhost wordpress]# vim wp-config.php /** WordPress數據庫的名稱 */ define('DB_NAME', 'mytest'); /** MySQL數據庫用戶名 */ define('DB_USER', 'admin'); /** MySQL數據庫密碼 */ define('DB_PASSWORD', 'admin'); /** MySQL主機 */ define('DB_HOST', '172.18.250.10');
驗證能都正常登陸:
登陸博客:
[root@localhost blog]# cd /www/php/ [root@localhost php]# unzip phpMyAdmin-4.4.14.1-all-languages.zip [root@localhost php]# ln -s phpMyAdmin-4.4.14.1-all-languages pma
生成一段隨機數,用作登陸phpmyadmin
[root@localhost pma]# cp config.sample.inc.php config.inc.php [root@localhost pma]# openssl rand -base64 30 d8yhR7wOU5+HzeZjGEusyAmNiQv/+rTzWQuoDiCR [root@localhost pma]# vim config.inc.php $cfg['blowfish_secret'] = 'd8yhR7wOU5+HzeZjGEusyAmNiQv/+rTzWQuoDiCR'; $cfg['Servers'][$i]['host'] = '172.18.250.10';
驗證網頁是否能打開:
安裝個php-mbstring,支持中文字符集
[root@localhost pma]# rpm -ivh php-mbstring-5.3.3-40.el6_6.x86_64.rpm
刷新頁面:
輸入剛才授權的賬號密碼:
。。。。。。
解決思路:
1、升級mysql版本。
2、降級phpmyadmin版本。
降低版本的方法:
[root@localhost pma]# cd libraries/ [root@localhost libraries]# vim common.inc.php if (PMA_MYSQL_INT_VERSION < 50500) { 改成 if (PMA_MYSQL_INT_VERSION < 50100 {
再次刷新,輸入賬號密碼:
OK,數據庫登錄成功。
五、安裝Xcache對php進行加速
[root@localhost libraries]# yum -y install php-xcache
1、先測試沒開啟加速前的請求速度:
[root@localhost setup]# ab -n100 -c10 http://172.18.250.76/wordpress/index.php Benchmarking 172.18.250.76 (be patient).....done Server Software: Apache/2.2.15 Server Hostname: 172.18.250.76 Server Port: 80 Document Path: /wordpress/index.php Document Length: 0 bytes Concurrency Level: 10 Time taken for tests: 4.792 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Non-2xx responses: 100 Total transferred: 36800 bytes HTML transferred: 0 bytes Requests per second: 20.87 [#/sec] (mean) Time per request: 479.161 [ms] (mean) Time per request: 47.916 [ms] (mean, across all concurrent requests) Transfer rate: 7.50 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 3.8 0 20 Processing: 143 459 331.6 352 1783 Waiting: 143 458 331.6 343 1783 Total: 143 460 331.4 360 1783 Percentage of the requests served within a certain time (ms) 50% 360 66% 405 75% 512 80% 581 90% 895 95% 1375 98% 1720 99% 1783 100% 1783 (longest request)
2、重啟httpd服務,開啟Xcache,在測試下
[root@localhost setup]# ab -n100 -c10 Benchmarking 172.18.250.76 (be patient).....done Server Software: Apache/2.2.15 Server Hostname: 172.18.250.76 Server Port: 80 Document Path: /wordpress/index.php Document Length: 0 bytes Concurrency Level: 10 Time taken for tests: 1.659 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Non-2xx responses: 100 Total transferred: 36800 bytes HTML transferred: 0 bytes Requests per second: 60.27 [#/sec] (mean) //三倍加速請求 Time per request: 165.908 [ms] (mean) Time per request: 16.591 [ms] (mean, across all concurrent requests) Transfer rate: 21.66 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 2.6 0 10 Processing: 41 158 27.5 158 235 Waiting: 40 158 27.6 158 235 Total: 41 159 28.7 158 245 Percentage of the requests served within a certain time (ms) 50% 158 66% 166 75% 168 80% 171 90% 192 95% 213 98% 240 99% 245 100% 245 (longest request)
六:對訪問phpmyadmin網頁時進行SSL加密認證
簽證及CA認證是怎么進行可以參考我的博文:Linux中加密解密技術及CA認證
1、先下載mod_ssl模塊,因為httpd2.2沒包含這個模塊
[root@localhost ssl]# yum -y install mod_ssl
2、編輯/etc/httpd/conf.d/ssl.conf文件
[root@localhost ssl]# vim /etc/httpd/conf.d/ssl.conf DocumentRoot "/www/php" //取消注釋,修改虛擬主機的url ServerName //虛擬主機名 SSLEngine on //確保為on SSLCertificateFile /etc/httpd/ssl/httpd.crt //存放簽署的證書 SSLCertificateFile /etc/httpd/ssl/httpd.key //存放私鑰的位置
3、重啟httpd服務器,查看443端口是否啟用
[root@localhost ssl]# netstat -ntlp tcp 0 0 :::443 :::* LISTEN 6080/httpd
4、驗證頁面是否能訪問
5、從虛擬機把CA證書下載到windows主機上
[root@www CA]# sz cacert.pem
6、把證書導入到瀏覽器當中
7、重新打開瀏覽器,輸入虛擬主機名:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。